explain.depesz.com

PostgreSQL's explain analyze made readable

Result: m7bc : Optimization for: Optimization for: plan #zGcF; plan #Xfso

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 0.376 18.408 ↑ 1.0 1 1

GroupAggregate (cost=250.81..256.70 rows=1 width=44) (actual time=18.408..18.408 rows=1 loops=1)

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

CTE subtopic_breakdown

3. 1.434 16.760 ↑ 40.0 5 1

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

  • Group Key: q.topic_id, q.subtopic_id
4. 4.472 15.326 ↓ 2.0 1,000 1

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

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

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

6. 0.954 8.896 ↓ 2.0 1,000 1

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

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

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

  • Group Key: q2.question_id
8. 2.644 5.496 ↓ 2.0 1,000 1

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

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

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

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

Initplan (forGroupAggregate)

12. 0.009 0.009 ↑ 1.0 1 1

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

13. 0.013 17.718 ↑ 1.0 5 1

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

14. 0.011 0.108 ↑ 1.0 1 1

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

15. 0.064 0.064 ↑ 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.057..0.064 rows=1 loops=1)

  • Index Cond: ((user_id = 1) AND (question_set_id = 2))
16. 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
17. 0.022 17.597 ↑ 1.0 5 1

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

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

Initplan (forSort)

19. 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.009..0.010 rows=1 loops=1)

20. 0.280 17.565 ↑ 1.0 5 1

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

  • Group Key: ts.topic_id
21. 0.022 17.285 ↑ 1.0 5 1

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

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

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

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

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

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

Initplan (forSort)

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

26. 0.231 17.141 ↑ 40.0 5 1

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

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

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

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

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

29. 0.046 0.094 ↑ 1.0 20 1

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

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

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

31. 0.021 0.046 ↑ 1.0 5 1

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

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

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

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

SubPlan (forGroupAggregate)

34. 0.097 0.291 ↑ 1.0 1 1

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

35. 0.194 0.194 ↑ 1.0 20 1

Index Only Scan using jmfyjm on user_question_set_association centile_rank_table (cost=0.14..1.49 rows=20 width=4) (actual time=0.179..0.194 rows=20 loops=1)

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

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

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