explain.depesz.com

PostgreSQL's explain analyze made readable

Result: IEZK : Optimization for: plan #NkzU

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 0.000 0.000 ↓ 0.0

Subquery Scan on gg (cost=451,131.94..452,337.35 rows=96,433 width=1,330) (actual rows= loops=)

2. 0.000 0.000 ↓ 0.0

Sort (cost=451,131.94..451,373.02 rows=96,433 width=1,362) (actual rows= loops=)

  • Sort Key: td_out.datacadastro, td_out.nomepaciente
3. 0.000 0.000 ↓ 0.0

Subquery Scan on td_out (cost=219,519.86..328,439.62 rows=96,433 width=1,362) (actual rows= loops=)

4. 0.000 0.000 ↓ 0.0

Unique (cost=219,519.86..318,796.32 rows=96,433 width=1,169) (actual rows= loops=)

5. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=219,519.86..318,555.24 rows=96,433 width=1,169) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = tbpacientes_agendamentos.idpaciente)
6. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=195,934.52..287,397.01 rows=96,433 width=1,039) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = td_prontuarios_total.idpaciente)
7. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=182,758.22..273,422.20 rows=96,433 width=1,031) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = t1_1.idpaciente)
8. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=91,385.00..180,402.42 rows=96,433 width=976) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = t1.idpaciente)
9. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=11.78..87,382.65 rows=96,433 width=921) (actual rows= loops=)

10. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=11.64..72,468.07 rows=96,433 width=889) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = tbimagens.idregistro)
11. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=2.57..72,217.69 rows=96,433 width=833) (actual rows= loops=)

  • Merge Cond: (tbpacientes.idpaciente = tbpacientes_creditos.idpaciente)
12. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=0.84..71,974.78 rows=96,433 width=801) (actual rows= loops=)

13. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=0.70..56,879.17 rows=96,433 width=793) (actual rows= loops=)

14. 0.000 0.000 ↓ 0.0

Index Scan using pk_tbpacientes on tbpacientes (cost=0.42..27,709.45 rows=96,433 width=776) (actual rows= loops=)

  • Filter: (idempresagestora = ANY ('{37,38,39}'::integer[]))
15. 0.000 0.000 ↓ 0.0

Index Scan using pk_tbcidades on tbcidades (cost=0.28..0.30 rows=1 width=21) (actual rows= loops=)

  • Index Cond: (tbpacientes.idcidade = idcidade)
16. 0.000 0.000 ↓ 0.0

Index Scan using pk_estado on tbestados (cost=0.14..0.16 rows=1 width=16) (actual rows= loops=)

  • Index Cond: (tbcidades.idestado = idestado)
17. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=1.73..1.79 rows=3 width=36) (actual rows= loops=)

  • Group Key: tbpacientes_creditos.idpaciente
18. 0.000 0.000 ↓ 0.0

Sort (cost=1.73..1.73 rows=3 width=20) (actual rows= loops=)

  • Sort Key: tbpacientes_creditos.idpaciente
19. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_creditos (cost=0.00..1.70 rows=3 width=20) (actual rows= loops=)

  • Filter: (idempresagestora = ANY ('{37,38,39}'::integer[]))
20. 0.000 0.000 ↓ 0.0

Sort (cost=8.89..9.00 rows=44 width=60) (actual rows= loops=)

  • Sort Key: tbimagens.idregistro
21. 0.000 0.000 ↓ 0.0

Seq Scan on tbimagens (cost=0.00..7.69 rows=44 width=60) (actual rows= loops=)

  • Filter: ((idobjetosistema)::text = 'pacientes'::text)
22. 0.000 0.000 ↓ 0.0

Index Scan using pk_tbpacientes_fontes on tbpacientes_fontes (cost=0.14..0.16 rows=1 width=36) (actual rows= loops=)

  • Index Cond: (tbpacientes.idpacientefonte = idpacientefonte)
