explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 2B7S

Settings
# exclusive inclusive rows x rows loops node
1. 0.008 101.727 ↑ 10.0 1 1

HashAggregate (cost=2,929.56..2,929.68 rows=10 width=82) (actual time=101.727..101.727 rows=1 loops=1)

  • Group Key: max(pessoa.codigo), array_to_string(array_agg(DISTINCT pessoa.nome), ', '::text), array_agg(DISTINCT pessoa.codigo), disciplina.codigo, disciplina.nome, min(horarioturmadiaitem.data), max(horarioturmadiaitem.data), 'PRESENCIAL'::text
2. 0.556 101.719 ↑ 10.0 1 1

GroupAggregate (cost=2,928.96..2,929.36 rows=10 width=82) (actual time=101.719..101.719 rows=1 loops=1)

  • Group Key: disciplina.codigo, disciplina.nome, matriculaperiodoturmadisciplina.modalidadedisciplina
3. 0.766 101.163 ↓ 14.8 148 1

Sort (cost=2,928.96..2,928.98 rows=10 width=82) (actual time=101.154..101.163 rows=148 loops=1)

  • Sort Key: disciplina.codigo, disciplina.nome, matriculaperiodoturmadisciplina.modalidadedisciplina
  • Sort Method: quicksort Memory: 45kB
4. 0.178 100.397 ↓ 14.8 148 1

Nested Loop (cost=79.99..2,928.79 rows=10 width=82) (actual time=75.045..100.397 rows=148 loops=1)

5. 0.440 99.331 ↓ 14.8 148 1

Nested Loop Left Join (cost=3.42..2,122.69 rows=10 width=65) (actual time=75.022..99.331 rows=148 loops=1)

  • Join Filter: ((((curso.periodicidade)::text = 'AN'::text) AND ((professortitulardisciplinaturma.ano)::text = (matriculaperiodo.ano)::text)) OR (((curso.periodicidade)::text = 'SE'::text) AND ((professortitulardisciplinaturma.ano)::text = (matriculaperiodo.ano)::text) AND ((professortitulardisciplinaturma.semestre)::text = (matriculaperiodo.semestre)::text)) OR ((curso.periodicidade)::text = 'IN'::text))
  • Rows Removed by Join Filter: 444
6. 3.455 98.151 ↓ 14.8 148 1

Nested Loop Left Join (cost=3.13..2,117.75 rows=10 width=69) (actual time=75.002..98.151 rows=148 loops=1)

  • Filter: (SubPlan 1)
  • Rows Removed by Filter: 1788
7. 7.638 61.784 ↓ 92.2 1,936 1

Nested Loop (cost=2.71..236.22 rows=21 width=67) (actual time=34.145..61.784 rows=1,936 loops=1)

  • Join Filter: ((((curso.periodicidade)::text = 'AN'::text) AND ((horarioturma.anovigente)::text = (matriculaperiodo.ano)::text)) OR (((curso.periodicidade)::text = 'SE'::text) AND ((horarioturma.anovigente)::text = (matriculaperiodo.ano)::text) AND ((horarioturma.semestrevigente)::text = (matriculaperiodo.semestre)::text)) OR ((curso.periodicidade)::text = 'IN'::text))
  • Rows Removed by Join Filter: 8051
8. 7.300 34.172 ↓ 50.4 9,987 1

Nested Loop (cost=2.42..170.07 rows=198 width=67) (actual time=0.078..34.172 rows=9,987 loops=1)

9. 3.462 6.898 ↓ 50.4 9,987 1

Nested Loop (cost=1.99..75.03 rows=198 width=67) (actual time=0.071..6.898 rows=9,987 loops=1)

10. 0.001 0.063 ↑ 1.0 1 1

Nested Loop (cost=1.57..33.71 rows=1 width=59) (actual time=0.054..0.063 rows=1 loops=1)

11. 0.002 0.054 ↑ 1.0 1 1

Nested Loop (cost=1.15..25.25 rows=1 width=54) (actual time=0.047..0.054 rows=1 loops=1)

12. 0.004 0.047 ↑ 1.0 1 1

Nested Loop (cost=1.00..25.08 rows=1 width=55) (actual time=0.042..0.047 rows=1 loops=1)

