explain.depesz.com

PostgreSQL's explain analyze made readable

Result: LRZe : Optimization for: Optimization for: plan #JN95; plan #z1hl

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 0.002 7,476.767 ↓ 4.0 8 1

Limit (cost=510,242.54..510,242.55 rows=2 width=1,506) (actual time=7,476.765..7,476.767 rows=8 loops=1)

2. 0.029 7,476.765 ↓ 4.0 8 1

Sort (cost=510,242.54..510,242.55 rows=2 width=1,506) (actual time=7,476.764..7,476.765 rows=8 loops=1)

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

Subquery Scan on ml (cost=510,242.39..510,242.53 rows=2 width=1,506) (actual time=7,476.727..7,476.736 rows=8 loops=1)

4. 0.006 7,476.731 ↓ 4.0 8 1

Unique (cost=510,242.39..510,242.51 rows=2 width=1,498) (actual time=7,476.725..7,476.731 rows=8 loops=1)

5. 0.038 7,476.725 ↓ 4.0 8 1

Sort (cost=510,242.39..510,242.40 rows=2 width=1,498) (actual time=7,476.724..7,476.725 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.003 7,476.687 ↓ 4.0 8 1

Append (cost=0.00..510,242.38 rows=2 width=1,498) (actual time=6,909.781..7,476.687 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.001..0.001 rows=0 loops=1)

  • One-Time Filter: false
8. 0.007 7,476.683 ↓ 8.0 8 1

Subquery Scan on *SELECT* 2 (cost=496,790.13..510,242.38 rows=1 width=355) (actual time=6,909.780..7,476.683 rows=8 loops=1)

9. 0.083 7,476.676 ↓ 8.0 8 1

Nested Loop Anti Join (cost=496,790.13..510,242.37 rows=1 width=351) (actual time=6,909.779..7,476.676 rows=8 loops=1)

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

Nested Loop Left Join (cost=496,789.84..510,234.02 rows=1 width=295) (actual time=6,909.027..7,471.937 rows=8 loops=1)

11. 0.016 7,471.913 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,789.56..510,233.72 rows=1 width=295) (actual time=6,909.019..7,471.913 rows=8 loops=1)

12. 0.018 7,471.857 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,789.28..510,225.41 rows=1 width=294) (actual time=6,909.004..7,471.857 rows=8 loops=1)

13. 0.018 7,471.799 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,789.00..510,218.81 rows=1 width=286) (actual time=6,908.990..7,471.799 rows=8 loops=1)

14. 0.026 7,471.709 ↓ 8.0 8 1

Nested Loop Left Join (cost=496,788.58..510,190.48 rows=1 width=278) (actual time=6,908.970..7,471.709 rows=8 loops=1)

15. 10.987 7,471.611 ↓ 8.0 8 1

Merge Left Join (cost=496,788.29..510,182.93 rows=1 width=266) (actual time=6,908.943..7,471.611 rows=8 loops=1)

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

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

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

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

18. 11.700 36.157 ↑ 2.0 8 1

