explain.depesz.com

PostgreSQL's explain analyze made readable

Result: TQN2

Settings
# exclusive inclusive rows x rows loops node
1. 0.412 4,893.961 ↑ 67.9 315 1

WindowAgg (cost=269,269,008.58..273,380,840.74 rows=21,375 width=748) (actual time=336.731..4,893.961 rows=315 loops=1)

2.          

CTE lpu

3. 4,628.184 4,858.666 ↑ 71,234,860.0 1 1

Nested Loop (cost=84,638.27..269,265,513.51 rows=71,234,860 width=150) (actual time=309.745..4,858.666 rows=1 loops=1)

  • Join Filter: (t_6.id = (COALESCE(d_pkg_agent_addrs.get_actual_on_date(t_5.agent, to_timestamp_simple('31.10.2020'::text, (d_pkg_std.frm_d())::text), '1'::numeric, 'ID'::character varying), d_pkg_agent_addrs.get_actual_on_date(t_5.agent, to_timestamp_simple('31.10.2020'::text, (d_pkg_std.frm_d())::text), '0'::numeric, 'ID'::character varying)))::text)
  • Rows Removed by Join Filter: 146,878
4. 74.597 230.482 ↓ 1.0 146,879 1

Hash Join (cost=78,374.85..85,118.16 rows=146,876 width=14) (actual time=124.652..230.482 rows=146,879 loops=1)

  • Hash Cond: (t_6.cid = up_6.catalog)
5. 31.279 31.279 ↓ 1.0 146,879 1

Seq Scan on d_agent_addrs t_6 (cost=0.00..4,723.76 rows=146,876 width=21) (actual time=0.010..31.279 rows=146,879 loops=1)

6. 0.044 124.606 ↑ 36.7 109 1

Hash (cost=78,324.83..78,324.83 rows=4,002 width=7) (actual time=124.606..124.606 rows=109 loops=1)

  • Buckets: 4,096 Batches: 1 Memory Usage: 37kB
7. 8.448 124.562 ↑ 36.4 110 1

HashAggregate (cost=78,284.81..78,324.83 rows=4,002 width=7) (actual time=124.512..124.562 rows=110 loops=1)

  • Group Key: up_6.catalog
8. 105.793 116.114 ↓ 1.3 25,227 1

Bitmap Heap Scan on d_urprivs up_6 (cost=1,466.95..78,236.69 rows=19,246 width=7) (actual time=14.995..116.114 rows=25,227 loops=1)

  • Recheck Cond: ((unitcode)::text = 'AGENT_ADDRS'::text)
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 2))
  • Rows Removed by Filter: 13,429
  • Heap Blocks: exact=24,926
9. 9.665 9.665 ↓ 1.5 58,350 1

Bitmap Index Scan on i_d_urprivs_ur (cost=0.00..1,363.96 rows=38,320 width=0) (actual time=9.665..9.665 rows=58,350 loops=1)

  • Index Cond: ((unitcode)::text = 'AGENT_ADDRS'::text)
10.          

SubPlan (for Bitmap Heap Scan)

11. 0.096 0.656 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.073..0.656 rows=855 loops=1)

12. 0.028 0.028 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_1 (cost=0.29..8.30 rows=1 width=8) (actual time=0.027..0.028 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
13. 0.532 0.532 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_1 (cost=0.29..89.42 rows=43 width=15) (actual time=0.041..0.532 rows=855 loops=1)

  • Index Cond: (sysuser = us_1.id)
14. 0.000 0.000 ↑ 970.0 1 146,879

Materialize (cost=6,263.42..268,801.28 rows=970 width=118) (actual time=0.000..0.000 rows=1 loops=146,879)

15. 0.016 8.126 ↑ 970.0 1 1

Hash Join (cost=6,263.42..268,796.43 rows=970 width=118) (actual time=5.073..8.126 rows=1 loops=1)

  • Hash Cond: (t_5.version = up_5.version)
16. 2.214 4.659 ↑ 970.0 1 1

Nested Loop Semi Join (cost=0.50..262,520.18 rows=970 width=125) (actual time=1.608..4.659 rows=1 loops=1)

  • Join Filter: (t_5.id = (t_7.column_value)::text)
  • Rows Removed by Join Filter: 1,939
17. 0.505 0.505 ↑ 1.0 1,940 1

Seq Scan on d_lpudict t_5 (cost=0.00..96.40 rows=1,940 width=125) (actual time=0.011..0.505 rows=1,940 loops=1)

18. 1.940 1.940 ↑ 1,000.0 1 1,940

Function Scan on table_expression t_7 (cost=0.50..10.50 rows=1,000 width=32) (actual time=0.001..0.001 rows=1 loops=1,940)

19. 0.009 3.451 ↑ 32.8 17 1

Hash (cost=6,255.95..6,255.95 rows=557 width=7) (actual time=3.451..3.451 rows=17 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
20. 0.263 3.442 ↑ 32.8 17 1

HashAggregate (cost=6,250.38..6,255.95 rows=557 width=7) (actual time=3.435..3.442 rows=17 loops=1)

  • Group Key: up_5.version
21. 2.627 3.179 ↑ 1.0 843 1

Bitmap Heap Scan on d_urprivs up_5 (cost=159.57..6,248.27 rows=845 width=7) (actual time=0.918..3.179 rows=843 loops=1)

  • Recheck Cond: ((unitcode)::text = 'LPUDICT'::text)
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 1))
  • Rows Removed by Filter: 451
  • Heap Blocks: exact=454
