explain.depesz.com

PostgreSQL's explain analyze made readable

Result: Wm20 : Optimization for: plan #BEbw

Settings

Optimization path:

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 1,926.785 1,926.785 ↓ 1.0 205,446 1

CTE Scan on contas (cost=72,665.63..80,883.35 rows=205,443 width=577) (actual time=1,050.168..1,926.785 rows=205,446 loops=1)

2.          

CTE contas

3. 134.237 1,698.624 ↓ 1.0 205,446 1

Hash Left Join (cost=48,358.60..72,665.63 rows=205,443 width=182) (actual time=1,050.159..1,698.624 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = cr_saldo.contasareceber_codigo)
4. 51.526 751.612 ↓ 1.0 205,446 1

Hash Left Join (cost=25,165.21..46,133.79 rows=205,443 width=94) (actual time=237.372..751.612 rows=205,446 loops=1)

  • Hash Cond: (cr_1.tipodocumento_codigo = t.codigo)
5. 34.946 700.072 ↓ 1.0 205,446 1

Hash Left Join (cost=25,163.72..43,307.45 rows=205,443 width=80) (actual time=237.353..700.072 rows=205,446 loops=1)

  • Hash Cond: (cr_1.gruposcontas_codigo = grct.codigo)
6. 53.813 665.116 ↓ 1.0 205,446 1

Hash Left Join (cost=25,162.63..42,535.94 rows=205,443 width=75) (actual time=237.339..665.116 rows=205,446 loops=1)

  • Hash Cond: (cr_sit_1.situacoesconta_codigo = sc_1.codigo)
7. 93.773 611.290 ↓ 1.0 205,446 1

Hash Left Join (cost=25,161.49..39,709.96 rows=205,443 width=68) (actual time=237.316..611.290 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = cr_sit_1.contasareceber_codigo)
8. 75.438 468.442 ↓ 1.0 205,446 1

Hash Left Join (cost=19,623.62..31,347.25 rows=205,443 width=64) (actual time=187.043..468.442 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = crav.contasareceber_codigo)
9. 58.096 341.338 ↓ 1.0 205,446 1

Hash Left Join (cost=14,672.14..23,853.06 rows=205,443 width=60) (actual time=134.306..341.338 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = pvpg_cr.contasareceber_codigo)
10. 30.056 213.914 ↓ 1.0 205,446 1

Hash Left Join (cost=6,428.25..14,558.39 rows=205,443 width=52) (actual time=64.842..213.914 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = snfpg_cr.contasareceber_codigo)
11. 102.185 180.578 ↓ 1.0 205,446 1

Hash Join (cost=5,733.47..13,091.43 rows=205,443 width=44) (actual time=61.553..180.578 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = cr_fat_1.contasareceber_codigo)
12. 17.979 17.979 ↑ 1.0 205,639 1

Seq Scan on contasareceber cr_1 (cost=0.00..4,532.39 rows=205,639 width=44) (actual time=0.007..17.979 rows=205,639 loops=1)

13. 35.600 60.414 ↓ 1.0 205,446 1

Hash (cost=3,165.43..3,165.43 rows=205,443 width=4) (actual time=60.414..60.414 rows=205,446 loops=1)

  • Buckets: 262144 Batches: 1 Memory Usage: 9271kB
14. 24.814 24.814 ↓ 1.0 205,446 1

Seq Scan on contasareceber_faturamentos cr_fat_1 (cost=0.00..3,165.43 rows=205,443 width=4) (actual time=0.008..24.814 rows=205,446 loops=1)

  • Filter: (contasareceber_codigo IS NOT NULL)
15. 0.035 3.280 ↑ 1.0 176 1

