By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
4 rows affected
4 rows affected
10 rows affected
q_id | q_title | ss_s_id | ss_q_id | score | ts |
---|---|---|---|---|---|
1 | Quiz 1 | 40204123 | 1 | 80 | 2021-01-12 15:37:11 |
2 | Quiz 2 | 40204123 | 2 | 75 | 2021-01-12 15:38:06 |
3 | Quiz 3 | 40204123 | 3 | 30 | 2021-01-13 22:13:13 |
q_id | q_title |
---|---|
1 | Quiz 1 |
2 | Quiz 2 |
3 | Quiz 3 |
4 | Quiz 4 |
s_id | s_name |
---|---|
40204123 | Student2_name |
q_id | q_title | s_id | s_name |
---|---|---|---|
1 | Quiz 1 | 40204123 | Student2_name |
2 | Quiz 2 | 40204123 | Student2_name |
3 | Quiz 3 | 40204123 | Student2_name |
4 | Quiz 4 | 40204123 | Student2_name |
q_id | q_title | s_id | s_name |
---|---|---|---|
1 | Quiz 1 | 12345678 | Student1_name |
2 | Quiz 2 | 12345678 | Student1_name |
3 | Quiz 3 | 12345678 | Student1_name |
4 | Quiz 4 | 12345678 | Student1_name |
1 | Quiz 1 | 40204123 | Student2_name |
2 | Quiz 2 | 40204123 | Student2_name |
3 | Quiz 3 | 40204123 | Student2_name |
4 | Quiz 4 | 40204123 | Student2_name |
1 | Quiz 1 | 40213894 | Student3_name |
2 | Quiz 2 | 40213894 | Student3_name |
3 | Quiz 3 | 40213894 | Student3_name |
4 | Quiz 4 | 40213894 | Student3_name |
1 | Quiz 1 | 98765432 | Student4_name |
2 | Quiz 2 | 98765432 | Student4_name |
3 | Quiz 3 | 98765432 | Student4_name |
4 | Quiz 4 | 98765432 | Student4_name |
ERROR: argument of WHERE must be type boolean, not type integer
LINE 9: WHERE s.s_id -- IN (40204123, 40213894) test with and withou...
^
QUERY PLAN |
---|
Hash Left Join (cost=14.64..46.31 rows=540 width=188) (actual time=0.077..0.083 rows=4 loops=1) |
Hash Cond: ((s.s_id = ss.ss_s_id) AND (q.q_id = ss.ss_q_id)) |
Buffers: shared hit=5 |
-> Nested Loop (cost=0.15..28.97 rows=540 width=184) (actual time=0.032..0.035 rows=4 loops=1) |
Buffers: shared hit=3 |
-> Index Scan using student_pk on student s (cost=0.15..8.17 rows=1 width=62) (actual time=0.020..0.021 rows=1 loops=1) |
Index Cond: (s_id = 40204123) |
Buffers: shared hit=2 |
-> Seq Scan on quiz q (cost=0.00..15.40 rows=540 width=122) (actual time=0.008..0.009 rows=4 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=14.37..14.37 rows=8 width=12) (actual time=0.027..0.027 rows=3 loops=1) |
Buckets: 1024 Batches: 1 Memory Usage: 9kB |
Buffers: shared hit=2 |
-> Bitmap Heap Scan on student_score ss (cost=4.21..14.37 rows=8 width=12) (actual time=0.017..0.019 rows=3 loops=1) |
Recheck Cond: (ss_s_id = 40204123) |
Heap Blocks: exact=1 |
Buffers: shared hit=2 |
-> Bitmap Index Scan on sp_pk (cost=0.00..4.21 rows=8 width=0) (actual time=0.006..0.007 rows=3 loops=1) |
Index Cond: (ss_s_id = 40204123) |
Buffers: shared hit=1 |
Planning Time: 0.254 ms |
Execution Time: 0.188 ms |
QUERY PLAN |
---|
Merge Left Join (cost=67.97..70.81 rows=540 width=188) (actual time=0.078..0.083 rows=4 loops=1) |
Merge Cond: (q.q_id = ss.ss_q_id) |
Join Filter: (ss.ss_s_id = s.s_id) |
Buffers: shared hit=5 |
-> Sort (cost=53.47..54.82 rows=540 width=184) (actual time=0.046..0.047 rows=4 loops=1) |
Sort Key: q.q_id |
Sort Method: quicksort Memory: 25kB |
Buffers: shared hit=3 |
-> Nested Loop (cost=0.15..28.97 rows=540 width=184) (actual time=0.025..0.028 rows=4 loops=1) |
Buffers: shared hit=3 |
-> Index Scan using student_pk on student s (cost=0.15..8.17 rows=1 width=62) (actual time=0.016..0.017 rows=1 loops=1) |
Index Cond: (s_id = 40204123) |
Buffers: shared hit=2 |
-> Seq Scan on quiz q (cost=0.00..15.40 rows=540 width=122) (actual time=0.006..0.007 rows=4 loops=1) |
Buffers: shared hit=1 |
-> Sort (cost=14.49..14.51 rows=8 width=12) (actual time=0.028..0.029 rows=3 loops=1) |
Sort Key: ss.ss_q_id |
Sort Method: quicksort Memory: 25kB |
Buffers: shared hit=2 |
-> Bitmap Heap Scan on student_score ss (cost=4.21..14.37 rows=8 width=12) (actual time=0.013..0.014 rows=3 loops=1) |
Recheck Cond: (ss_s_id = 40204123) |
Heap Blocks: exact=1 |
Buffers: shared hit=2 |
-> Bitmap Index Scan on sp_pk (cost=0.00..4.21 rows=8 width=0) (actual time=0.004..0.004 rows=3 loops=1) |
Index Cond: (ss_s_id = 40204123) |
Buffers: shared hit=1 |
Planning Time: 0.231 ms |
Execution Time: 0.133 ms |