23. 0.000 0.000 ↓ 0.0

Materialize (cost=91,373.22..91,973.32 rows=120,020 width=59) (actual rows= loops=)

24. 0.000 0.000 ↓ 0.0

Sort (cost=91,373.22..91,673.27 rows=120,020 width=59) (actual rows= loops=)

  • Sort Key: t1.idpaciente
25. 0.000 0.000 ↓ 0.0

Hash Join (cost=46,692.99..76,732.79 rows=120,020 width=59) (actual rows= loops=)

  • Hash Cond: (t6.idcategoriaservico = t7.idcategoriaservico)
26. 0.000 0.000 ↓ 0.0

Hash Join (cost=46,565.37..76,289.64 rows=120,020 width=45) (actual rows= loops=)

  • Hash Cond: (t5.iditemservico = t6.iditemservico)
27. 0.000 0.000 ↓ 0.0

Hash Join (cost=45,034.61..74,443.79 rows=120,020 width=45) (actual rows= loops=)

  • Hash Cond: (t1.idprofissional = t3.idprofissional)
28. 0.000 0.000 ↓ 0.0

Hash Join (cost=44,933.36..74,026.74 rows=120,020 width=16) (actual rows= loops=)

  • Hash Cond: (t5.idpacienteagendamento = t8.idpacienteagendamento)
29. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_agendamentos t5 (cost=0.00..18,870.91 rows=731,091 width=8) (actual rows= loops=)

30. 0.000 0.000 ↓ 0.0

Hash (cost=42,846.11..42,846.11 rows=120,020 width=16) (actual rows= loops=)

31. 0.000 0.000 ↓ 0.0

Hash Join (cost=28,025.08..42,846.11 rows=120,020 width=16) (actual rows= loops=)

  • Hash Cond: (t8.idordemservico = t4.idordemservico)
32. 0.000 0.000 ↓ 0.0

Seq Scan on tbordens_servico_itens t8 (cost=0.00..11,671.97 rows=519,697 width=8) (actual rows= loops=)

33. 0.000 0.000 ↓ 0.0

Hash (cost=27,268.54..27,268.54 rows=60,523 width=20) (actual rows= loops=)

34. 0.000 0.000 ↓ 0.0

Hash Join (cost=20,268.86..27,268.54 rows=60,523 width=20) (actual rows= loops=)

  • Hash Cond: (t4.idordemservico = t1.idordemservico)
35. 0.000 0.000 ↓ 0.0

Seq Scan on tbordens_servico t4 (cost=0.00..5,411.69 rows=262,069 width=4) (actual rows= loops=)

36. 0.000 0.000 ↓ 0.0

Hash (cost=19,512.32..19,512.32 rows=60,523 width=16) (actual rows= loops=)

37. 0.000 0.000 ↓ 0.0

Hash Join (cost=16,509.99..19,512.32 rows=60,523 width=16) (actual rows= loops=)

  • Hash Cond: (t2.idprontuario = t1.idpacienteprontuario)
38. 0.000 0.000 ↓ 0.0

Subquery Scan on t2 (cost=7,158.74..8,369.20 rows=60,523 width=4) (actual rows= loops=)

39. 0.000 0.000 ↓ 0.0

HashAggregate (cost=7,158.74..7,763.97 rows=60,523 width=8) (actual rows= loops=)

  • Group Key: tbpacientes_prontuarios.idpaciente
40. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_prontuarios (cost=0.00..6,462.38 rows=139,273 width=8) (actual rows= loops=)

  • Filter: (idempresagestora = ANY ('{37,38,39}'::integer[]))
41. 0.000 0.000 ↓ 0.0

Hash (cost=5,721.00..5,721.00 rows=197,700 width=20) (actual rows= loops=)

42. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_prontuarios t1 (cost=0.00..5,721.00 rows=197,700 width=20) (actual rows= loops=)

43. 0.000 0.000 ↓ 0.0