22. 0.188 0.188 ↑ 1.3 1,294 1

Bitmap Index Scan on i_d_urprivs_ur (cost=0.00..61.18 rows=1,683 width=0) (actual time=0.188..0.188 rows=1,294 loops=1)

  • Index Cond: ((unitcode)::text = 'LPUDICT'::text)
23.          

SubPlan (for Bitmap Heap Scan)

24. 0.093 0.364 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.043..0.364 rows=855 loops=1)

25. 0.009 0.009 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us (cost=0.29..8.30 rows=1 width=8) (actual time=0.009..0.009 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
26. 0.262 0.262 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur (cost=0.29..89.42 rows=43 width=15) (actual time=0.032..0.262 rows=855 loops=1)

  • Index Cond: (sysuser = us.id)
27. 0.107 4,885.674 ↑ 67.9 315 1

Hash Join (cost=3,495.06..1,695,690.18 rows=21,375 width=733) (actual time=336.653..4,885.674 rows=315 loops=1)

  • Hash Cond: (t4.id = t3.id)
28. 4,858.672 4,858.672 ↑ 71,234,860.0 1 1

CTE Scan on lpu t4 (cost=0.00..1,424,697.20 rows=71,234,860 width=566) (actual time=309.750..4,858.672 rows=1 loops=1)

29. 0.212 26.895 ↓ 375.0 375 1

Hash (cost=3,495.05..3,495.05 rows=1 width=199) (actual time=26.895..26.895 rows=375 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 97kB
30. 0.289 26.683 ↓ 375.0 375 1

Nested Loop Semi Join (cost=616.02..3,495.05 rows=1 width=199) (actual time=3.578..26.683 rows=375 loops=1)

31. 0.165 21.894 ↓ 375.0 375 1

Nested Loop (cost=517.28..3,395.34 rows=1 width=206) (actual time=3.048..21.894 rows=375 loops=1)

32. 0.086 21.138 ↓ 197.0 197 1

Nested Loop Semi Join (cost=517.01..3,394.87 rows=1 width=126) (actual time=3.030..21.138 rows=197 loops=1)

33. 0.109 17.900 ↓ 197.0 197 1

Nested Loop (cost=418.27..3,295.19 rows=1 width=133) (actual time=2.531..17.900 rows=197 loops=1)

34. 0.048 17.397 ↓ 197.0 197 1

Nested Loop Semi Join (cost=417.99..3,294.66 rows=1 width=119) (actual time=2.497..17.397 rows=197 loops=1)

35. 0.181 14.788 ↓ 197.0 197 1

Nested Loop Semi Join (cost=319.25..3,101.44 rows=1 width=126) (actual time=1.986..14.788 rows=197 loops=1)

36. 0.220 11.061 ↓ 197.0 197 1

Nested Loop (cost=220.51..3,002.50 rows=1 width=133) (actual time=1.399..11.061 rows=197 loops=1)

37. 0.113 10.447 ↓ 197.0 197 1

Nested Loop Semi Join (cost=220.09..3,001.47 rows=1 width=147) (actual time=1.387..10.447 rows=197 loops=1)

38. 0.220 6.985 ↓ 197.0 197 1

Nested Loop (cost=121.35..2,901.77 rows=1 width=154) (actual time=0.798..6.985 rows=197 loops=1)

39. 0.124 2.910 ↑ 1.2 257 1

Hash Join (cost=121.07..2,580.25 rows=304 width=140) (actual time=0.601..2.910 rows=257 loops=1)

  • Hash Cond: (t_2.lpu_in = t3.id)
40. 0.105 2.227 ↑ 1.2 257 1

Nested Loop (cost=0.42..2,458.80 rows=304 width=133) (actual time=0.037..2.227 rows=257 loops=1)

41. 0.066 0.066 ↑ 1.2 257 1

Seq Scan on d_pregnant_cards t_2 (cost=0.00..9.04 rows=304 width=124) (actual time=0.011..0.066 rows=257 loops=1)

42. 2.056 2.056 ↑ 1.0 1 257

Index Scan using pk_d_agents on d_agents t1 (cost=0.42..8.06 rows=1 width=57) (actual time=0.008..0.008 rows=1 loops=257)

  • Index Cond: (id = t_2.agent)
43. 0.246 0.559 ↑ 1.0 1,940 1

Hash (cost=96.40..96.40 rows=1,940 width=7) (actual time=0.559..0.559 rows=1,940 loops=1)

  • Buckets: 2,048 Batches: 1 Memory Usage: 91kB
44. 0.313 0.313 ↑ 1.0 1,940 1

Seq Scan on d_lpudict t3 (cost=0.00..96.40 rows=1,940 width=7) (actual time=0.005..0.313 rows=1,940 loops=1)

45. 3.855 3.855 ↑ 1.0 1 257

Index Scan using i_d_agent_pregnancy_pid on d_agent_pregnancy t (cost=0.28..1.05 rows=1 width=14) (actual time=0.014..0.015 rows=1 loops=257)

  • Index Cond: (pid = t1.id)
  • Filter: (((end_date >= to_timestamp_simple('01.10.2020'::text, 'dd.mm.yyyy'::text)) AND (end_date <= to_timestamp_simple('31.10.2020'::text, 'dd.mm.yyyy'::text))) OR (nullif2(end_date) IS NULL))
  • Rows Removed by Filter: 1
46. 3.044 3.349 ↑ 4.0 1 197

Index Only Scan using uk_d_urprivs on d_urprivs up (cost=98.74..134.96 rows=4 width=7) (actual time=0.017..0.017 rows=1 loops=197)

  • Index Cond: ((unitcode = 'AGENT_PREGNANCY'::text) AND (catalog = t.cid))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 6))
  • Heap Fetches: 197
