explain.depesz.com

PostgreSQL's explain analyze made readable

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

Settings

Optimization path:

Optimization(s) for this plan:

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

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

2.          

CTE contas

3. 132.550 1,733.073 ↓ 1.0 205,446 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

13. 37.062 63.250 ↓ 1.0 205,446 1

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

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

  • Filter: (contasareceber_codigo IS NOT NULL)
15. 0.045 3.781 ↑ 1.0 176 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 16kB
16. 0.122 3.736 ↑ 1.0 176 1

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

17. 2.263 3.438 ↑ 1.0 176 1

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

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

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

19. 0.024 0.046 ↑ 1.0 176 1

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

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

Seq Scan on saidasnf_pagtos_contasareceber snfpg_cr (cost=0.00..2.76 rows=176 width=8) (actual time=0.005..0.022 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. 5.674 78.426 ↑ 1.0 28,064 1

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

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

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

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

25. 5.096 44.103 ↑ 1.0 28,064 1

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

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

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

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

28. 16.915 26.444 ↑ 1.0 93,499 1

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

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

30. 35.966 54.616 ↑ 1.0 177,399 1

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

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

32. 44.321 57.003 ↑ 1.0 205,639 1

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

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

34. 0.010 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.005 0.005 ↑ 1.0 6 1

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

36. 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
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.002..0.002 rows=4 loops=1)

38. 0.013 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.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 817.758 ↓ 0.0 0 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
41. 0.000 817.757 ↓ 0.0 0 1

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

42. 817.757 817.757 ↓ 0.0 0 1

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

  • Filter: (contasareceber_faturamentos_codigo IS NOT NULL)
43.          

CTE contas_pagtos

44. 0.001 817.753 ↓ 0.0 0 1

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

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

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

46. 53.223 817.747 ↑ 68,056.0 1 1

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

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

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

48. 109.111 208.500 ↓ 3.0 204,172 1

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

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

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

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

  • Filter: ((dhpagamento)::date <= (now())::date)
51. 0.028 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
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.002..0.017 rows=167 loops=1)

53. 0.001 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.001 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)

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 817.755 ↓ 0.0 0 1

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

70. 817.754 817.754 ↓ 0.0 0 1

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

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