explain.depesz.com

PostgreSQL's explain analyze made readable

Result: KpwE

Settings
# exclusive inclusive rows x rows loops node
1. 305.224 2,420.938 ↑ 1.4 46,497 1

Hash Left Join (cost=62,072.53..20,647,721.58 rows=64,378 width=1,258) (actual time=928.271..2,420.938 rows=46,497 loops=1)

  • Hash Cond: (a_4.uf = a_5.uf_orig)
  • Join Filter: (((CASE WHEN (btrim((a_7.dt_doc)::text) = ''::text) THEN NULL::date ELSE to_date((a_7.dt_doc)::text, 'ddMMyyyy'::text) END) >= to_date((a_5.dt_inicial)::text, 'yyyymmdd'::text)) AND ((CASE WHEN (btrim((a_7.dt_doc)::text) = ''::text) THEN NULL::date ELSE to_date((a_7.dt_doc)::text, 'ddMMyyyy'::text) END) <= to_date((a_5.dt_final)::text, 'yyyymmdd'::text)))
  • Rows Removed by Join Filter: 12620
2. 26.298 2,104.424 ↑ 1.4 46,497 1

Hash Left Join (cost=61,987.25..20,633,058.86 rows=64,378 width=1,873) (actual time=916.503..2,104.424 rows=46,497 loops=1)

  • Hash Cond: ((CASE WHEN (a_6.cod_mun IS NULL) THEN ''::bpchar ELSE a_6.cod_mun END) = a_4.cod_mun)
3. 20.410 2,055.113 ↑ 1.4 46,497 1

Hash Left Join (cost=61,607.88..20,631,713.94 rows=64,355 width=1,870) (actual time=893.476..2,055.113 rows=46,497 loops=1)

  • Hash Cond: ((a_7.fk_0000 = a.fk_0000) AND (a_3.cod_nat = a.cod_nat))
4. 30.379 2,034.464 ↑ 1.4 46,497 1

Hash Left Join (cost=61,592.13..20,627,672.30 rows=64,355 width=1,611) (actual time=893.215..2,034.464 rows=46,497 loops=1)

  • Hash Cond: ((a_7.fk_0000 = a_1.fk_0000) AND (a_3.unid = a_1.unid))
5. 72.123 1,991.202 ↑ 1.4 46,497 1

Nested Loop Left Join (cost=61,576.38..20,623,630.66 rows=64,355 width=1,352) (actual time=880.269..1,991.202 rows=46,497 loops=1)

6. 44.572 1,035.636 ↑ 1.4 46,497 1

Hash Join (cost=61,575.96..20,585,901.57 rows=64,355 width=1,076) (actual time=860.900..1,035.636 rows=46,497 loops=1)

  • Hash Cond: (a_7.id = a_3.fk_c100)
7. 57.354 501.670 ↑ 126.8 21,544 1

Merge Join (cost=53,678.98..20,153,839.50 rows=2,732,397 width=375) (actual time=371.160..501.670 rows=21,544 loops=1)

  • Merge Cond: (a_7.fk_0000 = b.fk_0000)
  • Join Filter: (CASE WHEN (b.tipo = 'C100'::bpchar) THEN ((CASE WHEN (a_7.dt_e_s <> ''::bpchar) THEN to_date((a_7.dt_e_s)::text, 'ddMMyyyy'::text) ELSE to_date((a_7.dt_doc)::text, 'ddMMyyyy'::text) END >= (SubPlan 1)) AND (CASE WHEN (a_7.dt_e_s <> ''::bpchar) THEN to_date((a_7.dt_e_s)::text, 'ddMMyyyy'::text) ELSE to_date((a_7.dt_doc)::text, 'ddMMyyyy'::text) END <= $1)) ELSE true END AND (SubPlan 3) AND (SubPlan 4))
8.          

Initplan (forMerge Join)

9. 0.000 0.000 ↓ 0.0 0

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

10. 0.000 0.000 ↓ 0.0 0

Seq Scan on tab_cenario_fiscal_parametros c_1 (cost=0.00..23.20 rows=880 width=4) (never executed)

11. 18.094 277.121 ↑ 3.3 21,545 1

Merge Left Join (cost=11,017.92..11,829.58 rows=70,971 width=308) (actual time=256.073..277.121 rows=21,545 loops=1)

  • Merge Cond: ((a_7.fk_0000 = a_6.fk_0000) AND (a_7.cod_part = a_6.cod_part))
  • Filter: (CASE WHEN (a_6.cod_mun IS NULL) THEN ''::bpchar ELSE a_6.cod_mun END IS NOT NULL)
12. 60.761 257.813 ↑ 3.3 21,545 1

Sort (cost=10,990.29..11,168.61 rows=71,328 width=157) (actual time=254.918..257.813 rows=21,545 loops=1)

  • Sort Key: a_7.fk_0000, a_7.cod_part
  • Sort Method: quicksort Memory: 22007kB
13. 197.052 197.052 ↑ 1.0 71,281 1

Seq Scan on reg_c100 a_7 (cost=0.00..5,240.48 rows=71,328 width=157) (actual time=15.047..197.052 rows=71,281 loops=1)

  • Filter: ((cod_part IS NOT NULL) AND (id IS NOT NULL))
14. 0.886 1.214 ↓ 2.6 647 1

Sort (cost=27.63..28.26 rows=253 width=216) (actual time=1.146..1.214 rows=647 loops=1)

  • Sort Key: a_6.fk_0000, a_6.cod_part
  • Sort Method: quicksort Memory: 92kB
15. 0.328 0.328 ↑ 1.0 253 1

