explain.depesz.com

PostgreSQL's explain analyze made readable

Result: JN95

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.002 5,632.312 ↓ 4.0 8 1

Limit (cost=514,010.12..514,010.13 rows=2 width=1,506) (actual time=5,632.311..5,632.312 rows=8 loops=1)

2. 0.039 5,632.310 ↓ 4.0 8 1

Sort (cost=514,010.12..514,010.13 rows=2 width=1,506) (actual time=5,632.310..5,632.310 rows=8 loops=1)

  • Sort Key: ((ml.seq + 0)), ml.customername
  • Sort Method: quicksort Memory: 29kB
3. 0.005 5,632.271 ↓ 4.0 8 1

Subquery Scan on ml (cost=514,009.97..514,010.11 rows=2 width=1,506) (actual time=5,632.263..5,632.271 rows=8 loops=1)

4. 0.006 5,632.266 ↓ 4.0 8 1

Unique (cost=514,009.97..514,010.09 rows=2 width=1,498) (actual time=5,632.261..5,632.266 rows=8 loops=1)

5. 0.047 5,632.260 ↓ 4.0 8 1

Sort (cost=514,009.97..514,009.98 rows=2 width=1,498) (actual time=5,632.260..5,632.260 rows=8 loops=1)

  • Sort Key: tn_source, id, customername, (CASE WHEN (customertype = '905324761813487616'::bigint) THEN contactname WHEN (customertype = '905324680615956480'::bigint) THEN contactname ELSE NULL::character varying END), ((to_date(to_char((CURRENT_DATE)::timestamp with time zone, 'yyyy-mm-dd'::text), 'yyyy-mm-dd'::text) - to_date(to_char(recentvisittime, 'yyyy-mm-dd'::text), 'yyyy-mm-dd'::text))), tn_times, (CASE WHEN (number IS NULL) THEN '0'::bigint ELSE number END), store_channeltype, store_channeltype, storelevelname, address, status, plandate, userid, userinfoname, customertype, seq, actualvisittime, visittype, status, isplan, tn_isdistributor
  • Sort Method: quicksort Memory: 29kB
6. 0.004 5,632.213 ↓ 4.0 8 1

Append (cost=0.00..514,009.96 rows=2 width=1,498) (actual time=5,189.591..5,632.213 rows=8 loops=1)

7. 0.001 0.001 ↓ 0.0 0 1

Result (cost=0.00..0.00 rows=0 width=673) (actual time=0.001..0.001 rows=0 loops=1)

  • One-Time Filter: false
8. 0.007 5,632.208 ↓ 8.0 8 1

Subquery Scan on *SELECT* 2 (cost=502,342.67..514,009.96 rows=1 width=673) (actual time=5,189.589..5,632.208 rows=8 loops=1)

9. 0.071 5,632.201 ↓ 8.0 8 1

Nested Loop Anti Join (cost=502,342.67..514,009.95 rows=1 width=669) (actual time=5,189.587..5,632.201 rows=8 loops=1)

  • Join Filter: ((kx_visit_planvisit.userid = p.userid) AND (kx_visit_planvisit.customerid = p.customerid))
10. 0.015 5,628.482 ↓ 8.0 8 1

Nested Loop Left Join (cost=502,342.38..514,001.60 rows=1 width=617) (actual time=5,189.134..5,628.482 rows=8 loops=1)

11. 0.019 5,628.467 ↓ 8.0 8 1

Nested Loop Left Join (cost=502,342.10..514,001.30 rows=1 width=617) (actual time=5,189.129..5,628.467 rows=8 loops=1)

12. 0.015 5,628.416 ↓ 8.0 8 1

Nested Loop Left Join (cost=502,341.82..513,992.99 rows=1 width=616) (actual time=5,189.117..5,628.416 rows=8 loops=1)

13. 0.016 5,628.361 ↓ 8.0 8 1

Nested Loop Left Join (cost=502,341.54..513,986.39 rows=1 width=608) (actual time=5,189.103..5,628.361 rows=8 loops=1)

14. 0.027 5,628.281 ↓ 8.0 8 1