Hash Right Join (cost=344.79..4,648.49 rows=16 width=220) (actual time=36.152..36.157 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. 23.910 23.910 ↑ 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.910 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.547 ↑ 2.0 8 1

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

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

Append (cost=98.81..344.51 rows=16 width=236) (actual time=0.398..0.538 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.005 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.054 ↓ 0.0 0 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
30. 0.002 0.054 ↓ 0.0 0 1

Merge Right Join (cost=75.57..75.93 rows=8 width=240) (actual time=0.054..0.054 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.029 ↓ 0.0 0 1

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

  • Sort Key: ks.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 (cost=0.42..66.65 rows=8 width=240) (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.seleareaid = orgstructid)
35. 0.004 0.473 ↑ 1.0 8 1

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

36. 0.168 0.469 ↑ 1.0 8 1

Hash Left Join (cost=60.44..155.53 rows=8 width=1,747) (actual time=0.333..0.469 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.038..0.080 rows=8 loops=1)

38. 0.029 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.021 0.021 ↑ 1.0 8 1

Bitmap Index Scan on ka_kq_channelcustomers_pkey (cost=0.00..34.34 rows=8 width=0) (actual time=0.021..0.021 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.071 0.221 ↓ 1.0 395 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
42. 0.150 0.150 ↓ 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.150 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.006..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. 96.926 7,424.372 ↓ 808.5 161,704 1

GroupAggregate (cost=491,686.60..505,078.72 rows=200 width=16) (actual time=6,872.688..7,424.372 rows=161,704 loops=1)

  • Group Key: kvw.customerid
45. 265.414 7,327.446 ↑ 1.1 302,194 1

GroupAggregate (cost=491,686.60..500,055.42 rows=334,753 width=36) (actual time=6,872.679..7,327.446 rows=302,194 loops=1)

  • Group Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
46. 1,173.933 7,062.032 ↓ 3.3 1,109,873 1

Sort (cost=491,686.60..492,523.48 rows=334,753 width=28) (actual time=6,872.668..7,062.032 rows=1,109,873 loops=1)

  • Sort Key: kvw.customerid, kvw.recorddate, kvd2.tn_start, kvd2.tn_end
  • Sort Method: external merge Disk: 50160kB
47. 987.862 5,888.099 ↓ 3.6 1,219,231 1

Hash Join (cost=426,830.67..452,956.93 rows=334,753 width=28) (actual time=4,524.118..5,888.099 rows=1,219,231 loops=1)

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

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

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 112488
49. 353.104 4,523.485 ↓ 3.7 1,207,600 1

Hash (cost=420,159.16..420,159.16 rows=328,441 width=36) (actual time=4,523.485..4,523.485 rows=1,207,600 loops=1)

  • Buckets: 65536 (originally 65536) Batches: 32 (originally 8) Memory Usage: 3585kB
50. 1,826.077 4,170.381 ↓ 3.7 1,207,600 1

Hash Join (cost=217,468.11..420,159.16 rows=328,441 width=36) (actual time=1,249.359..4,170.381 rows=1,207,600 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,095.229 1,095.229 ↑ 1.0 3,322,042 1

Seq Scan on kx_visit_workrecord kvw (cost=0.00..110,661.44 rows=3,372,275 width=12) (actual time=0.007..1,095.229 rows=3,322,042 loops=1)

  • Filter: (platstatus = 1)
52. 84.425 1,249.075 ↑ 1.0 342,996 1

Hash (cost=210,858.69..210,858.69 rows=359,954 width=24) (actual time=1,249.075..1,249.075 rows=342,996 loops=1)

  • Buckets: 65536 Batches: 8 Memory Usage: 2862kB
53. 97.826 1,164.650 ↑ 1.0 342,996 1

Merge Join (cost=201,515.04..210,858.69 rows=359,954 width=24) (actual time=913.492..1,164.650 rows=342,996 loops=1)

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

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

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

  • Filter: ((tn_end >= CURRENT_DATE) AND (tn_start <= CURRENT_DATE))
  • Rows Removed by Filter: 2244
56. 47.708 894.531 ↑ 1.1 390,591 1

Materialize (cost=187,671.69..189,723.97 rows=410,456 width=32) (actual time=752.863..894.531 rows=390,591 loops=1)

57. 381.810 846.823 ↑ 1.1 390,591 1

Sort (cost=187,671.69..188,697.83 rows=410,456 width=32) (actual time=752.859..846.823 rows=390,591 loops=1)

  • Sort Key: kst.tn_storedevicion, kst.seleareaid, kst.storelevel
  • Sort Method: external merge Disk: 16888kB
58. 465.013 465.013 ↓ 1.0 410,866 1

Seq Scan on kx_kq_store kst (cost=0.00..139,582.10 rows=410,456 width=32) (actual time=0.011..465.013 rows=410,866 loops=1)

  • Filter: (platstatus = 1)
  • Rows Removed by Filter: 371
59. 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)
60. 0.072 0.072 ↑ 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.009 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.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)
62. 0.040 0.040 ↑ 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.005 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. 4.656 4.656 ↓ 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.582..0.582 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 : 21.797 ms
Execution time : 7,498.089 ms