explain.depesz.com

PostgreSQL's explain analyze made readable

Result: z1hl : Optimization for: plan #JN95

Settings

Optimization path:

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.002 13,781.610 ↓ 4.0 8 1

Limit (cost=510,227.68..510,227.68 rows=2 width=1,506) (actual time=13,781.608..13,781.610 rows=8 loops=1)

2. 0.036 13,781.608 ↓ 4.0 8 1

Sort (cost=510,227.68..510,227.68 rows=2 width=1,506) (actual time=13,781.607..13,781.608 rows=8 loops=1)

  • Sort Key: ((ml.seq + 0)), ml.customername
  • Sort Method: quicksort Memory: 29kB
3. 0.008 13,781.572 ↓ 4.0 8 1

Subquery Scan on ml (cost=510,227.53..510,227.67 rows=2 width=1,506) (actual time=13,781.559..13,781.572 rows=8 loops=1)

4. 0.009 13,781.564 ↓ 4.0 8 1

Unique (cost=510,227.53..510,227.64 rows=2 width=1,498) (actual time=13,781.556..13,781.564 rows=8 loops=1)

5. 0.042 13,781.555 ↓ 4.0 8 1

Sort (cost=510,227.53..510,227.53 rows=2 width=1,498) (actual time=13,781.555..13,781.555 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 13,781.513 ↓ 4.0 8 1

Append (cost=0.00..510,227.52 rows=2 width=1,498) (actual time=12,879.589..13,781.513 rows=8 loops=1)

7. 0.001 0.001 ↓ 0.0 0 1

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

  • One-Time Filter: false
8. 0.010 13,781.508 ↓ 8.0 8 1

Subquery Scan on *SELECT* 2 (cost=496,776.03..510,227.52 rows=1 width=355) (actual time=12,879.587..13,781.508 rows=8 loops=1)

9. 0.103 13,781.498 ↓ 8.0 8 1

Nested Loop Anti Join (cost=496,776.03..510,227.51 rows=1 width=351) (actual time=12,879.585..13,781.498 rows=8 loops=1)

  • Join Filter: ((kx_visit_planvisit.userid = p.userid) AND (kx_visit_planvisit.customerid = p.customerid))
10. 0.016 13,775.667 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,775.74..510,219.15 rows=1 width=295) (actual time=12,878.839..13,775.667 rows=8 loops=1)

11. 0.012 13,775.643 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,775.46..510,218.85 rows=1 width=295) (actual time=12,878.833..13,775.643 rows=8 loops=1)

12. 0.018 13,775.583 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,775.18..510,210.54 rows=1 width=294) (actual time=12,878.818..13,775.583 rows=8 loops=1)

13. 0.018 13,775.509 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,774.90..510,203.94 rows=1 width=286) (actual time=12,878.801..13,775.509 rows=8 loops=1)

14. 0.030 13,775.411 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,774.48..510,175.61 rows=1 width=278) (actual time=12,878.780..13,775.411 rows=8 loops=1)

15. 17.268 13,775.285 ↓ 8.0 8 1

Merge Left Join (cost=496,774.19..510,168.07 rows=1 width=266) (actual time=12,878.746..13,775.285 rows=8 loops=1)

  • Merge Cond: ("*SELECT* 1".id = kvw.customerid)
16. 0.017 88.447 ↓ 8.0 8 1

Sort (cost=5,101.70..5,101.70 rows=1 width=258) (actual time=88.444..88.447 rows=8 loops=1)

  • Sort Key: p.customerid
  • Sort Method: quicksort Memory: 29kB
17. 0.008 88.430 ↓ 8.0 8 1

Nested Loop (cost=345.21..5,101.69 rows=1 width=258) (actual time=88.384..88.430 rows=8 loops=1)

18. 33.212 88.366 ↑ 2.0 8 1

Hash Right Join (cost=344.79..4,648.49 rows=16 width=220) (actual time=88.361..88.366 rows=8 loops=1)

  • Hash Cond: ((tvd.tn_leveldevision = "*SELECT* 1".tn_storedevicion) AND (tvd.tn_storelevel = "*SELECT* 1".storelevel) AND (tvd.tn_area = "*SELECT* 1".saleareaid))
19. 54.535 54.535 ↑ 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..54.535 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.009 0.619 ↑ 2.0 8 1