Hash (cost=78.89..78.89 rows=1,789 width=37) (actual rows= loops=)

44. 0.000 0.000 ↓ 0.0

Seq Scan on tbprofissionais t3 (cost=0.00..78.89 rows=1,789 width=37) (actual rows= loops=)

45. 0.000 0.000 ↓ 0.0

Hash (cost=1,077.56..1,077.56 rows=36,256 width=8) (actual rows= loops=)

46. 0.000 0.000 ↓ 0.0

Seq Scan on tbitens_servicos t6 (cost=0.00..1,077.56 rows=36,256 width=8) (actual rows= loops=)

47. 0.000 0.000 ↓ 0.0

Hash (cost=92.83..92.83 rows=2,783 width=22) (actual rows= loops=)

48. 0.000 0.000 ↓ 0.0

Seq Scan on tbcategorias_servicos t7 (cost=0.00..92.83 rows=2,783 width=22) (actual rows= loops=)

49. 0.000 0.000 ↓ 0.0

Materialize (cost=91,373.22..91,973.32 rows=120,020 width=59) (actual rows= loops=)

50. 0.000 0.000 ↓ 0.0

Sort (cost=91,373.22..91,673.27 rows=120,020 width=59) (actual rows= loops=)

  • Sort Key: t1_1.idpaciente
51. 0.000 0.000 ↓ 0.0

Hash Join (cost=46,692.99..76,732.79 rows=120,020 width=59) (actual rows= loops=)

  • Hash Cond: (t6_1.idcategoriaservico = t7_1.idcategoriaservico)
52. 0.000 0.000 ↓ 0.0

Hash Join (cost=46,565.37..76,289.64 rows=120,020 width=45) (actual rows= loops=)

  • Hash Cond: (t5_1.iditemservico = t6_1.iditemservico)
53. 0.000 0.000 ↓ 0.0

Hash Join (cost=45,034.61..74,443.79 rows=120,020 width=45) (actual rows= loops=)

  • Hash Cond: (t1_1.idprofissional = t3_1.idprofissional)
54. 0.000 0.000 ↓ 0.0

Hash Join (cost=44,933.36..74,026.74 rows=120,020 width=16) (actual rows= loops=)

  • Hash Cond: (t5_1.idpacienteagendamento = t8_1.idpacienteagendamento)
55. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_agendamentos t5_1 (cost=0.00..18,870.91 rows=731,091 width=8) (actual rows= loops=)

56. 0.000 0.000 ↓ 0.0

Hash (cost=42,846.11..42,846.11 rows=120,020 width=16) (actual rows= loops=)

57. 0.000 0.000 ↓ 0.0

Hash Join (cost=28,025.08..42,846.11 rows=120,020 width=16) (actual rows= loops=)

  • Hash Cond: (t8_1.idordemservico = t4_1.idordemservico)
58. 0.000 0.000 ↓ 0.0

Seq Scan on tbordens_servico_itens t8_1 (cost=0.00..11,671.97 rows=519,697 width=8) (actual rows= loops=)

59. 0.000 0.000 ↓ 0.0

Hash (cost=27,268.54..27,268.54 rows=60,523 width=20) (actual rows= loops=)

60. 0.000 0.000 ↓ 0.0

Hash Join (cost=20,268.86..27,268.54 rows=60,523 width=20) (actual rows= loops=)

  • Hash Cond: (t4_1.idordemservico = t1_1.idordemservico)
61. 0.000 0.000 ↓ 0.0

Seq Scan on tbordens_servico t4_1 (cost=0.00..5,411.69 rows=262,069 width=4) (actual rows= loops=)

62. 0.000 0.000 ↓ 0.0

Hash (cost=19,512.32..19,512.32 rows=60,523 width=16) (actual rows= loops=)

63. 0.000 0.000 ↓ 0.0

Hash Join (cost=16,509.99..19,512.32 rows=60,523 width=16) (actual rows= loops=)

  • Hash Cond: (t2_1.idprontuario = t1_1.idpacienteprontuario)
