explain.depesz.com

PostgreSQL's explain analyze made readable

Result: r1N8 : Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: Optimization for: plan #Uty0; plan #oKUj; plan #1Rpu; plan #sxgX; plan #GP1; plan #8BPr; plan #w1WL; plan #hu9E; plan #jHPe; plan #AswY

Settings

Optimization path:

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.050 41,084.083 ↑ 1.0 100 1

Limit (cost=2,115,398.99..2,145,677.07 rows=100 width=843) (actual time=40,989.658..41,084.083 rows=100 loops=1)

2. 0.178 41,084.033 ↑ 7,018.5 100 1

Subquery Scan on final (cost=2,115,398.99..214,622,695.66 rows=701,852 width=843) (actual time=40,989.656..41,084.033 rows=100 loops=1)

3. 4.043 41,083.855 ↑ 7,018.5 100 1

Nested Loop Left Join (cost=2,115,398.99..214,601,640.10 rows=701,852 width=891) (actual time=40,989.651..41,083.855 rows=100 loops=1)

4. 0.091 41,055.812 ↑ 7,018.5 100 1

Nested Loop Left Join (cost=2,115,390.54..208,467,453.62 rows=701,852 width=747) (actual time=40,988.557..41,055.812 rows=100 loops=1)

5. 0.259 41,055.521 ↑ 7,018.5 100 1

Nested Loop (cost=2,115,390.26..208,255,154.24 rows=701,852 width=747) (actual time=40,988.549..41,055.521 rows=100 loops=1)

6. 0.178 41,055.162 ↑ 7,018.5 100 1

Nested Loop (cost=2,115,390.11..208,139,976.18 rows=701,852 width=727) (actual time=40,988.539..41,055.162 rows=100 loops=1)

7. 0.167 41,054.784 ↑ 29,243.8 100 1

Hash Join (cost=2,115,389.97..207,678,079.20 rows=2,924,383 width=727) (actual time=40,988.528..41,054.784 rows=100 loops=1)

  • Hash Cond: (COALESCE(sistema_de_gestao.hospital_id, valor_esperado.hospital_id) = hospital.id)
8. 0.233 41,054.305 ↑ 5,848,766.4 100 1

Hash Full Join (cost=2,115,388.95..206,110,243.24 rows=584,876,639 width=607) (actual time=40,988.207..41,054.305 rows=100 loops=1)

  • Hash Cond: ((CASE WHEN (remessa.rem_numero ~ '^[0-9]+$'::text) THEN (concat_immutable(VARIADIC ARRAY[(remessa.sistema_de_gestao_id)::text, remessa.rem_numero]))::numeric ELSE (concat_immutable(VARIADIC ARRAY[(remessa.sistema_de_gestao_id)::text, (abs(((('x'::text || substr(md5(remessa.rem_numero), 1, 16)))::bit(16))::integer))::text]))::numeric END) = valor_esperado.entidade_id)
9. 69.282 40,874.660 ↑ 31,071.6 100 1

GroupAggregate (cost=2,091,616.23..185,575,783.45 rows=3,107,162 width=499) (actual time=40,808.733..40,874.660 rows=100 loops=1)

  • Group Key: remessa.id, justificativa.id, sistema_de_gestao.hospital_id, convenio_1.id, operadora_1.id, competencia_1.id, rpa.id
10. 2,971.542 40,801.748 ↑ 620.1 5,011 1

Sort (cost=2,091,616.23..2,099,384.14 rows=3,107,162 width=455) (actual time=40,800.269..40,801.748 rows=5,011 loops=1)

  • Sort Key: remessa.id, justificativa.id, sistema_de_gestao.hospital_id, convenio_1.id, operadora_1.id, competencia_1.id, rpa.id
  • Sort Method: external merge Disk: 593,136kB
11. 1,060.326 37,830.206 ↑ 1.0 2,987,733 1

Hash Left Join (cost=524,706.43..1,119,339.34 rows=3,107,162 width=455) (actual time=14,192.450..37,830.206 rows=2,987,733 loops=1)

  • Hash Cond: ((convenio_1.convnome = rpa.nome_convenio) AND (remessa.rem_numero = rpa.numero_remessa))
12. 753.884 36,769.878 ↑ 1.0 2,987,733 1

