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?.
CREATE TABLE
CREATE INDEX
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
INSERT 0 33400
ANALYZE
min | max |
---|---|
2006-02-01 | 2007-11-30 |
SELECT 1
city_id | logdate | peaktemp | unitsales |
---|---|---|---|
53 | 2006-02-01 | 17 | 434 |
89 | 2006-02-02 | 17 | 981 |
91 | 2006-02-03 | 22 | 752 |
41 | 2006-02-04 | 6 | 603 |
62 | 2006-02-05 | 23 | 523 |
86 | 2006-02-06 | 12 | 10 |
71 | 2006-02-07 | 1 | 43 |
73 | 2006-02-08 | 5 | 230 |
38 | 2006-02-09 | 7 | 689 |
76 | 2006-02-10 | 1 | 698 |
SELECT 10
QUERY PLAN |
---|
Sort (cost=483.62..483.87 rows=101 width=12) |
Sort Key: (count(*)) DESC |
-> HashAggregate (cost=479.25..480.26 rows=101 width=12) |
Group Key: measurement.city_id |
-> Append (cost=0.00..462.98 rows=3254 width=4) |
-> Seq Scan on measurement_y2006m02 measurement_1 (cost=0.00..36.00 rows=301 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m03 measurement_2 (cost=0.00..40.00 rows=281 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m04 measurement_3 (cost=0.00..39.00 rows=300 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m05 measurement_4 (cost=0.00..40.00 rows=269 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m06 measurement_5 (cost=0.00..39.00 rows=325 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m07 measurement_6 (cost=0.00..40.00 rows=326 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m08 measurement_7 (cost=0.00..40.00 rows=276 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m09 measurement_8 (cost=0.00..39.00 rows=289 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m10 measurement_9 (cost=0.00..40.00 rows=290 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m11 measurement_10 (cost=0.00..39.00 rows=282 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Seq Scan on measurement_y2006m12 measurement_11 (cost=0.00..40.00 rows=305 width=4) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone)) |
-> Bitmap Heap Scan on measurement_y2007m01 measurement_12 (cost=5.03..14.71 rows=10 width=4) |
Recheck Cond: ((logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone) AND (peaktemp >= 5) AND (peaktemp <= 10)) |
-> Bitmap Index Scan on measurement_y2007m01_logdate_peaktemp_idx (cost=0.00..5.03 rows=10 width=0) |
Index Cond: ((logdate >= '2006-01-01'::date) AND (logdate <= '2007-01-01 00:00:00'::timestamp without time zone) AND (peaktemp >= 5) AND (peaktemp <= 10)) |
Planning: |
Buffers: shared hit=47 |
EXPLAIN
QUERY PLAN |
---|
Sort (cost=932.86..933.11 rows=101 width=12) (actual time=5.877..5.886 rows=101 loops=1) |
Sort Key: (count(*)) DESC |
Sort Method: quicksort Memory: 30kB |
Buffers: shared hit=199 |
-> HashAggregate (cost=928.49..929.50 rows=101 width=12) (actual time=5.831..5.847 rows=101 loops=1) |
Group Key: measurement.city_id |
Batches: 1 Memory Usage: 32kB |
Buffers: shared hit=196 |
-> Append (cost=0.00..896.25 rows=6449 width=4) (actual time=0.012..4.677 rows=6449 loops=1) |
Buffers: shared hit=196 |
-> Seq Scan on measurement_y2006m02 measurement_1 (cost=0.00..36.00 rows=301 width=4) (actual time=0.011..0.172 rows=301 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1099 |
Buffers: shared hit=8 |
-> Seq Scan on measurement_y2006m03 measurement_2 (cost=0.00..40.00 rows=281 width=4) (actual time=0.011..0.202 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1269 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m04 measurement_3 (cost=0.00..39.00 rows=300 width=4) (actual time=0.011..0.182 rows=300 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1200 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m05 measurement_4 (cost=0.00..40.00 rows=269 width=4) (actual time=0.009..0.179 rows=269 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1281 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m06 measurement_5 (cost=0.00..39.00 rows=325 width=4) (actual time=0.009..0.197 rows=325 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1175 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m07 measurement_6 (cost=0.00..40.00 rows=326 width=4) (actual time=0.010..0.200 rows=326 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1224 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m08 measurement_7 (cost=0.00..40.00 rows=276 width=4) (actual time=0.011..0.183 rows=276 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1274 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m09 measurement_8 (cost=0.00..39.00 rows=289 width=4) (actual time=0.009..0.179 rows=289 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1211 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m10 measurement_9 (cost=0.00..40.00 rows=290 width=4) (actual time=0.009..0.184 rows=290 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1260 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m11 measurement_10 (cost=0.00..39.00 rows=282 width=4) (actual time=0.010..0.180 rows=282 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1218 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m12 measurement_11 (cost=0.00..40.00 rows=305 width=4) (actual time=0.009..0.186 rows=305 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1245 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m01 measurement_12 (cost=0.00..40.00 rows=301 width=4) (actual time=0.009..0.184 rows=301 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1249 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m02 measurement_13 (cost=0.00..36.00 rows=292 width=4) (actual time=0.009..0.183 rows=292 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1108 |
Buffers: shared hit=8 |
-> Seq Scan on measurement_y2007m03 measurement_14 (cost=0.00..40.00 rows=286 width=4) (actual time=0.011..0.185 rows=286 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1264 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m04 measurement_15 (cost=0.00..39.00 rows=281 width=4) (actual time=0.009..0.178 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1219 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m05 measurement_16 (cost=0.00..40.00 rows=292 width=4) (actual time=0.009..0.182 rows=292 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1258 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m06 measurement_17 (cost=0.00..39.00 rows=288 width=4) (actual time=0.009..0.194 rows=288 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1212 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m07 measurement_18 (cost=0.00..40.00 rows=304 width=4) (actual time=0.010..0.184 rows=304 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1246 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m08 measurement_19 (cost=0.00..40.00 rows=303 width=4) (actual time=0.009..0.178 rows=303 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1247 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m09 measurement_20 (cost=0.00..39.00 rows=287 width=4) (actual time=0.009..0.172 rows=287 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1213 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m10 measurement_21 (cost=0.00..40.00 rows=290 width=4) (actual time=0.010..0.213 rows=290 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1260 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m11 measurement_22 (cost=0.00..39.00 rows=281 width=4) (actual time=0.011..0.173 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10) AND (logdate >= '2006-01-01'::date) AND (logdate <= '2009-01-01 00:00:00'::timestamp without time zone)) |
Rows Removed by Filter: 1219 |
Buffers: shared hit=9 |
Planning: |
Buffers: shared hit=60 |
Planning Time: 1.085 ms |
Execution Time: 5.981 ms |
EXPLAIN
QUERY PLAN |
---|
Sort (cost=765.86..766.11 rows=101 width=12) (actual time=5.237..5.246 rows=101 loops=1) |
Sort Key: (count(*)) DESC |
Sort Method: quicksort Memory: 30kB |
Buffers: shared hit=196 |
-> HashAggregate (cost=761.49..762.50 rows=101 width=12) (actual time=5.205..5.220 rows=101 loops=1) |
Group Key: measurement.city_id |
Batches: 1 Memory Usage: 32kB |
Buffers: shared hit=196 |
-> Append (cost=0.00..729.25 rows=6449 width=4) (actual time=0.013..4.060 rows=6449 loops=1) |
Buffers: shared hit=196 |
-> Seq Scan on measurement_y2006m02 measurement_1 (cost=0.00..29.00 rows=301 width=4) (actual time=0.013..0.160 rows=301 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1099 |
Buffers: shared hit=8 |
-> Seq Scan on measurement_y2006m03 measurement_2 (cost=0.00..32.25 rows=281 width=4) (actual time=0.008..0.156 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1269 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m04 measurement_3 (cost=0.00..31.50 rows=300 width=4) (actual time=0.007..0.151 rows=300 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1200 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m05 measurement_4 (cost=0.00..32.25 rows=269 width=4) (actual time=0.008..0.157 rows=269 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1281 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m06 measurement_5 (cost=0.00..31.50 rows=325 width=4) (actual time=0.008..0.156 rows=325 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1175 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m07 measurement_6 (cost=0.00..32.25 rows=326 width=4) (actual time=0.009..0.161 rows=326 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1224 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m08 measurement_7 (cost=0.00..32.25 rows=276 width=4) (actual time=0.008..0.156 rows=276 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1274 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m09 measurement_8 (cost=0.00..31.50 rows=289 width=4) (actual time=0.008..0.153 rows=289 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1211 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m10 measurement_9 (cost=0.00..32.25 rows=290 width=4) (actual time=0.022..0.171 rows=290 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1260 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m11 measurement_10 (cost=0.00..31.50 rows=282 width=4) (actual time=0.008..0.151 rows=282 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1218 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2006m12 measurement_11 (cost=0.00..32.25 rows=305 width=4) (actual time=0.008..0.158 rows=305 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1245 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m01 measurement_12 (cost=0.00..32.25 rows=301 width=4) (actual time=0.008..0.157 rows=301 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1249 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m02 measurement_13 (cost=0.00..29.00 rows=292 width=4) (actual time=0.007..0.162 rows=292 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1108 |
Buffers: shared hit=8 |
-> Seq Scan on measurement_y2007m03 measurement_14 (cost=0.00..32.25 rows=286 width=4) (actual time=0.008..0.157 rows=286 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1264 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m04 measurement_15 (cost=0.00..31.50 rows=281 width=4) (actual time=0.007..0.151 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1219 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m05 measurement_16 (cost=0.00..32.25 rows=292 width=4) (actual time=0.007..0.154 rows=292 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1258 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m06 measurement_17 (cost=0.00..31.50 rows=288 width=4) (actual time=0.007..0.153 rows=288 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1212 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m07 measurement_18 (cost=0.00..32.25 rows=304 width=4) (actual time=0.008..0.158 rows=304 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1246 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m08 measurement_19 (cost=0.00..32.25 rows=303 width=4) (actual time=0.008..0.157 rows=303 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1247 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m09 measurement_20 (cost=0.00..31.50 rows=287 width=4) (actual time=0.007..0.150 rows=287 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1213 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m10 measurement_21 (cost=0.00..32.25 rows=290 width=4) (actual time=0.009..0.171 rows=290 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1260 |
Buffers: shared hit=9 |
-> Seq Scan on measurement_y2007m11 measurement_22 (cost=0.00..31.50 rows=281 width=4) (actual time=0.008..0.170 rows=281 loops=1) |
Filter: ((peaktemp >= 5) AND (peaktemp <= 10)) |
Rows Removed by Filter: 1219 |
Buffers: shared hit=9 |
Planning Time: 0.625 ms |
Execution Time: 5.308 ms |
EXPLAIN