Seq Scan on reg_0150 a_6 (cost=0.00..17.53 rows=253 width=216) (actual time=0.050..0.328 rows=253 loops=1)

16. 1.729 102.563 ↑ 61,600.0 1 1

Sort (cost=42,661.03..42,815.03 rows=61,600 width=114) (actual time=100.841..102.563 rows=1 loops=1)

  • Sort Key: b.fk_0000
  • Sort Method: quicksort Memory: 25kB
17. 0.003 100.834 ↑ 61,600.0 1 1

Subquery Scan on b (cost=0.00..37,760.55 rows=61,600 width=114) (actual time=100.817..100.834 rows=1 loops=1)

18. 73.183 100.831 ↑ 61,600.0 1 1

Nested Loop (cost=0.00..37,144.55 rows=61,600 width=140) (actual time=100.814..100.831 rows=1 loops=1)

  • Join Filter: CASE WHEN (a_8.tipo = '0000'::bpchar) THEN ((to_date(""substring""((b_1.dt_in)::text, 3, 6), 'MMyyyy'::text) >= to_date((a_8.data_inicial)::text, 'yyyyMM'::text)) AND (to_date(""substring""((b_1.dt_in)::text, 3, 6), 'MMyyyy'::text) <= to_date((a_8.data_final)::text, 'yyyyMM'::text))) ELSE true END
  • Rows Removed by Join Filter: 3
19. 16.858 16.858 ↑ 880.0 1 1

Seq Scan on tab_cenario_fiscal_parametros a_8 (cost=0.00..18.80 rows=880 width=60) (actual time=16.857..16.858 rows=1 loops=1)

20. 0.018 10.790 ↑ 35.0 4 1

Materialize (cost=0.00..12.10 rows=140 width=27) (actual time=10.785..10.790 rows=4 loops=1)

21. 10.772 10.772 ↑ 35.0 4 1

Seq Scan on reg_0000 b_1 (cost=0.00..11.40 rows=140 width=27) (actual time=10.769..10.772 rows=4 loops=1)

22.          

SubPlan (forMerge Join)

23. 0.000 0.000 ↓ 0.0 0

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

24. 0.000 0.000 ↓ 0.0 0

Seq Scan on tab_cenario_fiscal_parametros c (cost=0.00..23.20 rows=880 width=4) (never executed)

25. 43.088 43.088 ↑ 50.0 2 21,544

ProjectSet (cost=0.00..0.52 rows=100 width=32) (actual time=0.002..0.002 rows=2 loops=21,544)

26. 0.000 0.000 ↑ 1.0 1 21,544

Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.000..0.000 rows=1 loops=21,544)

27. 21.544 21.544 ↑ 100.0 1 21,544

ProjectSet (cost=0.00..0.52 rows=100 width=32) (actual time=0.001..0.001 rows=1 loops=21,544)

28. 0.000 0.000 ↑ 1.0 1 21,544

Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.000..0.000 rows=1 loops=21,544)

29. 86.333 489.394 ↑ 1.0 64,340 1

Hash (cost=7,092.55..7,092.55 rows=64,355 width=717) (actual time=489.394..489.394 rows=64,340 loops=1)

  • Buckets: 65536 Batches: 1 Memory Usage: 48154kB
30. 403.061 403.061 ↑ 1.0 64,340 1

Seq Scan on reg_c170 a_3 (cost=0.00..7,092.55 rows=64,355 width=717) (actual time=0.017..403.061 rows=64,340 loops=1)

  • Filter: ((cod_item IS NOT NULL) AND (unid IS NOT NULL) AND (cod_nat IS NOT NULL))
31. 883.443 883.443 ↑ 1.0 1 46,497

Index Scan using reg_0200_cod_item_fk_0000_idx on reg_0200 a_2 (cost=0.41..0.58 rows=1 width=341) (actual time=0.019..0.019 rows=1 loops=46,497)

  • Index Cond: ((cod_item = a_3.cod_item) AND (fk_0000 = a_7.fk_0000))
32. 0.017 12.883 ↑ 57.5 4 1

Hash (cost=12.30..12.30 rows=230 width=273) (actual time=12.883..12.883 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
33. 12.866 12.866 ↑ 57.5 4 1

Seq Scan on reg_0190 a_1 (cost=0.00..12.30 rows=230 width=273) (actual time=12.864..12.866 rows=4 loops=1)

34. 0.000 0.239 ↓ 0.0 0 1

Hash (cost=12.30..12.30 rows=230 width=277) (actual time=0.239..0.239 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
35. 0.239 0.239 ↓ 0.0 0 1

Seq Scan on reg_0400 a (cost=0.00..12.30 rows=230 width=277) (actual time=0.239..0.239 rows=0 loops=1)

36. 2.709 23.013 ↑ 1.0 5,570 1

Hash (cost=309.72..309.72 rows=5,572 width=270) (actual time=23.013..23.013 rows=5,570 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 1713kB
37. 20.304 20.304 ↑ 1.0 5,570 1

Seq Scan on tab_municipios_ibge a_4 (cost=0.00..309.72 rows=5,572 width=270) (actual time=0.016..20.304 rows=5,570 loops=1)

38. 0.063 11.290 ↓ 7.4 81 1

Hash (cost=85.14..85.14 rows=11 width=26) (actual time=11.290..11.290 rows=81 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 13kB
39. 11.227 11.227 ↓ 7.4 81 1

Seq Scan on tab_aliq_interestaduais a_5 (cost=0.00..85.14 rows=11 width=26) (actual time=9.369..11.227 rows=81 loops=1)

  • Filter: (upper(btrim((uf_orig)::text)) = upper(btrim((uf_dest)::text)))
  • Rows Removed by Filter: 2106