Nested Loop (cost=524,690.93..1,103,011.24 rows=3,107,162 width=259) (actual time=14,192.444..36,769.878 rows=2,987,733 loops=1)

  • Join Filter: (remessa.sistema_de_gestao_id = sistema_de_gestao.id)
13. 0.005 0.005 ↑ 1.0 1 1

Seq Scan on sistema_de_gestao (cost=0.00..1.01 rows=1 width=16) (actual time=0.004..0.005 rows=1 loops=1)

14. 922.860 36,015.989 ↑ 1.0 2,987,733 1

Hash Left Join (cost=524,690.93..1,064,170.71 rows=3,107,162 width=251) (actual time=14,192.436..36,015.989 rows=2,987,733 loops=1)

  • Hash Cond: ((remessa.rem_numero = justificativa.numero_remessa) AND (remessa.sistema_de_gestao_id = justificativa.sistema_de_gestao_id))
15. 869.540 35,091.845 ↑ 1.0 2,987,733 1

Hash Left Join (cost=524,689.61..1,047,856.73 rows=3,107,162 width=179) (actual time=14,191.146..35,091.845 rows=2,987,733 loops=1)

  • Hash Cond: (guia_convenio.recebimento_id = recebimento.id)
16. 1,067.020 34,212.544 ↑ 1.0 2,987,733 1

Hash Left Join (cost=524,405.08..1,039,413.33 rows=3,107,162 width=183) (actual time=14,181.374..34,212.544 rows=2,987,733 loops=1)

  • Hash Cond: (guia_convenio.guiprotocolo = protocolo_convenio.id)
17. 1,424.281 32,648.705 ↑ 1.0 2,987,733 1

Hash Join (cost=473,152.36..980,004.29 rows=3,107,162 width=183) (actual time=13,681.889..32,648.705 rows=2,987,733 loops=1)

  • Hash Cond: (guia_prestador.guiremessa = remessa.id)
18. 4,504.239 31,153.090 ↑ 1.0 2,987,856 1

Hash Left Join (cost=470,052.85..947,724.39 rows=3,107,162 width=46) (actual time=13,610.525..31,153.090 rows=2,987,856 loops=1)

  • Hash Cond: (guia_prestador.guiguiaassoc = guia_convenio.id)
19. 13,040.880 13,040.880 ↑ 1.0 2,987,856 1

Seq Scan on fiboguia guia_prestador (cost=0.00..393,423.23 rows=3,107,162 width=30) (actual time=1.897..13,040.880 rows=2,987,856 loops=1)

  • Filter: ((discriminador <> 'RECURSO'::text) AND (guiorigem = 'HOSPITAL'::text))
  • Rows Removed by Filter: 2,747,008
20. 1,808.575 13,607.971 ↑ 1.0 5,734,864 1

Hash (cost=364,743.49..364,743.49 rows=5,735,949 width=24) (actual time=13,607.971..13,607.971 rows=5,734,864 loops=1)

  • Buckets: 2,097,152 Batches: 4 Memory Usage: 88,271kB
21. 11,799.396 11,799.396 ↑ 1.0 5,734,864 1

Seq Scan on fiboguia guia_convenio (cost=0.00..364,743.49 rows=5,735,949 width=24) (actual time=0.015..11,799.396 rows=5,734,864 loops=1)

22. 18.153 71.334 ↑ 1.0 58,270 1

Hash (cost=2,371.12..2,371.12 rows=58,271 width=145) (actual time=71.334..71.334 rows=58,270 loops=1)

  • Buckets: 65,536 Batches: 1 Memory Usage: 11,877kB
23. 11.452 53.181 ↑ 1.0 58,270 1

Hash Join (cost=113.53..2,371.12 rows=58,271 width=145) (actual time=0.690..53.181 rows=58,270 loops=1)

  • Hash Cond: (remessa.operadora_id = operadora_1.id)
24. 12.767 41.717 ↑ 1.0 58,270 1

Hash Join (cost=111.45..2,202.57 rows=58,271 width=145) (actual time=0.673..41.717 rows=58,270 loops=1)

  • Hash Cond: (competencia_1.comp_convenio = convenio_1.convnome)
25. 11.643 28.825 ↑ 1.0 58,270 1

Hash Join (cost=92.92..2,027.86 rows=58,271 width=128) (actual time=0.544..28.825 rows=58,270 loops=1)

  • Hash Cond: (remessa.remcompetencia = competencia_1.id)
