explain.depesz.com

PostgreSQL's explain analyze made readable

Result: UvIL : Optimization for: Optimization for: Optimization for: plan #BEbw; plan #Wm20; plan #47YU

Settings

Optimization path:

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

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

2.          

CTE contas

3. 127.075 1,631.172 ↓ 1.0 205,446 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  • Hash Cond: (cr_1.codigo = cr_fat_1.contasareceber_codigo)
12. 16.919 16.919 ↑ 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.004..16.919 rows=205,639 loops=1)

13. 33.199 58.382 ↓ 1.0 205,446 1

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

  • Buckets: 262144 Batches: 1 Memory Usage: 9271kB
14. 25.183 25.183 ↓ 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.006..25.183 rows=205,446 loops=1)

  • Filter: (contasareceber_codigo IS NOT NULL)
15. 0.051 3.541 ↑ 1.0 176 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 16kB
16. 0.139 3.490 ↑ 1.0 176 1

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

17. 2.013 3.175 ↑ 1.0 176 1

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

  • Hash Cond: (snfpg.codigo = snfpg_cr.saidasnf_pagtos_codigo)
18. 1.120 1.120 ↑ 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.120 rows=22,122 loops=1)

19. 0.025 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.017 0.017 ↑ 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.017 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.774 68.010 ↑ 1.0 28,064 1

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

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

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

  • Hash Cond: (pv.codigo = pvpg.codprevenda)
24. 5.224 5.224 ↑ 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.224 rows=91,560 loops=1)

25. 4.089 38.838 ↑ 1.0 28,064 1

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

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

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

  • Hash Cond: (pvpg_cr.prevendas_pagtos_codigo = pvpg.codigo)
27. 1.364 1.364 ↑ 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.364 rows=28,064 loops=1)

28. 14.612 24.309 ↑ 1.0 93,499 1

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

  • Buckets: 131072 Batches: 1 Memory Usage: 4677kB
29. 9.697 9.697 ↑ 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.003..9.697 rows=93,499 loops=1)

30. 28.946 46.225 ↑ 1.0 177,399 1

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

  • Buckets: 262144 Batches: 1 Memory Usage: 8978kB
31. 17.279 17.279 ↑ 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.006..17.279 rows=177,399 loops=1)

32. 37.842 50.059 ↑ 1.0 205,639 1

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

  • Buckets: 262144 Batches: 1 Memory Usage: 10081kB
33. 12.217 12.217 ↑ 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..12.217 rows=205,639 loops=1)

34. 0.012 0.015 ↑ 1.0 6 1

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

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

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

36. 0.011 0.013 ↑ 1.0 4 1

Hash (cost=1.04..1.04 rows=4 width=13) (actual time=0.013..0.013 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.012 0.017 ↑ 1.0 22 1

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

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

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

40. 0.000 783.338 ↓ 0.0 0 1

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

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

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

42. 783.337 783.337 ↓ 0.0 0 1

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

  • Filter: (contasareceber_faturamentos_codigo IS NOT NULL)
43.          

CTE contas_pagtos

44. 0.002 783.333 ↓ 0.0 0 1

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

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

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

46. 50.931 783.325 ↑ 68,056.0 1 1

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

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

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

48. 103.298 198.635 ↓ 3.0 204,172 1

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

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

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

  • Hash Cond: (crpg.codigo = crpg_e.contasareceber_pagtos_codigo)
50. 60.329 60.329 ↓ 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..60.329 rows=204,339 loops=1)

  • Filter: ((dhpagamento)::date <= (now())::date)
51. 0.026 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.018 0.018 ↑ 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.018 rows=167 loops=1)

53. 0.003 0.005 ↓ 0.0 0 1

Materialize (cost=1.39..17.72 rows=1 width=62) (actual time=0.005..0.005 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.000 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.002 0.002 ↓ 0.0 0 1

Index Scan using contasareceber_pkey1 on contasareceber cr (cost=0.42..4.66 rows=1 width=57) (actual time=0.002..0.002 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.001 783.335 ↓ 0.0 0 1

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

70. 783.334 783.334 ↓ 0.0 0 1

CTE Scan on contas_pagtos contas_pagtos_1 (cost=0.00..0.02 rows=1 width=423) (actual time=783.334..783.334 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. 783.336 783.336 ↓ 0.0 0 1

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