13. 0.004 0.026 ↑ 1.0 1 1

Nested Loop (cost=0.71..16.76 rows=1 width=60) (actual time=0.023..0.026 rows=1 loops=1)

14. 0.015 0.015 ↑ 1.0 1 1

Index Scan using historico_pkey on historico (cost=0.43..8.45 rows=1 width=21) (actual time=0.013..0.015 rows=1 loops=1)

  • Index Cond: (codigo = 2007739)
15. 0.007 0.007 ↑ 1.0 1 1

Index Scan using disciplina_pkey on disciplina (cost=0.28..8.30 rows=1 width=39) (actual time=0.006..0.007 rows=1 loops=1)

  • Index Cond: (codigo = historico.disciplina)
16. 0.017 0.017 ↑ 1.0 1 1

Index Scan using matricula_pkey on matricula (cost=0.29..8.31 rows=1 width=13) (actual time=0.016..0.017 rows=1 loops=1)

  • Index Cond: ((matricula)::text = (historico.matricula)::text)
17. 0.005 0.005 ↑ 1.0 1 1

Index Scan using curso_pkey on curso (cost=0.14..0.17 rows=1 width=7) (actual time=0.004..0.005 rows=1 loops=1)

  • Index Cond: (codigo = matricula.curso)
18. 0.008 0.008 ↑ 1.0 1 1

Index Scan using matriculaperiodo_pkey on matriculaperiodo (cost=0.42..8.44 rows=1 width=13) (actual time=0.007..0.008 rows=1 loops=1)

  • Index Cond: (codigo = historico.matriculaperiodo)
19. 3.373 3.373 ↓ 12.7 9,987 1

Index Scan using idx_horturdiaitem_disciplina on horarioturmadiaitem (cost=0.43..33.47 rows=786 width=16) (actual time=0.016..3.373 rows=9,987 loops=1)

  • Index Cond: (disciplina = disciplina.codigo)
20. 19.974 19.974 ↑ 1.0 1 9,987

Index Scan using horarioturmadia_pkey on horarioturmadia (cost=0.42..0.47 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=9,987)

  • Index Cond: (codigo = horarioturmadiaitem.horarioturmadia)
21. 19.974 19.974 ↑ 1.0 1 9,987

Index Scan using horarioturma_pkey on horarioturma (cost=0.29..0.31 rows=1 width=13) (actual time=0.001..0.002 rows=1 loops=9,987)

  • Index Cond: (codigo = horarioturmadia.horarioturma)
22. 5.808 5.808 ↑ 1.0 1 1,936

Index Scan using matriculaperiodoturmadisciplina_pkey on matriculaperiodoturmadisciplina (cost=0.43..8.45 rows=1 width=26) (actual time=0.002..0.003 rows=1 loops=1,936)

  • Index Cond: (codigo = historico.matriculaperiodoturmadisciplina)
23.          

SubPlan (for Nested Loop Left Join)

24. 2.072 27.104 ↑ 20.7 3 1,936

Append (cost=0.00..162.12 rows=62 width=4) (actual time=0.001..0.014 rows=3 loops=1,936)

25. 0.000 0.000 ↑ 1.0 1 1,936

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

26. 0.000 0.000 ↑ 1.0 1 1,936

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

27. 0.000 0.000 ↑ 1.0 1 1,936

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

28. 1.788 25.032 ↓ 0.0 0 1,788

Nested Loop (cost=4.79..161.47 rows=59 width=4) (actual time=0.014..0.014 rows=0 loops=1,788)

29. 5.364 23.244 ↓ 0.0 0 1,788

Nested Loop (cost=4.51..133.99 rows=59 width=4) (actual time=0.013..0.013 rows=0 loops=1,788)

30. 3.576 7.152 ↑ 1.0 3 1,788

HashAggregate (cost=0.07..0.10 rows=3 width=4) (actual time=0.003..0.004 rows=3 loops=1,788)

  • Group Key: (CASE WHEN ((matriculaperiodoturmadisciplina.turmateorica IS NULL) AND (matriculaperiodoturmadisciplina.turmapratica IS NULL) AND (matriculaperiodoturmadisciplina.turma IS NOT NULL)) THEN matriculaperiodoturmadisciplina.turma ELSE CASE WHEN (matriculaperiodo.turma IS NOT NULL) THEN matriculaperiodo.turma ELSE 0 END END)