64. 0.000 0.000 ↓ 0.0

Subquery Scan on t2_1 (cost=7,158.74..8,369.20 rows=60,523 width=4) (actual rows= loops=)

65. 0.000 0.000 ↓ 0.0

HashAggregate (cost=7,158.74..7,763.97 rows=60,523 width=8) (actual rows= loops=)

  • Group Key: tbpacientes_prontuarios_1.idpaciente
66. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_prontuarios tbpacientes_prontuarios_1 (cost=0.00..6,462.38 rows=139,273 width=8) (actual rows= loops=)

  • Filter: (idempresagestora = ANY ('{37,38,39}'::integer[]))
67. 0.000 0.000 ↓ 0.0

Hash (cost=5,721.00..5,721.00 rows=197,700 width=20) (actual rows= loops=)

68. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_prontuarios t1_1 (cost=0.00..5,721.00 rows=197,700 width=20) (actual rows= loops=)

69. 0.000 0.000 ↓ 0.0

Hash (cost=78.89..78.89 rows=1,789 width=37) (actual rows= loops=)

70. 0.000 0.000 ↓ 0.0

Seq Scan on tbprofissionais t3_1 (cost=0.00..78.89 rows=1,789 width=37) (actual rows= loops=)

71. 0.000 0.000 ↓ 0.0

Hash (cost=1,077.56..1,077.56 rows=36,256 width=8) (actual rows= loops=)

72. 0.000 0.000 ↓ 0.0

Seq Scan on tbitens_servicos t6_1 (cost=0.00..1,077.56 rows=36,256 width=8) (actual rows= loops=)

73. 0.000 0.000 ↓ 0.0

Hash (cost=92.83..92.83 rows=2,783 width=22) (actual rows= loops=)

74. 0.000 0.000 ↓ 0.0

Seq Scan on tbcategorias_servicos t7_1 (cost=0.00..92.83 rows=2,783 width=22) (actual rows= loops=)

75. 0.000 0.000 ↓ 0.0

Sort (cost=13,176.30..13,327.61 rows=60,523 width=12) (actual rows= loops=)

  • Sort Key: td_prontuarios_total.idpaciente
76. 0.000 0.000 ↓ 0.0

Subquery Scan on td_prontuarios_total (cost=7,158.74..8,369.20 rows=60,523 width=12) (actual rows= loops=)

77. 0.000 0.000 ↓ 0.0

HashAggregate (cost=7,158.74..7,763.97 rows=60,523 width=12) (actual rows= loops=)

  • Group Key: tbpacientes_prontuarios_2.idpaciente
78. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_prontuarios tbpacientes_prontuarios_2 (cost=0.00..6,462.38 rows=139,273 width=8) (actual rows= loops=)

  • Filter: (idempresagestora = ANY ('{37,38,39}'::integer[]))
79. 0.000 0.000 ↓ 0.0

Materialize (cost=23,585.34..23,667.74 rows=2,523 width=12) (actual rows= loops=)

80. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=23,585.34..23,636.20 rows=2,523 width=16) (actual rows= loops=)

  • Group Key: tbpacientes_agendamentos.idpaciente, tbpacientes_agendamentos.dataagendamento
81. 0.000 0.000 ↓ 0.0

Sort (cost=23,585.34..23,591.75 rows=2,563 width=12) (actual rows= loops=)

  • Sort Key: tbpacientes_agendamentos.idpaciente, tbpacientes_agendamentos.dataagendamento
82. 0.000 0.000 ↓ 0.0

Seq Scan on tbpacientes_agendamentos (cost=0.00..23,440.23 rows=2,563 width=12) (actual rows= loops=)

  • Filter: ((COALESCE(cancelado, '0'::bit(1)) = '1'::bit(1)) AND (idempresagestora = ANY ('{37,38,39}'::integer[])))