Hi: I find we can't prune partitions in the planner if the qual is a stable function.
CREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR VALUES FROM ('2006-02-01') TO ('2006-03-01'); CREATE TABLE measurement_y2006m03 PARTITION OF measurement FOR VALUES FROM ('2006-03-01') TO ('2006-04-01'); postgres=# explain (costs off) select * from measurement postgres-# where logdate = to_date('2006-03-02', 'yyyy-mm-dd'); QUERY PLAN ----------------------------------------------------------------------------- Append Subplans Removed: 1 <-- Here -> Seq Scan on measurement_y2006m03 measurement_1 Filter: (logdate = to_date('2006-03-02'::text, 'yyyy-mm-dd'::text)) (4 rows) IMO, we should do it. Why not? The attached is used to show the things in my mind. Btw, why the to_date function is declared as stable rather than immutable since it always delivers the same result for the same inputs. -- Best Regards Andy Fan
v1-0001-Allow-planner-prune-partitionn-with-stable-Expr.patch
Description: Binary data