Hash (cost=344.51..344.51 rows=16 width=236) (actual time=0.619..0.619 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 11kB
21. 0.001 0.610 ↑ 2.0 8 1

Append (cost=98.81..344.51 rows=16 width=236) (actual time=0.431..0.610 rows=8 loops=1)

22. 0.000 0.064 ↓ 0.0 0 1

Subquery Scan on *SELECT* 1 (cost=98.81..188.90 rows=8 width=236) (actual time=0.064..0.064 rows=0 loops=1)

23. 0.001 0.064 ↓ 0.0 0 1

Nested Loop Left Join (cost=98.81..188.82 rows=8 width=1,748) (actual time=0.064..0.064 rows=0 loops=1)

24. 0.003 0.063 ↓ 0.0 0 1

Hash Right Join (cost=98.53..124.43 rows=8 width=236) (actual time=0.063..0.063 rows=0 loops=1)

  • Hash Cond: (pd2.dickey = ks.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.001 0.060 ↓ 0.0 0 1

Hash (cost=98.43..98.43 rows=8 width=232) (actual time=0.059..0.060 rows=0 loops=1)

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

Hash Right Join (cost=76.03..98.43 rows=8 width=232) (actual time=0.059..0.059 rows=0 loops=1)

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

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

29. 0.000 0.055 ↓ 0.0 0 1

Hash (cost=75.93..75.93 rows=8 width=240) (actual time=0.055..0.055 rows=0 loops=1)

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

Merge Right Join (cost=75.57..75.93 rows=8 width=240) (actual time=0.055..0.055 rows=0 loops=1)

  • Merge Cond: (pd3.dickey = ks.storelevel)
31. 0.023 0.023 ↑ 392.0 1 1

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

  • Heap Fetches: 1
32. 0.003 0.031 ↓ 0.0 0 1

Sort (cost=66.77..66.79 rows=8 width=240) (actual time=0.031..0.031 rows=0 loops=1)

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

Index Scan using kx_kq_store_pkey on kx_kq_store ks (cost=0.42..66.65 rows=8 width=240) (actual time=0.028..0.028 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.seleareaid = orgstructid)
35. 0.003 0.545 ↑ 1.0 8 1

Subquery Scan on *SELECT* 2_1 (cost=60.44..155.61 rows=8 width=235) (actual time=0.366..0.545 rows=8 loops=1)

36. 0.210 0.542 ↑ 1.0 8 1

Hash Left Join (cost=60.44..155.53 rows=8 width=1,747) (actual time=0.365..0.542 rows=8 loops=1)

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

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

38. 0.028 0.050 ↑ 1.0 8 1

Bitmap Heap Scan on ka_kq_channelcustomers kc_1 (cost=34.34..65.21 rows=8 width=215) (actual time=0.028..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
39. 0.022 0.022 ↑ 1.0 8 1

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

  • Index Cond: (id = ANY ('{1177391284491522408,1143488581524919345,1143488581524919343,1177391284491522491,1143522017862094940,1177391284491522511,1177391284491522530,1143522017862095204}'::bigint[]))
40. 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)
41. 0.106 0.252 ↓ 1.0 395 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
42. 0.146 0.146 ↓ 1.0 395 1

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

43. 0.056 0.056 ↑ 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.007..0.007 rows=1 loops=8)

  • Index Cond: (customerid = "*SELECT* 1".id)
  • Filter: ((actualvisitdate >= '2019-11-28'::date) AND (actualvisitdate <= '2019-11-28'::date) AND (platstatus = 1) AND (userid = '1143705983973986304'::bigint))
44. 134.173 13,669.570 ↓ 808.5 161,695 1

GroupAggregate (cost=491,672.49..505,063.85 rows=200 width=16) (actual time=12,790.295..13,669.570 rows=161,695 loops=1)

  • Group Key: kvw.customerid
45. 457.062 13,535.397 ↑ 1.1 302,163 1

GroupAggregate (cost=491,672.49..500,040.84 rows=334,734 width=36) (actual time=12,790.284..13,535.397 rows=302,163 loops=1)

  • Group Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
46. 1,492.145 13,078.335 ↓ 3.3 1,109,763 1

Sort (cost=491,672.49..492,509.33 rows=334,734 width=28) (actual time=12,790.272..13,078.335 rows=1,109,763 loops=1)

  • Sort Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
  • Sort Method: external merge Disk: 50152kB
47. 1,059.041 11,586.190 ↓ 3.6 1,219,107 1

Hash Join (cost=426,818.64..452,944.71 rows=334,734 width=28) (actual time=10,357.560..11,586.190 rows=1,219,107 loops=1)

  • Hash Cond: (ste.storeid = kst.id)
48. 170.588 170.588 ↑ 1.0 413,704 1

Seq Scan on kx_kq_storerepresentative ste (cost=0.00..15,373.20 rows=418,540 width=8) (actual time=0.013..170.588 rows=413,704 loops=1)

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 112488
49. 555.594 10,356.561 ↓ 3.7 1,207,480 1

Hash (cost=420,147.37..420,147.37 rows=328,422 width=36) (actual time=10,356.561..10,356.561 rows=1,207,480 loops=1)

  • Buckets: 65536 (originally 65536) Batches: 32 (originally 8) Memory Usage: 3585kB
50. 3,390.889 9,800.967 ↓ 3.7 1,207,480 1

Hash Join (cost=217,468.11..420,147.37 rows=328,422 width=36) (actual time=4,658.928..9,800.967 rows=1,207,480 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
51. 1,751.806 1,751.806 ↑ 1.0 3,321,920 1

Seq Scan on kx_visit_workrecord kvw (cost=0.00..110,654.98 rows=3,372,078 width=12) (actual time=0.007..1,751.806 rows=3,321,920 loops=1)

  • Filter: (platstatus = 1)
52. 177.866 4,658.272 ↑ 1.0 342,995 1

Hash (cost=210,858.69..210,858.69 rows=359,954 width=24) (actual time=4,658.272..4,658.272 rows=342,995 loops=1)

  • Buckets: 65536 Batches: 8 Memory Usage: 2862kB
53. 423.089 4,480.406 ↑ 1.0 342,995 1

Merge Join (cost=201,515.04..210,858.69 rows=359,954 width=24) (actual time=3,608.987..4,480.406 rows=342,995 loops=1)

  • Merge Cond: ((kvd2.tn_leveldevision = kst.tn_storedevicion) AND (kvd2.tn_area = kst.seleareaid) AND (kvd2.tn_storelevel = kst.storelevel))
54. 470.269 634.376 ↑ 1.0 93,636 1

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

  • Sort Key: kvd2.tn_leveldevision, kvd2.tn_area, kvd2.tn_storelevel
  • Sort Method: external merge Disk: 4584kB
55. 164.107 164.107 ↑ 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.013..164.107 rows=93,636 loops=1)

  • Filter: ((tn_end >= CURRENT_DATE) AND (tn_start <= CURRENT_DATE))
  • Rows Removed by Filter: 2244
56. 128.652 3,422.941 ↑ 1.1 390,590 1

Materialize (cost=187,671.69..189,723.97 rows=410,456 width=32) (actual time=2,993.944..3,422.941 rows=390,590 loops=1)

57. 1,633.772 3,294.289 ↑ 1.1 390,590 1

Sort (cost=187,671.69..188,697.83 rows=410,456 width=32) (actual time=2,993.938..3,294.289 rows=390,590 loops=1)

  • Sort Key: kst.tn_storedevicion, kst.seleareaid, kst.storelevel
  • Sort Method: external merge Disk: 16880kB
58. 1,660.517 1,660.517 ↓ 1.0 410,865 1

Seq Scan on kx_kq_store kst (cost=0.00..139,582.10 rows=410,456 width=32) (actual time=0.014..1,660.517 rows=410,865 loops=1)

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 371
59. 0.096 0.096 ↑ 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.012..0.012 rows=1 loops=8)

  • Index Cond: (id = p.customerid)
  • Filter: (platstatus = 1)
60. 0.080 0.080 ↑ 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.009..0.010 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))
61. 0.056 0.056 ↑ 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.007..0.007 rows=1 loops=8)

  • Index Cond: ((orgstructid = p.userid) AND (orgstructid = '1143705983973986304'::bigint))
  • Filter: (platstatus = 1)
62. 0.048 0.048 ↑ 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.005..0.006 rows=1 loops=8)

  • Index Cond: (po.userinfoid = userinfoid)
  • Filter: (platstatus = 1)
63. 0.008 0.008 ↓ 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.001..0.001 rows=0 loops=8)

  • Index Cond: (tn_id = tvd.tn_adminid)
  • Filter: (platstatus = 1)
64. 5.728 5.728 ↓ 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.716..0.716 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 : 32.711 ms
Execution time : 13,808.438 ms