47.          

SubPlan (for Index Only Scan)

48. 0.075 0.305 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.034..0.305 rows=855 loops=1)

49. 0.009 0.009 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_3 (cost=0.29..8.30 rows=1 width=8) (actual time=0.008..0.009 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
50. 0.221 0.221 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_3 (cost=0.29..89.42 rows=43 width=15) (actual time=0.024..0.221 rows=855 loops=1)

  • Index Cond: (sysuser = us_3.id)
51. 0.394 0.394 ↑ 1.0 1 197

Index Scan using pk_d_agents on d_agents t_1 (cost=0.42..1.03 rows=1 width=14) (actual time=0.002..0.002 rows=1 loops=197)

  • Index Cond: (id = t1.id)
52. 3.266 3.546 ↑ 4.0 1 197

Index Only Scan using uk_d_urprivs on d_urprivs up_1 (cost=98.74..107.41 rows=4 width=7) (actual time=0.018..0.018 rows=1 loops=197)

  • Index Cond: ((unitcode = 'AGENTS'::text) AND (catalog = t_1.cid))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 7))
  • Heap Fetches: 197
53.          

SubPlan (for Index Only Scan)

54. 0.069 0.280 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.031..0.280 rows=855 loops=1)

55. 0.008 0.008 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_4 (cost=0.29..8.30 rows=1 width=8) (actual time=0.007..0.008 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
56. 0.203 0.203 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_4 (cost=0.29..89.42 rows=43 width=15) (actual time=0.022..0.203 rows=855 loops=1)

  • Index Cond: (sysuser = us_4.id)
57. 2.327 2.561 ↑ 1.0 1 197

Index Only Scan using uk_d_urprivs on d_urprivs up_2 (cost=98.74..193.21 rows=1 width=7) (actual time=0.013..0.013 rows=1 loops=197)

  • Index Cond: ((unitcode = 'PREGNANT_CARDS'::text) AND (version = t_2.version))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 8))
  • Heap Fetches: 197
58.          

SubPlan (for Index Only Scan)

59. 0.071 0.234 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.029..0.234 rows=855 loops=1)

60. 0.008 0.008 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_5 (cost=0.29..8.30 rows=1 width=8) (actual time=0.007..0.008 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
61. 0.155 0.155 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_5 (cost=0.29..89.42 rows=43 width=15) (actual time=0.021..0.155 rows=855 loops=1)

  • Index Cond: (sysuser = us_5.id)
62. 0.394 0.394 ↑ 1.0 1 197

Index Scan using pk_d_agent_pregnancy on d_agent_pregnancy t_3 (cost=0.28..0.53 rows=1 width=14) (actual time=0.002..0.002 rows=1 loops=197)

  • Index Cond: (id = t_2.pregnancy)
63. 2.917 3.152 ↑ 4.0 1 197

Index Only Scan using uk_d_urprivs on d_urprivs up_3 (cost=98.74..134.05 rows=4 width=7) (actual time=0.016..0.016 rows=1 loops=197)

  • Index Cond: ((unitcode = 'AGENT_PREGNANCY'::text) AND (catalog = t_3.cid))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 9))
  • Heap Fetches: 197
