Partition prune with stable Expr - Mailing list pgsql-hackers

From Andy Fan
Subject Partition prune with stable Expr
Date
Msg-id CAKU4AWrksHsgWtjAD7fFsMfbZWdFtnTUGD6kEM6TeVGOJJGbwQ@mail.gmail.com
Whole thread Raw
Responses Re: Partition prune with stable Expr  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
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
Attachment

pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: AppendStringInfoChar instead of appendStringInfoString
Next
From: David Rowley
Date:
Subject: Re: Partition prune with stable Expr