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?.
version |
---|
PostgreSQL 12.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), 64-bit |
4 rows affected
6 rows affected
18 rows affected
42 rows affected
cname | combo | cid | ln | prob |
---|---|---|---|---|
Dublin | 1 | 101 | C++ | 0.61 |
Dublin | 1 | 101 | Java | 0.61 |
Dublin | 1 | 101 | C | 0.61 |
Dublin | 5 | 101 | Python | 0.51 |
Dublin | 5 | 101 | C | 0.51 |
Dublin | 5 | 101 | Java | 0.51 |
Dublin | 9 | 101 | Python | 0.41 |
Dublin | 9 | 101 | C++ | 0.41 |
Dublin | 9 | 101 | C | 0.41 |
Dublin | 13 | 101 | Java | 0.25 |
Dublin | 13 | 101 | C | 0.25 |
Dublin | 13 | 101 | C++ | 0.25 |
Dublin | 13 | 101 | Python | 0.25 |
Dublin | 14 | 101 | Nim | 0.05 |
Dublin | 14 | 101 | Clojure | 0.05 |
Madrid | 4 | 104 | C | 0.64 |
Madrid | 4 | 104 | Java | 0.64 |
Madrid | 4 | 104 | C++ | 0.64 |
Madrid | 8 | 104 | Java | 0.54 |
Madrid | 8 | 104 | C | 0.54 |
Madrid | 8 | 104 | Python | 0.54 |
Madrid | 12 | 104 | C++ | 0.44 |
Madrid | 12 | 104 | Python | 0.44 |
Madrid | 12 | 104 | C | 0.44 |
Paris | 2 | 102 | Java | 0.62 |
Paris | 2 | 102 | C | 0.62 |
Paris | 2 | 102 | C++ | 0.62 |
Paris | 6 | 102 | Java | 0.52 |
Paris | 6 | 102 | C | 0.52 |
Paris | 6 | 102 | Python | 0.52 |
Paris | 10 | 102 | C | 0.42 |
Paris | 10 | 102 | C++ | 0.42 |
Paris | 10 | 102 | Python | 0.42 |
Rome | 3 | 103 | C++ | 0.63 |
Rome | 3 | 103 | Java | 0.63 |
Rome | 3 | 103 | C | 0.63 |
Rome | 7 | 103 | Java | 0.53 |
Rome | 7 | 103 | C | 0.53 |
Rome | 7 | 103 | Python | 0.53 |
Rome | 11 | 103 | Python | 0.43 |
Rome | 11 | 103 | C++ | 0.43 |
Rome | 11 | 103 | C | 0.43 |
City name | Languages | Probability |
---|---|---|
Dublin | C, C++, Java | 0.61 |
Dublin | C, C++, Java, Python | 0.25 |
Dublin | C, C++, Python | 0.41 |
Dublin | C, Java, Python | 0.51 |
Dublin | Clojure, Nim | 0.05 |
Madrid | C, C++, Java | 0.64 |
Madrid | C, C++, Python | 0.44 |
Madrid | C, Java, Python | 0.54 |
Paris | C, C++, Java | 0.62 |
Paris | C, C++, Python | 0.42 |
Paris | C, Java, Python | 0.52 |
Rome | C, C++, Java | 0.63 |
Rome | C, C++, Python | 0.43 |
Rome | C, Java, Python | 0.53 |
QUERY PLAN |
---|
Sort (cost=336.45..340.70 rows=1700 width=76) (actual time=0.216..0.218 rows=14 loops=1) |
Sort Key: c.city_name, (string_agg(l.lang_name, ', '::text ORDER BY c.city_name, cljc.c_l_combo_set, l.lang_name)) |
Sort Method: quicksort Memory: 26kB |
Buffers: shared hit=3 |
-> GroupAggregate (cost=202.74..245.24 rows=1700 width=76) (actual time=0.133..0.197 rows=14 loops=1) |
Group Key: c.city_name, cljc.c_l_combo_set, cljc.c_l_combo_jp |
Buffers: shared hit=3 |
-> Sort (cost=202.74..206.99 rows=1700 width=76) (actual time=0.114..0.119 rows=42 loops=1) |
Sort Key: c.city_name, cljc.c_l_combo_set, cljc.c_l_combo_jp |
Sort Method: quicksort Memory: 28kB |
Buffers: shared hit=3 |
-> Hash Join (cost=75.58..111.52 rows=1700 width=76) (actual time=0.056..0.083 rows=42 loops=1) |
Hash Cond: (cljc.c_id = c.city_id) |
Buffers: shared hit=3 |
-> Hash Join (cost=38.58..70.05 rows=1700 width=48) (actual time=0.039..0.055 rows=42 loops=1) |
Hash Cond: (cljc.l_id = l.lang_id) |
Buffers: shared hit=2 |
-> Seq Scan on city_lang_jp_combo cljc (cost=0.00..27.00 rows=1700 width=20) (actual time=0.005..0.009 rows=42 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=22.70..22.70 rows=1270 width=36) (actual time=0.014..0.014 rows=6 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on language l (cost=0.00..22.70 rows=1270 width=36) (actual time=0.006..0.007 rows=6 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=22.00..22.00 rows=1200 width=36) (actual time=0.013..0.014 rows=4 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on city c (cost=0.00..22.00 rows=1200 width=36) (actual time=0.009..0.010 rows=4 loops=1) |
Buffers: shared hit=1 |
Planning Time: 0.336 ms |
Execution Time: 0.257 ms |
city | sa | prob |
---|---|---|
Dublin | C, C++, Java | 0.61 |
Dublin | C, C++, Java, Python | 0.25 |
Dublin | C, C++, Python | 0.41 |
Dublin | C, Java, Python | 0.51 |
Dublin | Clojure, Nim | 0.05 |
Madrid | C, C++, Java | 0.64 |
Madrid | C, C++, Python | 0.44 |
Madrid | C, Java, Python | 0.54 |
Paris | C, C++, Java | 0.62 |
Paris | C, C++, Python | 0.42 |
Paris | C, Java, Python | 0.52 |
Rome | C, C++, Java | 0.63 |
Rome | C, C++, Python | 0.43 |
Rome | C, Java, Python | 0.53 |
QUERY PLAN |
---|
Unique (cost=3091.16..3105.61 rows=1445 width=104) (actual time=0.983..1.000 rows=14 loops=1) |
Buffers: shared hit=7 |
-> Sort (cost=3091.16..3094.77 rows=1445 width=104) (actual time=0.983..0.990 rows=42 loops=1) |
Sort Key: ty.cn, (string_agg(ty.lang2, ', '::text ORDER BY ty.cn, ty.lang1, ty.lang2)), ty.prob |
Sort Method: quicksort Memory: 28kB |
Buffers: shared hit=7 |
-> GroupAggregate (cost=2816.63..3015.32 rows=1445 width=104) (actual time=0.695..0.914 rows=42 loops=1) |
Group Key: ty.cn, ty.lang1, ty.prob |
Buffers: shared hit=7 |
-> Sort (cost=2816.63..2852.76 rows=14450 width=104) (actual time=0.664..0.678 rows=128 loops=1) |
Sort Key: ty.cn, ty.lang1, ty.prob |
Sort Method: quicksort Memory: 35kB |
Buffers: shared hit=7 |
-> Subquery Scan on ty (cost=1637.60..1818.23 rows=14450 width=104) (actual time=0.473..0.513 rows=128 loops=1) |
Buffers: shared hit=7 |
-> Sort (cost=1637.60..1673.73 rows=14450 width=128) (actual time=0.472..0.485 rows=128 loops=1) |
Sort Key: c1.c_l_combo_set, cl.c_id, cl.l_id, c2.l_id |
Sort Method: quicksort Memory: 41kB |
Buffers: shared hit=7 |
-> Hash Join (cost=306.64..639.19 rows=14450 width=128) (actual time=0.233..0.364 rows=128 loops=1) |
Hash Cond: (c2.l_id = l2.lang_id) |
Buffers: shared hit=7 |
-> Merge Join (cost=268.07..562.57 rows=14450 width=92) (actual time=0.198..0.289 rows=128 loops=1) |
Merge Cond: (c2.c_l_combo_set = c1.c_l_combo_set) |
Buffers: shared hit=6 |
-> Index Only Scan using c_l_combo_id_pk on city_lang_jp_combo c2 (cost=0.15..73.65 rows=1700 width=8) (actual time=0.021..0.054 rows=42 loops=1) |
Heap Fetches: 42 |
Buffers: shared hit=2 |
-> Sort (cost=267.91..272.16 rows=1700 width=88) (actual time=0.173..0.186 rows=127 loops=1) |
Sort Key: c1.c_l_combo_set |
Sort Method: quicksort Memory: 28kB |
Buffers: shared hit=4 |
-> Hash Join (cost=131.82..176.70 rows=1700 width=88) (actual time=0.108..0.152 rows=42 loops=1) |
Hash Cond: (c1.l_id = l1.lang_id) |
Buffers: shared hit=4 |
-> Hash Join (cost=93.25..133.65 rows=1700 width=56) (actual time=0.075..0.107 rows=42 loops=1) |
Hash Cond: (c1.c_id = c.city_id) |
Buffers: shared hit=3 |
-> Hash Join (cost=56.25..92.17 rows=1700 width=28) (actual time=0.046..0.067 rows=42 loops=1) |
Hash Cond: ((c1.c_id = cl.c_id) AND (c1.l_id = cl.l_id)) |
Buffers: shared hit=2 |
-> Seq Scan on city_lang_jp_combo c1 (cost=0.00..27.00 rows=1700 width=20) (actual time=0.005..0.010 rows=42 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=28.50..28.50 rows=1850 width=8) (actual time=0.021..0.022 rows=18 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on city_language cl (cost=0.00..28.50 rows=1850 width=8) (actual time=0.005..0.009 rows=18 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=22.00..22.00 rows=1200 width=36) (actual time=0.013..0.013 rows=4 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on city c (cost=0.00..22.00 rows=1200 width=36) (actual time=0.006..0.007 rows=4 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=22.70..22.70 rows=1270 width=36) (actual time=0.021..0.021 rows=6 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on language l1 (cost=0.00..22.70 rows=1270 width=36) (actual time=0.006..0.008 rows=6 loops=1) |
Buffers: shared hit=1 |
-> Hash (cost=22.70..22.70 rows=1270 width=36) (actual time=0.019..0.019 rows=6 loops=1) |
Buckets: 2048 Batches: 1 Memory Usage: 17kB |
Buffers: shared hit=1 |
-> Seq Scan on language l2 (cost=0.00..22.70 rows=1270 width=36) (actual time=0.009..0.011 rows=6 loops=1) |
Buffers: shared hit=1 |
Planning Time: 2.466 ms |
Execution Time: 1.168 ms |