31. 3.576 3.576 ↑ 1.0 3 1,788

Append (cost=0.00..0.06 rows=3 width=4) (actual time=0.000..0.002 rows=3 loops=1,788)

32. 0.000 0.000 ↑ 1.0 1 1,788

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

33. 0.000 0.000 ↑ 1.0 1 1,788

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

34. 0.000 0.000 ↑ 1.0 1 1,788

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

35. 5.364 10.728 ↓ 0.0 0 5,364

Bitmap Heap Scan on turmaagrupada ta (cost=4.44..44.43 rows=20 width=8) (actual time=0.002..0.002 rows=0 loops=5,364)

  • Recheck Cond: (turma = (CASE WHEN ((matriculaperiodoturmadisciplina.turmateorica IS NULL) AND (matriculaperiodoturmadisciplina.turmapratica IS NULL) AND (matriculaperiodoturmadisciplina.turma IS NOT NULL)) THEN matriculaperiodoturmadisciplina.turma ELSE CASE WHEN (matriculaperiodo.turma IS NOT NULL) THEN matriculaperiodo.turma ELSE 0 END END))
36. 5.364 5.364 ↓ 0.0 0 5,364

Bitmap Index Scan on idx_turmaagrupada_turma (cost=0.00..4.44 rows=20 width=0) (actual time=0.001..0.001 rows=0 loops=5,364)

  • Index Cond: (turma = (CASE WHEN ((matriculaperiodoturmadisciplina.turmateorica IS NULL) AND (matriculaperiodoturmadisciplina.turmapratica IS NULL) AND (matriculaperiodoturmadisciplina.turma IS NOT NULL)) THEN matriculaperiodoturmadisciplina.turma ELSE CASE WHEN (matriculaperiodo.turma IS NOT NULL) THEN matriculaperiodo.turma ELSE 0 END END))
37. 0.000 0.000 ↓ 0.0 0

Index Only Scan using turma_pkey on turma t (cost=0.29..0.46 rows=1 width=4) (never executed)

  • Index Cond: (codigo = ta.turmaorigem)
  • Heap Fetches: 0
38. 0.740 0.740 ↓ 4.0 4 148

Index Scan using idx_professortitulardisciplinaturma_tur_dis_ano_sem on professortitulardisciplinaturma (cost=0.29..0.47 rows=1 width=21) (actual time=0.002..0.005 rows=4 loops=148)

  • Index Cond: ((turma = horarioturma.turma) AND (disciplina = disciplina.codigo))
  • Filter: titular
39. 0.296 0.888 ↑ 1.0 1 148

Bitmap Heap Scan on pessoa (cost=76.57..80.60 rows=1 width=29) (actual time=0.006..0.006 rows=1 loops=148)

  • Recheck Cond: (((professortitulardisciplinaturma.professor = codigo) AND (codigo IS NOT NULL)) OR ((codigo = horarioturmadiaitem.professor) AND (codigo IS NOT NULL)))
  • Filter: (((professortitulardisciplinaturma.codigo IS NOT NULL) AND (professortitulardisciplinaturma.professor = codigo)) OR ((professortitulardisciplinaturma.codigo IS NULL) AND (codigo = horarioturmadiaitem.professor)))
  • Heap Blocks: exact=148
40. 0.148 0.592 ↓ 0.0 0 148

BitmapOr (cost=76.57..76.57 rows=2 width=0) (actual time=0.004..0.004 rows=0 loops=148)

41. 0.296 0.296 ↑ 1.0 1 148

Bitmap Index Scan on pessoa_pkey (cost=0.00..0.50 rows=1 width=0) (actual time=0.002..0.002 rows=1 loops=148)

  • Index Cond: ((professortitulardisciplinaturma.professor = codigo) AND (codigo IS NOT NULL))
42. 0.148 0.148 ↑ 1.0 1 148

Bitmap Index Scan on pessoa_pkey (cost=0.00..0.43 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=148)

  • Index Cond: ((codigo = horarioturmadiaitem.professor) AND (codigo IS NOT NULL))
Planning time : 28.061 ms
Execution time : 102.053 ms