I have a postgresql measurement
table which is partitioned based on logdate
column by month. Suppose I have city_id
integer column and want to select latest row with city_id = 125
.
When I run explain select * from measurement where city_id = 125 limit 1;
I get
Limit (cost=0.00..3.39 rows=1 width=12)
-> Append (cost=0.00..308.25 rows=91 width=12)
-> Seq Scan on measurement (cost=0.00..0.00 rows=1 width=12)
Filter: (city_id = 125)
-> Seq Scan on measurement_y2006m01 (cost=0.00..34.25 rows=10 width=12)
Filter: (city_id = 125)
-> Seq Scan on measurement_y2006m02 (cost=0.00..34.25 rows=10 width=12)
Filter: (city_id = 125)
-> Seq Scan on measurement_y2006m03 (cost=0.00..34.25 rows=10 width=12)
Filter: (city_id = 125)
What is the default order in which those Seq Scan
actions are performed on inherited tables? And can I explicitly set it so that the latest tables are scanned first as I am expecting to select recently added rows more often?