Nested Loop Left Join (cost=502,341.12..513,958.06 rows=1 width=600) (actual time=5,189.086..5,628.281 rows=8 loops=1)

15. 9.255 5,628.182 ↓ 8.0 8 1

Merge Left Join (cost=502,340.83..513,950.51 rows=1 width=588) (actual time=5,189.061..5,628.182 rows=8 loops=1)

  • Merge Cond: (ks.id = kvw.customerid)
16. 0.015 34.047 ↓ 8.0 8 1

Sort (cost=5,141.01..5,141.02 rows=1 width=580) (actual time=34.044..34.047 rows=8 loops=1)

  • Sort Key: p.customerid
  • Sort Method: quicksort Memory: 28kB
17. 0.012 34.032 ↓ 8.0 8 1

Nested Loop (cost=356.20..5,141.00 rows=1 width=580) (actual time=33.998..34.032 rows=8 loops=1)

18. 10.180 33.972 ↑ 2.1 8 1

Hash Right Join (cost=355.78..4,659.48 rows=17 width=542) (actual time=33.968..33.972 rows=8 loops=1)

  • Hash Cond: ((tvd.tn_leveldevision = ks.tn_storedevicion) AND (tvd.tn_storelevel = ks.storelevel) AND (tvd.tn_area = ks.saleareaid))
19. 23.189 23.189 ↑ 1.0 93,636 1

Seq Scan on tn_visit_detail tvd (cost=0.00..3,249.90 rows=93,668 width=32) (actual time=0.009..23.189 rows=93,636 loops=1)

  • Filter: ((tn_start <= '2019-12-02 16:15:24'::timestamp without time zone) AND (tn_end >= '2019-12-02 16:15:24'::timestamp without time zone) AND (platstatus = 1))
  • Rows Removed by Filter: 2244
20. 0.008 0.603 ↑ 2.1 8 1