Hash (cost=692.58..692.58 rows=176 width=12) (actual time=3.280..3.280 rows=176 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 16kB
16. 0.104 3.245 ↑ 1.0 176 1

Nested Loop Left Join (cost=5.25..692.58 rows=176 width=12) (actual time=2.212..3.245 rows=176 loops=1)

17. 1.886 2.965 ↑ 1.0 176 1

Hash Right Join (cost=4.96..605.16 rows=176 width=8) (actual time=2.201..2.965 rows=176 loops=1)

  • Hash Cond: (snfpg.codigo = snfpg_cr.saidasnf_pagtos_codigo)
18. 1.037 1.037 ↑ 1.0 22,122 1

Seq Scan on saidasnf_pagto snfpg (cost=0.00..377.22 rows=22,122 width=8) (actual time=0.002..1.037 rows=22,122 loops=1)

19. 0.023 0.042 ↑ 1.0 176 1

Hash (cost=2.76..2.76 rows=176 width=8) (actual time=0.042..0.042 rows=176 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 15kB
20. 0.019 0.019 ↑ 1.0 176 1

Seq Scan on saidasnf_pagtos_contasareceber snfpg_cr (cost=0.00..2.76 rows=176 width=8) (actual time=0.003..0.019 rows=176 loops=1)

21. 0.176 0.176 ↑ 1.0 1 176

Index Scan using saidasnf_codigo_index on saidasnf snf (cost=0.29..0.49 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=176)

  • Index Cond: (snfpg.codsaidasnf = codigo)
22. 4.990 69.328 ↑ 1.0 28,064 1

Hash (cost=7,893.09..7,893.09 rows=28,064 width=12) (actual time=69.328..69.328 rows=28,064 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1462kB
23. 18.901 64.338 ↑ 1.0 28,064 1

Hash Right Join (cost=3,859.05..7,893.09 rows=28,064 width=12) (actual time=40.258..64.338 rows=28,064 loops=1)

  • Hash Cond: (pv.codigo = pvpg.codprevenda)
24. 5.339 5.339 ↑ 1.0 91,560 1

Seq Scan on prevendas pv (cost=0.00..3,295.60 rows=91,560 width=8) (actual time=0.001..5.339 rows=91,560 loops=1)

25. 4.583 40.098 ↑ 1.0 28,064 1

Hash (cost=3,508.25..3,508.25 rows=28,064 width=8) (actual time=40.098..40.098 rows=28,064 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1353kB
26. 9.874 35.515 ↑ 1.0 28,064 1

Hash Left Join (cost=2,716.73..3,508.25 rows=28,064 width=8) (actual time=24.918..35.515 rows=28,064 loops=1)

  • Hash Cond: (pvpg_cr.prevendas_pagtos_codigo = pvpg.codigo)
27. 1.428 1.428 ↑ 1.0 28,064 1

Seq Scan on prevendas_pagtos_contasareceber pvpg_cr (cost=0.00..405.64 rows=28,064 width=8) (actual time=0.003..1.428 rows=28,064 loops=1)

28. 15.190 24.213 ↑ 1.0 93,499 1

Hash (cost=1,547.99..1,547.99 rows=93,499 width=8) (actual time=24.213..24.213 rows=93,499 loops=1)

  • Buckets: 131072 Batches: 1 Memory Usage: 4677kB
29. 9.023 9.023 ↑ 1.0 93,499 1

Seq Scan on prevenda_pagto pvpg (cost=0.00..1,547.99 rows=93,499 width=8) (actual time=0.002..9.023 rows=93,499 loops=1)

30. 32.905 51.666 ↑ 1.0 177,399 1

Hash (cost=2,733.99..2,733.99 rows=177,399 width=8) (actual time=51.666..51.666 rows=177,399 loops=1)

  • Buckets: 262144 Batches: 1 Memory Usage: 8978kB
31. 18.761 18.761 ↑ 1.0 177,399 1

Seq Scan on contasareceber_avulsas crav (cost=0.00..2,733.99 rows=177,399 width=8) (actual time=0.003..18.761 rows=177,399 loops=1)

32. 37.611 49.075 ↑ 1.0 205,639 1

Hash (cost=2,967.39..2,967.39 rows=205,639 width=8) (actual time=49.075..49.075 rows=205,639 loops=1)

  • Buckets: 262144 Batches: 1 Memory Usage: 10081kB
33. 11.464 11.464 ↑ 1.0 205,639 1

Seq Scan on contasareceber_situacao cr_sit_1 (cost=0.00..2,967.39 rows=205,639 width=8) (actual time=0.004..11.464 rows=205,639 loops=1)

34. 0.009 0.013 ↑ 1.0 6 1

Hash (cost=1.06..1.06 rows=6 width=15) (actual time=0.013..0.013 rows=6 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
35. 0.004 0.004 ↑ 1.0 6 1

Seq Scan on situacoescontas sc_1 (cost=0.00..1.06 rows=6 width=15) (actual time=0.002..0.004 rows=6 loops=1)

36. 0.008 0.010 ↑ 1.0 4 1

Hash (cost=1.04..1.04 rows=4 width=13) (actual time=0.010..0.010 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
37. 0.002 0.002 ↑ 1.0 4 1

Seq Scan on gruposcontas grct (cost=0.00..1.04 rows=4 width=13) (actual time=0.001..0.002 rows=4 loops=1)

38. 0.010 0.014 ↑ 1.0 22 1

Hash (cost=1.22..1.22 rows=22 width=18) (actual time=0.014..0.014 rows=22 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
39. 0.004 0.004 ↑ 1.0 22 1

Seq Scan on tipodocumento t (cost=0.00..1.22 rows=22 width=18) (actual time=0.002..0.004 rows=22 loops=1)

40. 0.001 812.775 ↓ 0.0 0 1

Hash (cost=23,193.37..23,193.37 rows=1 width=92) (actual time=812.775..812.775 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
41. 0.001 812.774 ↓ 0.0 0 1

Subquery Scan on cr_saldo (cost=23,193.32..23,193.37 rows=1 width=92) (actual time=812.774..812.774 rows=0 loops=1)

42. 812.773 812.773 ↓ 0.0 0 1

CTE Scan on contas_final (cost=23,193.32..23,193.36 rows=1 width=145) (actual time=812.773..812.773 rows=0 loops=1)

  • Filter: (contasareceber_faturamentos_codigo IS NOT NULL)
43.          

CTE contas_pagtos

44. 0.002 812.770 ↓ 0.0 0 1

Merge Right Join (cost=21,975.25..23,182.58 rows=1 width=262) (actual time=812.770..812.770 rows=0 loops=1)

  • Merge Cond: (crpg.contasareceber_faturamentos_cr_codigo = cr.codigo)
45. 0.002 812.764 ↑ 68,056.0 1 1

Unique (cost=21,973.86..22,314.14 rows=68,056 width=35) (actual time=812.764..812.764 rows=1 loops=1)

46. 53.580 812.762 ↑ 68,056.0 1 1

Sort (cost=21,973.86..22,144.00 rows=68,056 width=35) (actual time=812.762..812.762 rows=1 loops=1)

  • Sort Key: crpg.contasareceber_faturamentos_cr_codigo, crpg.dhpagamento DESC
  • Sort Method: quicksort Memory: 22096kB
47. 557.485 759.182 ↓ 3.0 204,172 1

WindowAgg (cost=12,937.92..16,510.86 rows=68,056 width=35) (actual time=191.540..759.182 rows=204,172 loops=1)

48. 103.565 201.697 ↓ 3.0 204,172 1

Sort (cost=12,937.92..13,108.06 rows=68,056 width=35) (actual time=191.493..201.697 rows=204,172 loops=1)

  • Sort Key: crpg.contasareceber_faturamentos_cr_codigo
  • Sort Method: quicksort Memory: 22095kB
49. 35.895 98.132 ↓ 3.0 204,172 1

Hash Anti Join (cost=5.76..7,474.91 rows=68,056 width=35) (actual time=0.056..98.132 rows=204,172 loops=1)

  • Hash Cond: (crpg.codigo = crpg_e.contasareceber_pagtos_codigo)
50. 62.193 62.193 ↓ 3.0 204,339 1

Seq Scan on contasareceber_pagtos crpg (cost=0.00..6,609.74 rows=68,112 width=39) (actual time=0.006..62.193 rows=204,339 loops=1)

  • Filter: ((dhpagamento)::date <= (now())::date)
51. 0.027 0.044 ↑ 1.0 167 1

Hash (cost=3.67..3.67 rows=167 width=4) (actual time=0.044..0.044 rows=167 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
52. 0.017 0.017 ↑ 1.0 167 1

Seq Scan on contasareceber_pagtos_estornos crpg_e (cost=0.00..3.67 rows=167 width=4) (actual time=0.003..0.017 rows=167 loops=1)

53. 0.002 0.004 ↓ 0.0 0 1

Materialize (cost=1.39..17.72 rows=1 width=62) (actual time=0.004..0.004 rows=0 loops=1)

54. 0.000 0.002 ↓ 0.0 0 1

Nested Loop Left Join (cost=1.39..17.71 rows=1 width=62) (actual time=0.002..0.002 rows=0 loops=1)

55. 0.000 0.002 ↓ 0.0 0 1

Nested Loop Left Join (cost=0.97..13.27 rows=1 width=58) (actual time=0.002..0.002 rows=0 loops=1)

56. 0.001 0.002 ↓ 0.0 0 1

Nested Loop Left Join (cost=0.84..13.11 rows=1 width=61) (actual time=0.002..0.002 rows=0 loops=1)

57. 0.001 0.001 ↓ 0.0 0 1

Index Scan using contasareceber_pkey1 on contasareceber cr (cost=0.42..4.66 rows=1 width=57) (actual time=0.001..0.001 rows=0 loops=1)

  • Index Cond: (codigo = ANY (NULL::integer[]))
58. 0.000 0.000 ↓ 0.0 0

Index Scan using contasareceber_contasareceber_codigo_index on contasareceber_situacao cr_sit (cost=0.42..8.44 rows=1 width=8) (never executed)

  • Index Cond: (contasareceber_codigo = cr.codigo)
59. 0.000 0.000 ↓ 0.0 0

Index Scan using situacoescontas_pkey on situacoescontas sc (cost=0.13..0.15 rows=1 width=5) (never executed)

  • Index Cond: (cr_sit.situacoesconta_codigo = codigo)
60. 0.000 0.000 ↓ 0.0 0

Index Only Scan using contasareceber_faturamentos_pkey on contasareceber_faturamentos cr_fat (cost=0.42..4.44 rows=1 width=4) (never executed)

  • Index Cond: (contasareceber_codigo = cr.codigo)
  • Heap Fetches: 0
61.          

CTE datas_uteis

62. 0.000 0.000 ↓ 0.0 0

Function Scan on obter_datas_uteis diautil (cost=0.29..10.29 rows=1,000 width=4) (never executed)

63.          

Initplan (forFunction Scan)

64. 0.000 0.000 ↓ 0.0 0

Aggregate (cost=0.02..0.03 rows=1 width=4) (never executed)

65. 0.000 0.000 ↓ 0.0 0

CTE Scan on contas_pagtos (cost=0.00..0.02 rows=1 width=4) (never executed)

66.          

CTE config_carencia_juros

67. 0.000 0.000 ↓ 0.0 0

Function Scan on carenciajuros (cost=0.26..0.27 rows=1 width=4) (never executed)

68.          

CTE contas_saldos_ultimopagtoatrasado

69. 0.000 812.771 ↓ 0.0 0 1

Nested Loop (cost=0.00..0.13 rows=1 width=427) (actual time=812.771..812.771 rows=0 loops=1)

70. 812.771 812.771 ↓ 0.0 0 1

CTE Scan on contas_pagtos contas_pagtos_1 (cost=0.00..0.02 rows=1 width=423) (actual time=812.771..812.771 rows=0 loops=1)

71. 0.000 0.000 ↓ 0.0 0

CTE Scan on config_carencia_juros (cost=0.00..0.02 rows=1 width=4) (never executed)

72.          

SubPlan (forNested Loop)

73. 0.000 0.000 ↓ 0.0 0

Limit (cost=0.00..0.08 rows=1 width=4) (never executed)

74. 0.000 0.000 ↓ 0.0 0

CTE Scan on datas_uteis (cost=0.00..27.50 rows=333 width=4) (never executed)

  • Filter: (diautil >= (contas_pagtos_1.datavencimento + config_carencia_juros.carenciajuros))
75.          

CTE contas_final

76. 812.772 812.772 ↓ 0.0 0 1

CTE Scan on contas_saldos_ultimopagtoatrasado (cost=0.00..0.05 rows=1 width=428) (actual time=812.772..812.772 rows=0 loops=1)