explain.depesz.com

PostgreSQL's explain analyze made readable

Result: BEbw

Settings

Optimization(s) for this plan:

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

CTE Scan on contas (cost=72,665.65..80,883.37 rows=205,443 width=577) (actual time=1,074.759..1,952.481 rows=205,446 loops=1)

2.          

CTE contas_saldo

3. 0.001 837.425 ↓ 0.0 0 1

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

4. 837.424 837.424 ↓ 0.0 0 1

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

  • Filter: (contasareceber_faturamentos_codigo IS NOT NULL)
5.          

CTE contas_pagtos

6. 0.003 837.421 ↓ 0.0 0 1

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

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

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

8. 53.932 837.409 ↑ 68,056.0 1 1

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

  • Sort Key: crpg.contasareceber_faturamentos_cr_codigo, crpg.dhpagamento DESC
  • Sort Method: quicksort Memory: 22096kB
9. 574.941 783.477 ↓ 3.0 204,172 1

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

10. 102.732 208.536 ↓ 3.0 204,172 1

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

  • Sort Key: crpg.contasareceber_faturamentos_cr_codigo
  • Sort Method: quicksort Memory: 22095kB
11. 40.027 105.804 ↓ 3.0 204,172 1

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

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

  • Filter: ((dhpagamento)::date <= (now())::date)
13. 0.033 0.045 ↑ 1.0 167 1

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

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

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

15. 0.004 0.007 ↓ 0.0 0 1

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

16. 0.000 0.003 ↓ 0.0 0 1

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

17. 0.001 0.003 ↓ 0.0 0 1

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

18. 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)

19. 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[]))
20. 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)
21. 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)
22. 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
23.          

CTE datas_uteis

24. 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)

25.          

Initplan (forFunction Scan)

26. 0.000 0.000 ↓ 0.0 0

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

27. 0.000 0.000 ↓ 0.0 0

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

28.          

CTE config_carencia_juros

29. 0.000 0.000 ↓ 0.0 0

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

30.          

CTE contas_saldos_ultimopagtoatrasado

31. 0.001 837.423 ↓ 0.0 0 1

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

32. 837.422 837.422 ↓ 0.0 0 1

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

33. 0.000 0.000 ↓ 0.0 0

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

34.          

SubPlan (forNested Loop)

35. 0.000 0.000 ↓ 0.0 0

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

36. 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))
37.          

CTE contas_final

38. 837.424 837.424 ↓ 0.0 0 1

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

39.          

CTE contas

40. 131.677 1,722.526 ↓ 1.0 205,446 1

Hash Left Join (cost=25,165.25..49,472.28 rows=205,443 width=166) (actual time=1,074.750..1,722.526 rows=205,446 loops=1)

  • Hash Cond: (cr_1.codigo = cr_saldo.contasareceber_codigo)
41. 50.802 753.422 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.tipodocumento_codigo = t.codigo)
42. 33.753 702.601 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.gruposcontas_codigo = grct.codigo)
43. 54.661 668.837 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_sit_1.situacoesconta_codigo = sc_1.codigo)
44. 91.610 614.162 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.codigo = cr_sit_1.contasareceber_codigo)
45. 76.600 470.636 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.codigo = crav.contasareceber_codigo)
46. 58.570 346.932 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.codigo = pvpg_cr.contasareceber_codigo)
47. 30.718 217.947 ↓ 1.0 205,446 1

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

  • Hash Cond: (cr_1.codigo = snfpg_cr.contasareceber_codigo)
48. 105.096 183.662 ↓ 1.0 205,446 1

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

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

50. 35.152 60.642 ↓ 1.0 205,446 1

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

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

  • Filter: (contasareceber_codigo IS NOT NULL)
52. 0.056 3.567 ↑ 1.0 176 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 16kB
53. 0.000 3.511 ↑ 1.0 176 1

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

54. 2.030 3.170 ↑ 1.0 176 1

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

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

56. 0.024 0.043 ↑ 1.0 176 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 15kB
57. 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)

58. 0.352 0.352 ↑ 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.002 rows=1 loops=176)

  • Index Cond: (snfpg.codsaidasnf = codigo)
59. 5.179 70.415 ↑ 1.0 28,064 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 1462kB
60. 20.750 65.236 ↑ 1.0 28,064 1

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

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

62. 4.281 39.044 ↑ 1.0 28,064 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 1353kB
63. 9.685 34.763 ↑ 1.0 28,064 1

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

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

65. 14.222 23.514 ↑ 1.0 93,499 1

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

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

67. 29.620 47.104 ↑ 1.0 177,399 1

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

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

69. 39.582 51.916 ↑ 1.0 205,639 1

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

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

71. 0.011 0.014 ↑ 1.0 6 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
72. 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)

73. 0.009 0.011 ↑ 1.0 4 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
74. 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.002..0.002 rows=4 loops=1)

75. 0.015 0.019 ↑ 1.0 22 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
76. 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)

77. 0.001 837.427 ↓ 0.0 0 1

Hash (cost=0.02..0.02 rows=1 width=76) (actual time=837.427..837.427 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
78. 837.426 837.426 ↓ 0.0 0 1

CTE Scan on contas_saldo cr_saldo (cost=0.00..0.02 rows=1 width=76) (actual time=837.426..837.426 rows=0 loops=1)