explain.depesz.com

PostgreSQL's explain analyze made readable

Result: R5lT

Settings
# exclusive inclusive rows x rows loops node
1. 0.365 17.866 ↑ 1.0 1 1

GroupAggregate (cost=228.23..234.12 rows=1 width=44) (actual time=17.865..17.866 rows=1 loops=1)

  • Group Key: s.user_id, s.question_set_id, qs.question_set_id
2.          

CTE subtopic_breakdown

3. 1.570 16.354 ↑ 40.0 5 1

HashAggregate (cost=193.68..195.68 rows=200 width=24) (actual time=16.342..16.354 rows=5 loops=1)

  • Group Key: q.topic_id, q.subtopic_id
4. 3.004 14.784 ↓ 4.0 1,000 1

Merge Join (cost=0.85..191.16 rows=252 width=16) (actual time=0.185..14.784 rows=1,000 loops=1)

  • Merge Cond: (q.question_id = q2.question_id)
5. 3.631 3.631 ↑ 1.0 2,000 1

Index Scan using ix_questions_question_set_id_question_id_answer_index on questions q (cost=0.28..85.97 rows=2,000 width=12) (actual time=0.047..3.631 rows=2,000 loops=1)

  • Index Cond: (question_set_id = 2)
6. 2.406 8.149 ↓ 2.0 1,000 1

GroupAggregate (cost=0.57..91.37 rows=504 width=8) (actual time=0.130..8.149 rows=1,000 loops=1)

  • Group Key: q2.question_id
7. 2.771 5.743 ↓ 2.0 1,000 1

Merge Join (cost=0.57..81.29 rows=504 width=12) (actual time=0.103..5.743 rows=1,000 loops=1)

  • Merge Cond: (q2.question_id = aq.question_id)
8. 1.800 1.800 ↑ 1.0 2,000 1

Index Only Scan using ix_questions_question_set_id_question_id_answer_index on questions q2 (cost=0.28..44.28 rows=2,000 width=8) (actual time=0.045..1.800 rows=2,000 loops=1)

  • Index Cond: (question_set_id = 2)
  • Heap Fetches: 0
9. 1.172 1.172 ↑ 1.0 1,000 1

Index Only Scan using ix_answered_questions_user_id_q_set_id_q_id_answer_index on subscriptions_questions_association aq (cost=0.29..24.47 rows=1,009 width=8) (actual time=0.046..1.172 rows=1,000 loops=1)

  • Index Cond: ((user_id = 1) AND (question_set_id = 2))
  • Heap Fetches: 0
10.          

Initplan (forGroupAggregate)

11. 0.013 0.013 ↑ 1.0 1 1

Seq Scan on question_counts_mv qc (cost=0.00..1.01 rows=1 width=1,444) (actual time=0.012..0.013 rows=1 loops=1)

12. 0.016 17.313 ↑ 1.0 5 1

Nested Loop (cost=31.54..34.71 rows=5 width=106) (actual time=17.297..17.313 rows=5 loops=1)

13. 0.010 0.105 ↑ 1.0 1 1

Nested Loop (cost=0.28..3.33 rows=1 width=74) (actual time=0.097..0.105 rows=1 loops=1)

14. 0.062 0.062 ↑ 1.0 1 1

Index Scan using pk_user_question_set_association on user_question_set_association s (cost=0.28..2.30 rows=1 width=24) (actual time=0.058..0.062 rows=1 loops=1)

  • Index Cond: ((user_id = 1) AND (question_set_id = 2))
15. 0.033 0.033 ↑ 1.0 1 1

Seq Scan on question_sets qs (cost=0.00..1.02 rows=1 width=50) (actual time=0.031..0.033 rows=1 loops=1)

  • Filter: (question_set_id = 2)
  • Rows Removed by Filter: 1
16. 0.024 17.192 ↑ 1.0 5 1

Sort (cost=31.26..31.28 rows=5 width=44) (actual time=17.190..17.192 rows=5 loops=1)

  • Sort Key: ts.name
  • Sort Method: quicksort Memory: 18kB
17.          

Initplan (forSort)

