explain.depesz.com

PostgreSQL's explain analyze made readable

Result: Uty0

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.036 15,507.717 ↑ 1.0 100 1

Limit (cost=3,171,707.48..3,201,985.56 rows=100 width=843) (actual time=15,459.288..15,507.717 rows=100 loops=1)

2. 0.122 15,507.681 ↑ 12,384.5 100 1

Subquery Scan on final (cost=3,171,707.48..378,149,979.82 rows=1,238,448 width=843) (actual time=15,459.286..15,507.681 rows=100 loops=1)

3. 2.046 15,507.559 ↑ 12,384.5 100 1

Nested Loop Left Join (cost=3,171,707.48..378,112,826.38 rows=1,238,448 width=891) (actual time=15,459.282..15,507.559 rows=100 loops=1)

4. 0.085 15,504.813 ↑ 12,384.5 100 1

Nested Loop Left Join (cost=3,171,699.03..367,288,790.86 rows=1,238,448 width=747) (actual time=15,459.228..15,504.813 rows=100 loops=1)

5. 0.131 15,504.628 ↑ 12,384.5 100 1

Nested Loop (cost=3,171,698.75..366,914,179.46 rows=1,238,448 width=747) (actual time=15,459.223..15,504.628 rows=100 loops=1)

6. 0.120 15,504.397 ↑ 12,384.5 100 1

Nested Loop (cost=3,171,698.60..366,710,942.80 rows=1,238,448 width=727) (actual time=15,459.218..15,504.397 rows=100 loops=1)

7. 0.092 15,504.177 ↑ 51,602.0 100 1

Hash Join (cost=3,171,698.46..365,895,905.65 rows=5,160,200 width=727) (actual time=15,459.210..15,504.177 rows=100 loops=1)

  • Hash Cond: (COALESCE(sistema_de_gestao.hospital_id, valor_esperado.hospital_id) = hospital.id)
8. 0.179 15,504.062 ↑ 10,320,399.9 100 1

Hash Full Join (cost=3,171,697.44..363,129,392.44 rows=1,032,039,987 width=607) (actual time=15,459.176..15,504.062 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. 44.671 15,360.825 ↑ 54,827.2 100 1

GroupAggregate (cost=3,147,924.73..326,913,630.13 rows=5,482,721 width=499) (actual time=15,316.038..15,360.825 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,076.360 15,315.217 ↑ 1,094.1 5,011 1

Sort (cost=3,147,924.73..3,161,631.53 rows=5,482,721 width=455) (actual time=15,314.395..15,315.217 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: 542,448kB
11. 739.381 13,238.857 ↑ 1.8 2,987,733 1

Hash Left Join (cost=1,169,159.50..1,409,842.14 rows=5,482,721 width=455) (actual time=9,065.832..13,238.857 rows=2,987,733 loops=1)

  • Hash Cond: ((convenio_1.convnome = rpa.nome_convenio) AND (remessa.rem_numero = rpa.numero_remessa))
12. 577.992 12,499.475 ↑ 1.8 2,987,733 1

Nested Loop (cost=1,169,144.00..1,381,042.35 rows=5,482,721 width=259) (actual time=9,065.827..12,499.475 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.003..0.005 rows=1 loops=1)

14. 632.066 11,921.478 ↑ 1.8 2,987,733 1

Hash Left Join (cost=1,169,144.00..1,312,507.33 rows=5,482,721 width=251) (actual time=9,065.820..11,921.478 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. 579.101 11,289.400 ↑ 1.8 2,987,733 1

Hash Left Join (cost=1,169,142.68..1,283,721.63 rows=5,482,721 width=179) (actual time=9,065.798..11,289.400 rows=2,987,733 loops=1)

  • Hash Cond: (guia_convenio.guiprotocolo = protocolo_convenio.id)
16. 1,186.957 10,353.297 ↑ 1.8 2,987,733 1

Hash Join (cost=1,117,889.96..1,218,076.73 rows=5,482,721 width=179) (actual time=8,704.090..10,353.297 rows=2,987,733 loops=1)

  • Hash Cond: (guia_prestador.guiremessa = remessa.id)
17. 463.283 9,100.608 ↓ 1.0 5,491,696 1

Hash Right Join (cost=1,114,790.45..1,163,351.92 rows=5,482,721 width=42) (actual time=8,638.335..9,100.608 rows=5,491,696 loops=1)

  • Hash Cond: (recebimento.convenio_id = guia_convenio.id)
18. 0.766 0.766 ↑ 1.0 5,668 1

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

19. 672.639 8,636.559 ↓ 1.0 5,491,696 1

Hash (cost=998,068.44..998,068.44 rows=5,482,721 width=46) (actual time=8,636.559..8,636.559 rows=5,491,696 loops=1)

  • Buckets: 2,097,152 (originally 2097152) Batches: 8 (originally 4) Memory Usage: 331,965kB
20. 2,851.629 7,963.920 ↓ 1.0 5,491,696 1

Hash Left Join (cost=475,622.44..998,068.44 rows=5,482,721 width=46) (actual time=3,050.965..7,963.920 rows=5,491,696 loops=1)

  • Hash Cond: ((guia_prestador.discriminador || (guia_prestador.guiguiaassoc)::text) = (guia_convenio.discriminador || (guia_convenio.id)::text))
21. 2,062.043 2,062.043 ↓ 1.0 5,491,696 1

Seq Scan on fiboguia guia_prestador (cost=0.00..379,069.80 rows=5,482,721 width=39) (actual time=0.013..2,062.043 rows=5,491,696 loops=1)

  • Filter: (discriminador <> 'RECURSO'::text)
  • Rows Removed by Filter: 243,168
22. 1,575.327 3,050.248 ↑ 1.0 5,734,864 1

Hash (cost=364,732.64..364,732.64 rows=5,734,864 width=25) (actual time=3,050.248..3,050.248 rows=5,734,864 loops=1)

  • Buckets: 2,097,152 Batches: 4 Memory Usage: 105,516kB
23. 1,474.921 1,474.921 ↑ 1.0 5,734,864 1

Seq Scan on fiboguia guia_convenio (cost=0.00..364,732.64 rows=5,734,864 width=25) (actual time=0.011..1,474.921 rows=5,734,864 loops=1)

24. 17.284 65.732 ↑ 1.0 58,270 1

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

  • Buckets: 65,536 Batches: 1 Memory Usage: 11,877kB
25. 11.257 48.448 ↑ 1.0 58,270 1

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

  • Hash Cond: (remessa.operadora_id = operadora_1.id)
26. 13.020 37.179 ↑ 1.0 58,270 1

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

  • Hash Cond: (competencia_1.comp_convenio = convenio_1.convnome)
27. 11.531 24.038 ↑ 1.0 58,270 1

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

  • Hash Cond: (remessa.remcompetencia = competencia_1.id)
28. 11.969 11.969 ↑ 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..11.969 rows=58,270 loops=1)

  • Filter: ((rem_numero IS NOT NULL) AND (sistema_de_gestao_id IS NOT NULL))
  • Rows Removed by Filter: 1
29. 0.276 0.538 ↑ 1.0 2,441 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 156kB
30. 0.262 0.262 ↑ 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.262 rows=2,441 loops=1)

31. 0.032 0.121 ↑ 1.0 201 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 20kB
32. 0.089 0.089 ↑ 1.0 201 1

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

33. 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
34. 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.003..0.007 rows=48 loops=1)

35. 229.902 357.002 ↑ 1.0 1,276,343 1

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

  • Buckets: 2,097,152 Batches: 1 Memory Usage: 74,617kB
36. 127.100 127.100 ↑ 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.009..127.100 rows=1,276,343 loops=1)

