explain.depesz.com

PostgreSQL's explain analyze made readable

Result: HVOB

Settings
# exclusive inclusive rows x rows loops node
1. 0.371 19.514 ↑ 1.0 1 1

GroupAggregate (cost=250.81..294.21 rows=1 width=44) (actual time=19.514..19.514 rows=1 loops=1)

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

CTE subtopic_breakdown

3. 1.422 16.734 ↑ 40.0 5 1

HashAggregate (cost=216.26..218.26 rows=200 width=24) (actual time=16.722..16.734 rows=5 loops=1)

  • Group Key: q.topic_id, q.subtopic_id
4. 4.486 15.312 ↓ 2.0 1,000 1

Hash Join (cost=102.71..211.22 rows=504 width=16) (actual time=11.586..15.312 rows=1,000 loops=1)

  • Hash Cond: (q.question_id = q2.question_id)
5. 1.918 1.918 ↑ 1.0 4,000 1

Seq Scan on questions q (cost=0.00..98.00 rows=4,000 width=12) (actual time=0.017..1.918 rows=4,000 loops=1)

6. 0.971 8.908 ↓ 2.0 1,000 1

Hash (cost=96.41..96.41 rows=504 width=8) (actual time=8.908..8.908 rows=1,000 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 36kB
7. 2.474 7.937 ↓ 2.0 1,000 1

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

  • Group Key: q2.question_id
8. 2.657 5.463 ↓ 2.0 1,000 1

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

  • Merge Cond: (q2.question_id = aq.question_id)
9. 1.736 1.736 ↑ 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.066..1.736 rows=2,000 loops=1)

  • Index Cond: (question_set_id = 2)
  • Heap Fetches: 0
10. 1.070 1.070 ↑ 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.055..1.070 rows=1,000 loops=1)

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

Initplan (forGroupAggregate)

12. 0.008 0.008 ↑ 1.0 1 1

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

13. 0.015 17.734 ↑ 1.0 5 1

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

14. 0.012 0.108 ↑ 1.0 1 1

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

15. 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.056..0.062 rows=1 loops=1)

  • Index Cond: ((user_id = 1) AND (question_set_id = 2))
16. 0.034 0.034 ↑ 1.0 1 1

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

  • Filter: (question_set_id = 2)
  • Rows Removed by Filter: 1
17. 0.021 17.611 ↑ 1.0 5 1

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

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

Initplan (forSort)

19. 0.012 0.012 ↑ 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.010..0.012 rows=1 loops=1)

20. 0.281 17.578 ↑ 1.0 5 1

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

  • Group Key: ts.topic_id
21. 0.021 17.297 ↑ 1.0 5 1

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

  • Sort Key: ts.topic_id
  • Sort Method: quicksort Memory: 18kB
22. 0.048 17.276 ↑ 1.0 5 1

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

  • Hash Cond: (subtopic_breakdown.topic_id = ts.topic_id)
23. 0.017 17.168 ↑ 40.0 5 1

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

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

Initplan (forSort)

25. 0.015 0.015 ↑ 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.014..0.015 rows=1 loops=1)

26. 0.241 17.136 ↑ 40.0 5 1

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

  • Group Key: sts.subtopic_id, subtopic_breakdown.topic_id, subtopic_breakdown.subtopic_id
27. 0.034 16.895 ↑ 40.0 5 1

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

  • Hash Cond: (subtopic_breakdown.subtopic_id = sts.subtopic_id)
28. 16.756 16.756 ↑ 40.0 5 1

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

29. 0.056 0.105 ↑ 1.0 20 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 5kB
30. 0.049 0.049 ↑ 1.0 20 1

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

31. 0.033 0.060 ↑ 1.0 5 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 5kB
32. 0.027 0.027 ↑ 1.0 5 1

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

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

SubPlan (forGroupAggregate)

34. 0.105 1.386 ↑ 1.0 1 1

Aggregate (cost=39.05..39.06 rows=1 width=8) (actual time=1.386..1.386 rows=1 loops=1)

35. 1.281 1.281 ↑ 1.0 20 1

Seq Scan on user_question_set_association centile_rank_table (cost=0.00..39.00 rows=20 width=4) (actual time=1.243..1.281 rows=20 loops=1)

  • Filter: ((score IS NOT NULL) AND (question_set_id = s.question_set_id))
  • Rows Removed by Filter: 1980
36. 0.015 0.015 ↓ 0.0 0 1

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

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