18. 0.010 0.010 ↑ 1.0 1 1

Seq Scan on question_counts_mv qc_1 (cost=0.00..1.01 rows=1 width=1,444) (actual time=0.008..0.010 rows=1 loops=1)

19. 0.279 17.158 ↑ 1.0 5 1

GroupAggregate (cost=29.92..30.20 rows=5 width=44) (actual time=16.979..17.158 rows=5 loops=1)

  • Group Key: ts.topic_id
20. 0.021 16.879 ↑ 1.0 5 1

Sort (cost=29.92..29.93 rows=5 width=44) (actual time=16.877..16.879 rows=5 loops=1)

  • Sort Key: ts.topic_id
  • Sort Method: quicksort Memory: 18kB
21. 0.045 16.858 ↑ 1.0 5 1

Hash Right Join (cost=26.83..29.86 rows=5 width=44) (actual time=16.831..16.858 rows=5 loops=1)

  • Hash Cond: (subtopic_breakdown.topic_id = ts.topic_id)
22. 0.010 16.764 ↑ 40.0 5 1

Sort (cost=25.64..26.14 rows=200 width=55) (actual time=16.762..16.764 rows=5 loops=1)

  • Sort Key: sts.name
  • Sort Method: quicksort Memory: 18kB
23.          

Initplan (forSort)

24. 0.014 0.014 ↑ 1.0 1 1

Seq Scan on question_counts_mv qc_2 (cost=0.00..1.01 rows=1 width=1,444) (actual time=0.013..0.014 rows=1 loops=1)

25. 0.241 16.740 ↑ 40.0 5 1

HashAggregate (cost=8.49..16.99 rows=200 width=55) (actual time=16.633..16.740 rows=5 loops=1)

  • Group Key: sts.subtopic_id, subtopic_breakdown.topic_id, subtopic_breakdown.subtopic_id
26. 0.038 16.499 ↑ 40.0 5 1

Hash Left Join (cost=1.45..5.99 rows=200 width=43) (actual time=16.469..16.499 rows=5 loops=1)

  • Hash Cond: (subtopic_breakdown.subtopic_id = sts.subtopic_id)
27. 16.372 16.372 ↑ 40.0 5 1

CTE Scan on subtopic_breakdown (cost=0.00..4.00 rows=200 width=24) (actual time=16.350..16.372 rows=5 loops=1)

28. 0.038 0.089 ↑ 1.0 20 1

Hash (cost=1.20..1.20 rows=20 width=19) (actual time=0.089..0.089 rows=20 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 5kB
29. 0.051 0.051 ↑ 1.0 20 1

Seq Scan on subtopics sts (cost=0.00..1.20 rows=20 width=19) (actual time=0.031..0.051 rows=20 loops=1)

30. 0.021 0.049 ↑ 1.0 5 1

Hash (cost=1.12..1.12 rows=5 width=12) (actual time=0.049..0.049 rows=5 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 5kB
31. 0.028 0.028 ↑ 1.0 5 1

Seq Scan on topics ts (cost=0.00..1.12 rows=5 width=12) (actual time=0.021..0.028 rows=5 loops=1)

  • Filter: (question_set_id = 2)
  • Rows Removed by Filter: 5
32.          

SubPlan (forGroupAggregate)

33. 0.090 0.159 ↑ 1.0 1 1

Aggregate (cost=1.54..1.55 rows=1 width=8) (actual time=0.158..0.159 rows=1 loops=1)

34. 0.069 0.069 ↑ 1.0 20 1

Index Only Scan using ix_user_question_set_association_centile_rank on user_question_set_association centile_rank_table (cost=0.14..1.49 rows=20 width=4) (actual time=0.056..0.069 rows=20 loops=1)

  • Index Cond: (question_set_id = s.question_set_id)
  • Heap Fetches: 0
35. 0.016 0.016 ↓ 0.0 0 1

Seq Scan on tests active_test (cost=0.00..1.02 rows=1 width=1) (actual time=0.016..0.016 rows=0 loops=1)

  • Filter: ((user_id = s.user_id) AND (question_set_id = s.question_set_id))