26. 16.646 16.646 ↑ 1.0 58,270 1

Seq Scan on fiboremessa remessa (cost=0.00..1,781.71 rows=58,271 width=117) (actual time=0.004..16.646 rows=58,270 loops=1)

  • Filter: ((rem_numero IS NOT NULL) AND (sistema_de_gestao_id IS NOT NULL))
  • Rows Removed by Filter: 1
27. 0.273 0.536 ↑ 1.0 2,441 1

Hash (cost=62.41..62.41 rows=2,441 width=19) (actual time=0.536..0.536 rows=2,441 loops=1)

  • Buckets: 4,096 Batches: 1 Memory Usage: 156kB
28. 0.263 0.263 ↑ 1.0 2,441 1

Seq Scan on fibocompetencia competencia_1 (cost=0.00..62.41 rows=2,441 width=19) (actual time=0.004..0.263 rows=2,441 loops=1)

29. 0.034 0.125 ↑ 1.0 201 1

Hash (cost=16.01..16.01 rows=201 width=28) (actual time=0.125..0.125 rows=201 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 20kB
30. 0.091 0.091 ↑ 1.0 201 1

Seq Scan on fiboconvenio convenio_1 (cost=0.00..16.01 rows=201 width=28) (actual time=0.004..0.091 rows=201 loops=1)

31. 0.005 0.012 ↑ 1.0 48 1

Hash (cost=1.48..1.48 rows=48 width=8) (actual time=0.012..0.012 rows=48 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 10kB
32. 0.007 0.007 ↑ 1.0 48 1

Seq Scan on fibooperadora operadora_1 (cost=0.00..1.48 rows=48 width=8) (actual time=0.004..0.007 rows=48 loops=1)

33. 233.766 496.819 ↑ 1.0 1,276,343 1

Hash (cost=35,298.43..35,298.43 rows=1,276,343 width=16) (actual time=496.819..496.819 rows=1,276,343 loops=1)

  • Buckets: 2,097,152 Batches: 1 Memory Usage: 74,617kB
34. 263.053 263.053 ↑ 1.0 1,276,343 1

Seq Scan on fiboprotocolo protocolo_convenio (cost=0.00..35,298.43 rows=1,276,343 width=16) (actual time=0.696..263.053 rows=1,276,343 loops=1)

35. 0.583 9.761 ↑ 1.0 5,668 1

Hash (cost=213.68..213.68 rows=5,668 width=12) (actual time=9.761..9.761 rows=5,668 loops=1)

  • Buckets: 8,192 Batches: 1 Memory Usage: 330kB
36. 9.178 9.178 ↑ 1.0 5,668 1

Seq Scan on recebimento (cost=0.00..213.68 rows=5,668 width=12) (actual time=0.512..9.178 rows=5,668 loops=1)

37. 0.006 1.284 ↑ 1.0 13 1

Hash (cost=1.13..1.13 rows=13 width=112) (actual time=1.284..1.284 rows=13 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 10kB
38. 1.278 1.278 ↑ 1.0 13 1

Seq Scan on fibojustifdifvaloresfaturados justificativa (cost=0.00..1.13 rows=13 width=112) (actual time=1.276..1.278 rows=13 loops=1)

39. 0.000 0.002 ↓ 0.0 0 1

Hash (cost=12.20..12.20 rows=220 width=272) (actual time=0.002..0.002 rows=0 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 8kB
40. 0.002 0.002 ↓ 0.0 0 1

Seq Scan on detalhes_quitacao_rpa rpa (cost=0.00..12.20 rows=220 width=272) (actual time=0.002..0.002 rows=0 loops=1)

41.          

SubPlan (for GroupAggregate)

42. 0.100 0.300 ↑ 1.0 1 100

Aggregate (cost=8.30..8.31 rows=1 width=32) (actual time=0.003..0.003 rows=1 loops=100)

43. 0.200 0.200 ↓ 0.0 0 100

Index Scan using idx_recebimento_remessa_remessa_id_idx on recebimento_remessa lancamentos_manuais_na_remessa (cost=0.28..8.29 rows=1 width=7) (actual time=0.002..0.002 rows=0 loops=100)

  • Index Cond: (remessa.id = remessa_id)
44. 0.000 0.000 ↓ 0.0 0

Index Only Scan using idx_recebimento_remessa_remessa_id_idx on recebimento_remessa lancamentos_manuais_na_remessa_1 (cost=0.28..8.29 rows=1 width=0) (never executed)

  • Index Cond: (remessa_id = remessa.id)
  • Heap Fetches: 0
45. 0.690 0.690 ↑ 1.0 873 1

Seq Scan on recebimento_remessa lancamentos_manuais_na_remessa_2 (cost=0.00..19.73 rows=873 width=8) (actual time=0.295..0.690 rows=873 loops=1)

46. 0.100 0.500 ↑ 1.0 1 100

Aggregate (cost=16.62..16.63 rows=1 width=32) (actual time=0.005..0.005 rows=1 loops=100)

47. 0.000 0.400 ↓ 0.0 0 100

Nested Loop (cost=0.56..16.61 rows=1 width=7) (actual time=0.004..0.004 rows=0 loops=100)

48. 0.200 0.200 ↓ 0.0 0 100

Index Scan using lancamento_remessa_remessa_id_fato_contabil_id_unique on lancamento_remessa lancamentos_acrescimos_na_remessa (cost=0.28..8.30 rows=1 width=15) (actual time=0.002..0.002 rows=0 loops=100)

  • Index Cond: (remessa.id = remessa_id)
49. 0.209 0.209 ↑ 1.0 1 1

Index Scan using fato_contabil_pkey on fato_contabil (cost=0.28..8.30 rows=1 width=8) (actual time=0.209..0.209 rows=1 loops=1)

  • Index Cond: (id = lancamentos_acrescimos_na_remessa.fato_contabil_id)
  • Filter: (tipo = 'Acrescimo'::text)
50. 0.100 0.200 ↑ 1.0 1 100

Aggregate (cost=16.66..16.67 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=100)

51. 0.000 0.100 ↓ 0.0 0 100

Nested Loop (cost=0.56..16.65 rows=1 width=7) (actual time=0.001..0.001 rows=0 loops=100)

52. 0.100 0.100 ↓ 0.0 0 100

Index Scan using lancamento_remessa_remessa_id_fato_contabil_id_unique on lancamento_remessa lancamentos_deducoes_na_remessa (cost=0.28..8.30 rows=1 width=15) (actual time=0.001..0.001 rows=0 loops=100)

  • Index Cond: (remessa.id = remessa_id)
53. 0.003 0.003 ↓ 0.0 0 1

Index Scan using fato_contabil_pkey on fato_contabil fato_contabil_1 (cost=0.28..8.30 rows=1 width=8) (actual time=0.003..0.003 rows=0 loops=1)

  • Index Cond: (id = lancamentos_deducoes_na_remessa.fato_contabil_id)
  • Filter: (tipo = 'Deducao'::text)
  • Rows Removed by Filter: 1
54. 0.000 0.000 ↓ 0.0 0

Index Only Scan using idx_lancamento_remessa_remessa_id_idx on lancamento_remessa lancamentos_fatos_contabeis_na_remessa (cost=0.28..8.30 rows=1 width=0) (never executed)

  • Index Cond: (remessa_id = remessa.id)
  • Heap Fetches: 0
55. 1.940 1.940 ↑ 1.0 3,982 1

Seq Scan on lancamento_remessa lancamentos_fatos_contabeis_na_remessa_1 (cost=0.00..77.82 rows=3,982 width=8) (actual time=0.006..1.940 rows=3,982 loops=1)

56. 15.839 179.412 ↑ 1.0 37,647 1

Hash (cost=23,302.13..23,302.13 rows=37,647 width=132) (actual time=179.412..179.412 rows=37,647 loops=1)

  • Buckets: 65,536 Batches: 1 Memory Usage: 6,520kB
57. 7.017 163.573 ↑ 1.0 37,647 1

Subquery Scan on valor_esperado (cost=119.63..23,302.13 rows=37,647 width=132) (actual time=3.030..163.573 rows=37,647 loops=1)

58. 100.573 156.556 ↑ 1.0 37,647 1

Hash Left Join (cost=119.63..22,925.66 rows=37,647 width=140) (actual time=3.029..156.556 rows=37,647 loops=1)

  • Hash Cond: ((COALESCE(convenio_2.convnome, valor_faturado.convenio_integracao) = competencia_2.comp_convenio) AND (valor_faturado.competencia = competencia_2.comp_desc))
59. 10.855 54.734 ↑ 1.0 37,647 1

Hash Join (cost=20.60..1,452.52 rows=37,647 width=131) (actual time=1.714..54.734 rows=37,647 loops=1)

  • Hash Cond: (operadora_2.opconvenio = convenio_2.id)
60. 14.301 43.674 ↑ 1.0 37,647 1

Hash Join (cost=2.08..1,333.10 rows=37,647 width=111) (actual time=1.505..43.674 rows=37,647 loops=1)

  • Hash Cond: (valor_faturado.id_operadora = operadora_2.id)
61. 29.352 29.352 ↑ 1.0 37,647 1

Seq Scan on fibovaloresfaturadoserp valor_faturado (cost=0.00..1,223.47 rows=37,647 width=103) (actual time=1.478..29.352 rows=37,647 loops=1)

  • Filter: (numero_remessa IS NOT NULL)
62. 0.010 0.021 ↑ 1.0 48 1

Hash (cost=1.48..1.48 rows=48 width=16) (actual time=0.021..0.021 rows=48 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 11kB
63. 0.011 0.011 ↑ 1.0 48 1

Seq Scan on fibooperadora operadora_2 (cost=0.00..1.48 rows=48 width=16) (actual time=0.005..0.011 rows=48 loops=1)

64. 0.053 0.205 ↑ 1.0 201 1

Hash (cost=16.01..16.01 rows=201 width=28) (actual time=0.205..0.205 rows=201 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 20kB
65. 0.152 0.152 ↑ 1.0 201 1

Seq Scan on fiboconvenio convenio_2 (cost=0.00..16.01 rows=201 width=28) (actual time=0.005..0.152 rows=201 loops=1)

66. 0.790 1.249 ↑ 1.0 2,441 1

Hash (cost=62.41..62.41 rows=2,441 width=27) (actual time=1.248..1.249 rows=2,441 loops=1)

  • Buckets: 4,096 Batches: 1 Memory Usage: 175kB
67. 0.459 0.459 ↑ 1.0 2,441 1

Seq Scan on fibocompetencia competencia_2 (cost=0.00..62.41 rows=2,441 width=27) (actual time=0.005..0.459 rows=2,441 loops=1)

68. 0.003 0.312 ↑ 1.0 1 1

Hash (cost=1.01..1.01 rows=1 width=136) (actual time=0.312..0.312 rows=1 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
69. 0.309 0.309 ↑ 1.0 1 1

Seq Scan on fibohospital hospital (cost=0.00..1.01 rows=1 width=136) (actual time=0.309..0.309 rows=1 loops=1)

70. 0.200 0.200 ↑ 1.0 1 100

Index Scan using view_smartdata_operadoras_operadora_id_unique on view_smartdata_operadoras operadora (cost=0.14..0.16 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=100)

  • Index Cond: (operadora_id = COALESCE(operadora_1.id, valor_esperado.operadora_id))
71. 0.100 0.100 ↑ 1.0 1 100

Index Scan using fiboconvenio_pkey on fiboconvenio convenio (cost=0.14..0.16 rows=1 width=36) (actual time=0.001..0.001 rows=1 loops=100)

  • Index Cond: (id = COALESCE(convenio_1.id, valor_esperado.convenio_id))
72. 0.200 0.200 ↑ 1.0 1 100

Index Scan using fibocompetencia_pkey on fibocompetencia competencia (cost=0.28..0.30 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=100)

  • Index Cond: (COALESCE(competencia_1.id, valor_esperado.competencia_id) = id)
73. 0.200 24.000 ↑ 1.0 1 100

Result (cost=8.46..8.46 rows=1 width=1) (actual time=0.240..0.240 rows=1 loops=100)

74.          

Initplan (for Result)

75. 23.800 23.800 ↑ 1.0 1 100

Index Scan using idx_fiboarquivo_numero_remessa_idx on fiboarquivo arquivo (cost=0.43..8.46 rows=1 width=0) (actual time=0.238..0.238 rows=1 loops=100)

  • Index Cond: (COALESCE($9, $10) = numero_remessa)
  • Filter: ((cnpj_hospital = $11) AND (lower(metadado_nome_convenio) = lower($12)))
Planning time : 83.647 ms
Execution time : 41,158.032 ms