Hash (cost=355.48..355.48 rows=17 width=558) (actual time=0.603..0.603 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 11kB
21. 0.004 0.595 ↑ 2.1 8 1

Subquery Scan on ks (cost=98.78..355.48 rows=17 width=558) (actual time=0.427..0.595 rows=8 loops=1)

22. 0.003 0.591 ↑ 2.1 8 1

Append (cost=98.78..355.31 rows=17 width=1,586) (actual time=0.426..0.591 rows=8 loops=1)

23. 0.000 0.056 ↓ 0.0 0 1

Nested Loop Left Join (cost=98.78..188.79 rows=8 width=442) (actual time=0.056..0.056 rows=0 loops=1)

24. 0.004 0.056 ↓ 0.0 0 1

Hash Right Join (cost=98.50..124.40 rows=8 width=330) (actual time=0.056..0.056 rows=0 loops=1)

  • Hash Cond: (pd2.dickey = ks_1.storetype)
25. 0.000 0.000 ↓ 0.0 0

Seq Scan on pl_dictionary pd2 (cost=0.00..20.92 rows=392 width=20) (never executed)

26. 0.000 0.052 ↓ 0.0 0 1

Hash (cost=98.40..98.40 rows=8 width=326) (actual time=0.052..0.052 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
27. 0.004 0.052 ↓ 0.0 0 1

Hash Right Join (cost=76.00..98.40 rows=8 width=326) (actual time=0.051..0.052 rows=0 loops=1)

  • Hash Cond: (pd1.dickey = ks_1.channeltype)
28. 0.000 0.000 ↓ 0.0 0

Seq Scan on pl_dictionary pd1 (cost=0.00..20.92 rows=392 width=20) (never executed)

29. 0.001 0.048 ↓ 0.0 0 1

Hash (cost=75.90..75.90 rows=8 width=314) (actual time=0.048..0.048 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
30. 0.001 0.047 ↓ 0.0 0 1

Merge Right Join (cost=75.54..75.90 rows=8 width=314) (actual time=0.047..0.047 rows=0 loops=1)

  • Merge Cond: (pd3.dickey = ks_1.storelevel)
31. 0.016 0.016 ↑ 392.0 1 1

Index Scan using idx_pl_dictionary_dickey on pl_dictionary pd3 (cost=0.15..46.93 rows=392 width=20) (actual time=0.016..0.016 rows=1 loops=1)

32. 0.004 0.030 ↓ 0.0 0 1

Sort (cost=66.74..66.76 rows=8 width=302) (actual time=0.030..0.030 rows=0 loops=1)

  • Sort Key: ks_1.storelevel
  • Sort Method: quicksort Memory: 25kB
33. 0.026 0.026 ↓ 0.0 0 1

Index Scan using kx_kq_store_pkey on kx_kq_store ks_1 (cost=0.42..66.62 rows=8 width=302) (actual time=0.026..0.026 rows=0 loops=1)

  • Index Cond: (id = ANY ('{1177391284491522408,1143488581524919345,1143488581524919343,1177391284491522491,1143522017862094940,1177391284491522511,1177391284491522530,1143522017862095204}'::bigint[]))
  • Filter: ((platstatus = 1) AND ((customertype = '905324680615956480'::bigint) OR (customertype = '905324761813487616'::bigint)))
34. 0.000 0.000 ↓ 0.0 0

Index Scan using ix_pl_orgstruct_orgstructid on pl_orgstruct ps (cost=0.28..7.80 rows=1 width=84) (never executed)

  • Index Cond: (ks_1.seleareaid = orgstructid)
35. 0.193 0.528 ↑ 1.0 8 1

Hash Left Join (cost=60.44..155.53 rows=8 width=497) (actual time=0.369..0.528 rows=8 loops=1)

  • Hash Cond: (kc_1.channelcustomersort = pd1_1.dickey)
36. 0.014 0.080 ↑ 1.0 8 1

Nested Loop Left Join (cost=34.62..127.60 rows=8 width=331) (actual time=0.037..0.080 rows=8 loops=1)

37. 0.030 0.050 ↑ 1.0 8 1

Bitmap Heap Scan on ka_kq_channelcustomers kc_1 (cost=34.34..65.21 rows=8 width=255) (actual time=0.026..0.050 rows=8 loops=1)

  • Recheck Cond: (id = ANY ('{1177391284491522408,1143488581524919345,1143488581524919343,1177391284491522491,1143522017862094940,1177391284491522511,1177391284491522530,1143522017862095204}'::bigint[]))
  • Filter: ((platstatus = 1) AND ((customertype = '905324680615956480'::bigint) OR (customertype = '905324761813487616'::bigint)))
  • Heap Blocks: exact=8
38. 0.020 0.020 ↑ 1.0 8 1

Bitmap Index Scan on ka_kq_channelcustomers_pkey (cost=0.00..34.34 rows=8 width=0) (actual time=0.020..0.020 rows=8 loops=1)

  • Index Cond: (id = ANY ('{1177391284491522408,1143488581524919345,1143488581524919343,1177391284491522491,1143522017862094940,1177391284491522511,1177391284491522530,1143522017862095204}'::bigint[]))
39. 0.016 0.016 ↑ 1.0 1 8

Index Scan using ix_pl_orgstruct_orgstructid on pl_orgstruct ps_1 (cost=0.28..7.80 rows=1 width=84) (actual time=0.002..0.002 rows=1 loops=8)

  • Index Cond: (kc_1.saleareaid = orgstructid)
40. 0.088 0.255 ↓ 1.0 395 1

Hash (cost=20.92..20.92 rows=392 width=20) (actual time=0.255..0.255 rows=395 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
41. 0.167 0.167 ↓ 1.0 395 1

Seq Scan on pl_dictionary pd1_1 (cost=0.00..20.92 rows=392 width=20) (actual time=0.007..0.167 rows=395 loops=1)

42. 0.001 0.004 ↓ 0.0 0 1

Subquery Scan on *SELECT* 3 (cost=0.00..10.84 rows=1 width=1,972) (actual time=0.004..0.004 rows=0 loops=1)

43. 0.003 0.003 ↓ 0.0 0 1

Seq Scan on kx_kq_ka ka (cost=0.00..10.82 rows=1 width=1,968) (actual time=0.003..0.003 rows=0 loops=1)

  • Filter: ((platstatus = 1) AND ((customertype = '905324680615956480'::bigint) OR (customertype = '905324761813487616'::bigint)) AND (id = ANY ('{1177391284491522408,1143488581524919345,1143488581524919343,1177391284491522491,1143522017862094940,1177391284491522511,1177391284491522530,1143522017862095204}'::bigint[])))
44. 0.048 0.048 ↑ 1.0 1 8

Index Scan using idx_kx_visit_actual_customerid on kx_visit_actual p (cost=0.42..28.31 rows=1 width=38) (actual time=0.006..0.006 rows=1 loops=8)

  • Index Cond: (customerid = ks.id)
  • Filter: ((actualvisitdate >= '2019-11-28'::date) AND (actualvisitdate <= '2019-11-28'::date) AND (platstatus = 1) AND (userid = '1143705983973986304'::bigint))
45. 67.697 5,584.880 ↓ 807.9 161,585 1

GroupAggregate (cost=497,199.82..508,806.98 rows=200 width=16) (actual time=5,155.011..5,584.880 rows=161,585 loops=1)

  • Group Key: kvw.customerid
46. 214.376 5,517.183 ↓ 1.0 301,626 1

GroupAggregate (cost=497,199.82..504,453.04 rows=290,129 width=36) (actual time=5,155.004..5,517.183 rows=301,626 loops=1)

  • Group Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
47. 752.977 5,302.807 ↓ 3.8 1,107,786 1

Sort (cost=497,199.82..497,925.14 rows=290,129 width=28) (actual time=5,154.994..5,302.807 rows=1,107,786 loops=1)

  • Sort Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
  • Sort Method: external merge Disk: 50064kB
48. 474.178 4,549.830 ↓ 4.2 1,216,957 1

Hash Join (cost=438,261.44..463,931.93 rows=290,129 width=28) (actual time=3,975.821..4,549.830 rows=1,216,957 loops=1)

  • Hash Cond: (ste.storeid = kst.id)
49. 100.352 100.352 ↑ 1.0 413,688 1

Seq Scan on kx_kq_storerepresentative ste (cost=0.00..15,360.92 rows=418,206 width=8) (actual time=0.019..100.352 rows=413,688 loops=1)

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 111956
50. 306.224 3,975.300 ↓ 3.7 1,205,364 1

Hash (cost=431,575.48..431,575.48 rows=329,117 width=36) (actual time=3,975.300..3,975.300 rows=1,205,364 loops=1)

  • Buckets: 65536 (originally 65536) Batches: 32 (originally 8) Memory Usage: 3585kB
51. 1,586.041 3,669.076 ↓ 3.7 1,205,364 1

Hash Join (cost=228,577.05..431,575.48 rows=329,117 width=36) (actual time=1,224.139..3,669.076 rows=1,205,364 loops=1)

  • Hash Cond: (kvw.customerid = kst.id)
  • Join Filter: ((kvd2.tn_start <= kvw.recorddate) AND (kvd2.tn_end >= kvw.recorddate))
  • Rows Removed by Join Filter: 1891852
52. 859.133 859.133 ↑ 1.0 3,319,656 1

Seq Scan on kx_visit_workrecord kvw (cost=0.00..110,579.05 rows=3,369,764 width=12) (actual time=0.005..859.133 rows=3,319,656 loops=1)

  • Filter: (platstatus = 1)
53. 69.777 1,223.902 ↑ 1.2 342,981 1

Hash (cost=220,920.47..220,920.47 rows=417,006 width=24) (actual time=1,223.902..1,223.902 rows=342,981 loops=1)

  • Buckets: 65536 Batches: 8 Memory Usage: 2862kB
54. 80.659 1,154.125 ↑ 1.2 342,981 1

Merge Join (cost=210,243.78..220,920.47 rows=417,006 width=24) (actual time=950.770..1,154.125 rows=342,981 loops=1)

  • Merge Cond: ((kvd2.tn_leveldevision = kst.tn_storedevicion) AND (kvd2.tn_area = kst.seleareaid) AND (kvd2.tn_storelevel = kst.storelevel))
55. 105.987 153.266 ↑ 1.0 93,636 1

Sort (cost=13,786.36..14,020.53 rows=93,668 width=40) (actual time=141.527..153.266 rows=93,636 loops=1)

  • Sort Key: kvd2.tn_leveldevision, kvd2.tn_area, kvd2.tn_storelevel
  • Sort Method: external merge Disk: 4584kB
56. 47.279 47.279 ↑ 1.0 93,636 1

Seq Scan on tn_visit_detail kvd2 (cost=0.00..3,489.60 rows=93,668 width=40) (actual time=0.010..47.279 rows=93,636 loops=1)

  • Filter: ((tn_end >= CURRENT_DATE) AND (tn_start <= CURRENT_DATE))
  • Rows Removed by Filter: 2244
57. 39.460 920.200 ↑ 1.2 390,576 1

Materialize (cost=196,400.44..198,770.25 rows=473,962 width=32) (actual time=808.062..920.200 rows=390,576 loops=1)

58. 375.962 880.740 ↑ 1.2 390,576 1

Sort (cost=196,400.44..197,585.34 rows=473,962 width=32) (actual time=808.057..880.740 rows=390,576 loops=1)

  • Sort Key: kst.tn_storedevicion, kst.seleareaid, kst.storelevel
  • Sort Method: external merge Disk: 16880kB
59. 504.778 504.778 ↑ 1.2 410,849 1

Seq Scan on kx_kq_store kst (cost=0.00..140,379.06 rows=473,962 width=32) (actual time=0.011..504.778 rows=410,849 loops=1)

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 371
60. 0.072 0.072 ↑ 1.0 1 8

Index Scan using ka_kq_channelcustomers_pkey on ka_kq_channelcustomers kc (cost=0.29..7.54 rows=1 width=20) (actual time=0.009..0.009 rows=1 loops=8)

  • Index Cond: (id = p.customerid)
  • Filter: (platstatus = 1)
61. 0.064 0.064 ↑ 1.0 1 8

Index Scan using idx_kx_visit_customerstatus_customerid on kx_visit_customerstatus vc (cost=0.42..28.32 rows=1 width=24) (actual time=0.007..0.008 rows=1 loops=8)

  • Index Cond: (customerid = p.customerid)
  • Filter: ((visitdate >= '2019-11-28'::date) AND (visitdate <= '2019-11-28'::date) AND (userid = '1143705983973986304'::bigint) AND (platstatus = 1) AND (userid = p.userid))
62. 0.040 0.040 ↑ 1.0 1 8

Index Scan using ix_pl_orgstruct_orgstructid on pl_orgstruct po (cost=0.28..6.59 rows=1 width=16) (actual time=0.005..0.005 rows=1 loops=8)

  • Index Cond: ((orgstructid = p.userid) AND (orgstructid = '1143705983973986304'::bigint))
  • Filter: (platstatus = 1)
63. 0.032 0.032 ↑ 1.0 1 8

Index Scan using pl_userinfo_pkey on pl_userinfo pu (cost=0.28..8.30 rows=1 width=17) (actual time=0.004..0.004 rows=1 loops=8)

  • Index Cond: (po.userinfoid = userinfoid)
  • Filter: (platstatus = 1)
64. 0.000 0.000 ↓ 0.0 0 8

Index Scan using pk_tn_visit_administration_1 on tn_visit_administration tva (cost=0.28..0.30 rows=1 width=16) (actual time=0.000..0.000 rows=0 loops=8)

  • Index Cond: (tn_id = tvd.tn_adminid)
  • Filter: (platstatus = 1)
65. 3.648 3.648 ↓ 0.0 0 8

Index Scan using idx_kx_visit_planvisit_plandate on kx_visit_planvisit (cost=0.29..8.31 rows=1 width=16) (actual time=0.456..0.456 rows=0 loops=8)

  • Index Cond: ((plandate >= '2019-11-28'::date) AND (plandate <= '2019-11-28'::date))
  • Filter: ((userid = '1143705983973986304'::bigint) AND (platstatus = 1))
  • Rows Removed by Filter: 1964
Planning time : 29.339 ms
Execution time : 5,652.022 ms