explain.depesz.com

PostgreSQL's explain analyze made readable

Result: vWBJ

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.045 3,239.753 ↑ 28.3 145 1

Sort (cost=303,350.62..303,360.87 rows=4,100 width=72) (actual time=3,239.748..3,239.753 rows=145 loops=1)

  • Sort Key: foo.codigo
  • Sort Method: quicksort Memory: 36kB
2. 0.217 3,239.708 ↑ 28.3 145 1

WindowAgg (cost=272,219.92..303,104.59 rows=4,100 width=72) (actual time=2,449.824..3,239.708 rows=145 loops=1)

3. 45.227 3,239.491 ↑ 28.3 145 1

Subquery Scan on foo (cost=272,219.92..302,971.34 rows=4,100 width=48) (actual time=2,438.825..3,239.491 rows=145 loops=1)

  • Filter: (foo.clientes_codigo = 5620)
  • Rows Removed by Filter: 819893
4. 650.563 3,194.264 ↑ 1.0 820,038 1

WindowAgg (cost=272,219.92..292,720.87 rows=820,038 width=583) (actual time=2,369.218..3,194.264 rows=820,038 loops=1)

5. 535.388 2,543.701 ↑ 1.0 820,038 1

Sort (cost=272,219.92..274,270.01 rows=820,038 width=56) (actual time=2,369.208..2,543.701 rows=820,038 loops=1)

  • Sort Key: (COALESCE(pvpg.codprevenda, snfpg.codsaidasnf, cr.codigo)), (CASE WHEN (pvpg.codprevenda IS NOT NULL) THEN 'Pré-venda'::text WHEN (snfpg.codsaidasnf IS NOT NULL) THEN 'Nota de Saída'::text WHEN (cr.codigo IS NOT NULL) THEN 'Conta Avulsa'::text ELSE NULL::text END), cr.datavencimento, cr.codigo
  • Sort Method: external merge Disk: 30528kB
6. 141.600 2,008.313 ↑ 1.0 820,038 1

Hash Left Join (cost=83,371.47..135,607.33 rows=820,038 width=56) (actual time=536.220..2,008.313 rows=820,038 loops=1)

  • Hash Cond: (cr.codigo = crav.contasareceber_codigo)
7. 121.620 1,866.691 ↑ 1.0 820,038 1

Hash Left Join (cost=83,315.57..133,398.82 rows=820,038 width=24) (actual time=536.195..1,866.691 rows=820,038 loops=1)

  • Hash Cond: (cr.codigo = snfpg_cr.contasareceber_codigo)
8. 484.647 1,744.928 ↑ 1.0 820,038 1

Hash Right Join (cost=71,975.65..118,961.15 rows=820,038 width=16) (actual time=536.046..1,744.928 rows=820,038 loops=1)

  • Hash Cond: (pvpg_cr.contasareceber_codigo = cr.codigo)
9. 328.133 985.205 ↑ 1.0 819,997 1

Hash Left Join (cost=40,879.79..73,699.79 rows=819,997 width=12) (actual time=260.763..985.205 rows=819,997 loops=1)

  • Hash Cond: (pvpg.codprevenda = pv.codigo)
10. 310.223 521.787 ↑ 1.0 819,997 1

Hash Left Join (cost=16,639.69..39,012.18 rows=819,997 width=8) (actual time=125.359..521.787 rows=819,997 loops=1)

  • Hash Cond: (pvpg_cr.prevendas_pagtos_codigo = pvpg.codigo)
11. 86.304 86.304 ↑ 1.0 819,997 1

Seq Scan on prevendas_pagtos_contasareceber pvpg_cr (cost=0.00..11,828.97 rows=819,997 width=8) (actual time=0.010..86.304 rows=819,997 loops=1)

12. 69.670 125.260 ↑ 1.0 507,453 1

Hash (cost=8,313.53..8,313.53 rows=507,453 width=8) (actual time=125.260..125.260 rows=507,453 loops=1)

  • Buckets: 131072 Batches: 8 Memory Usage: 3498kB
13. 55.590 55.590 ↑ 1.0 507,453 1

Seq Scan on prevenda_pagto pvpg (cost=0.00..8,313.53 rows=507,453 width=8) (actual time=0.006..55.590 rows=507,453 loops=1)

14. 62.735 135.285 ↑ 1.0 483,071 1

Hash (cost=16,314.71..16,314.71 rows=483,071 width=8) (actual time=135.285..135.285 rows=483,071 loops=1)

  • Buckets: 131072 Batches: 8 Memory Usage: 3385kB
15. 72.550 72.550 ↑ 1.0 483,071 1

Seq Scan on prevendas pv (cost=0.00..16,314.71 rows=483,071 width=8) (actual time=0.010..72.550 rows=483,071 loops=1)

16. 128.310 275.076 ↑ 1.0 820,038 1

Hash (cost=16,840.38..16,840.38 rows=820,038 width=16) (actual time=275.076..275.076 rows=820,038 loops=1)

  • Buckets: 131072 Batches: 16 Memory Usage: 3233kB
17. 146.766 146.766 ↑ 1.0 820,038 1

Seq Scan on contasareceber cr (cost=0.00..16,840.38 rows=820,038 width=16) (actual time=0.032..146.766 rows=820,038 loops=1)

18. 0.005 0.143 ↑ 64.6 35 1

Hash (cost=11,311.68..11,311.68 rows=2,260 width=12) (actual time=0.143..0.143 rows=35 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 34kB
19. 0.000 0.138 ↑ 64.6 35 1

Nested Loop Left Join (cost=0.84..11,311.68 rows=2,260 width=12) (actual time=0.019..0.138 rows=35 loops=1)

20. 0.000 0.072 ↑ 64.6 35 1

Nested Loop Left Join (cost=0.42..9,943.00 rows=2,260 width=8) (actual time=0.013..0.072 rows=35 loops=1)

21. 0.006 0.006 ↑ 64.6 35 1

Seq Scan on saidasnf_pagtos_contasareceber snfpg_cr (cost=0.00..32.60 rows=2,260 width=8) (actual time=0.004..0.006 rows=35 loops=1)

22. 0.070 0.070 ↑ 1.0 1 35

Index Scan using saidasnf_pagto_pkey on saidasnf_pagto snfpg (cost=0.42..4.39 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=35)

  • Index Cond: (snfpg_cr.saidasnf_pagtos_codigo = codigo)
23. 0.070 0.070 ↑ 1.0 1 35

Index Scan using saidasnf_codigo_index on saidasnf snf (cost=0.42..0.61 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=35)

  • Index Cond: (snfpg.codsaidasnf = codigo)
24. 0.002 0.022 ↑ 340.0 6 1

Hash (cost=30.40..30.40 rows=2,040 width=8) (actual time=0.021..0.022 rows=6 loops=1)

  • Buckets: 2048 Batches: 1 Memory Usage: 17kB
25. 0.020 0.020 ↑ 340.0 6 1

Seq Scan on contasareceber_avulsas crav (cost=0.00..30.40 rows=2,040 width=8) (actual time=0.020..0.020 rows=6 loops=1)

Planning time : 2.293 ms
Execution time : 3,245.669 ms