37. 0.005 0.012 ↑ 1.0 13 1

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

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

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

39. 0.000 0.001 ↓ 0.0 0 1

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

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

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

41.          

SubPlan (for GroupAggregate)

42. 0.100 0.200 ↑ 1.0 1 100

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

43. 0.100 0.100 ↓ 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.001..0.001 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.084 0.084 ↑ 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.005..0.084 rows=873 loops=1)

46. 0.100 0.200 ↑ 1.0 1 100

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

47. 0.000 0.100 ↓ 0.0 0 100

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

48. 0.100 0.100 ↓ 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.001..0.001 rows=0 loops=100)

  • Index Cond: (remessa.id = remessa_id)
49. 0.004 0.004 ↑ 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.004..0.004 rows=1 loops=1)

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

Aggregate (cost=16.66..16.67 rows=1 width=32) (actual time=0.001..0.001 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.002 0.002 ↓ 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.002..0.002 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. 0.353 0.353 ↑ 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.003..0.353 rows=3,982 loops=1)

56. 13.385 143.058 ↑ 1.0 37,647 1

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

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

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

58. 91.548 123.218 ↑ 1.0 37,647 1

Hash Left Join (cost=119.63..22,925.66 rows=37,647 width=140) (actual time=3.595..123.218 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. 9.345 28.725 ↑ 1.0 37,647 1

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

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

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

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

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

  • Filter: (numero_remessa IS NOT NULL)
62. 0.023 0.047 ↑ 1.0 48 1

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

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

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

64. 0.124 0.484 ↑ 1.0 201 1

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

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

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

66. 1.834 2.945 ↑ 1.0 2,441 1

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

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

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

68. 0.006 0.023 ↑ 1.0 1 1

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

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

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

70. 0.100 0.100 ↑ 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.001..0.001 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.100 0.100 ↑ 1.0 1 100

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

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

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

74.          

Initplan (for Result)

75. 0.600 0.600 ↑ 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.006..0.006 rows=1 loops=100)

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