64.          

SubPlan (for Index Only Scan)

65. 0.073 0.235 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.032..0.235 rows=855 loops=1)

66. 0.006 0.006 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_6 (cost=0.29..8.30 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
67. 0.156 0.156 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_6 (cost=0.29..89.42 rows=43 width=15) (actual time=0.022..0.156 rows=855 loops=1)

  • Index Cond: (sysuser = us_6.id)
68. 0.591 0.591 ↑ 1.5 2 197

Index Scan using i_d_agent_prgn_mkbs_pid on d_agent_prgn_mkbs t_4 (cost=0.28..0.44 rows=3 width=94) (actual time=0.002..0.003 rows=2 loops=197)

  • Index Cond: (pid = t_3.id)
  • Filter: (diagn_type = '0'::numeric)
  • Rows Removed by Filter: 0
69. 4.264 4.500 ↑ 3.0 1 375

Index Only Scan using uk_d_urprivs on d_urprivs up_4 (cost=98.74..126.61 rows=3 width=7) (actual time=0.012..0.012 rows=1 loops=375)

  • Index Cond: ((unitcode = 'AGENT_PRGN_MKBS'::text) AND (catalog = t_4.cid))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 10))
  • Heap Fetches: 375
70.          

SubPlan (for Index Only Scan)

71. 0.071 0.236 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.034..0.236 rows=855 loops=1)

72. 0.010 0.010 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_7 (cost=0.29..8.30 rows=1 width=8) (actual time=0.009..0.010 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
73. 0.155 0.155 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_7 (cost=0.29..89.42 rows=43 width=15) (actual time=0.023..0.155 rows=855 loops=1)

  • Index Cond: (sysuser = us_7.id)
74.          

SubPlan (for WindowAgg)

75. 0.630 7.875 ↑ 1.0 1 315

Aggregate (cost=113.17..113.18 rows=1 width=32) (actual time=0.025..0.025 rows=1 loops=315)

76. 0.555 7.245 ↑ 1.0 1 315

Nested Loop Semi Join (cost=103.05..113.16 rows=1 width=87) (actual time=0.013..0.023 rows=1 loops=315)

77. 0.945 1.890 ↑ 1.0 1 315

Bitmap Heap Scan on d_agent_prgn_mkbs t_8 (cost=4.31..13.44 rows=1 width=94) (actual time=0.005..0.006 rows=1 loops=315)

  • Recheck Cond: (pid = t_3.id)
  • Filter: (diagn_type <> '0'::numeric(1,0))
  • Rows Removed by Filter: 10
  • Heap Blocks: exact=1,032
78. 0.945 0.945 ↓ 2.8 11 315

Bitmap Index Scan on i_d_agent_prgn_mkbs_pid (cost=0.00..4.31 rows=4 width=0) (actual time=0.003..0.003 rows=11 loops=315)

  • Index Cond: (pid = t_3.id)
79. 4.529 4.800 ↑ 3.0 1 400

Index Only Scan using uk_d_urprivs on d_urprivs up_7 (cost=98.74..126.90 rows=3 width=7) (actual time=0.012..0.012 rows=1 loops=400)

  • Index Cond: ((unitcode = 'AGENT_PRGN_MKBS'::text) AND (catalog = t_8.cid))
  • Filter: (((username)::text = ((SESSION_USER)::character varying)::text) OR (hashed SubPlan 4))
  • Heap Fetches: 400
80.          

SubPlan (for Index Only Scan)

81. 0.070 0.271 ↓ 77.7 855 1

Nested Loop (cost=0.58..98.16 rows=11 width=7) (actual time=0.040..0.271 rows=855 loops=1)

82. 0.013 0.013 ↑ 1.0 1 1

Index Scan using uk_d_users on d_users us_2 (cost=0.29..8.30 rows=1 width=8) (actual time=0.012..0.013 rows=1 loops=1)

  • Index Cond: ((username)::text = ((SESSION_USER)::character varying(30))::text)
83. 0.188 0.188 ↓ 19.9 855 1

Index Scan using i_d_userroles_u on d_userroles ur_2 (cost=0.29..89.42 rows=43 width=15) (actual time=0.026..0.188 rows=855 loops=1)

  • Index Cond: (sysuser = us_2.id)
Planning time : 18.140 ms
Execution time : 4,895.996 ms