Constraint exclusion not working - need different constraints? - Mailing list pgsql-general

From Doug Gorley
Subject Constraint exclusion not working - need different constraints?
Date
Msg-id 20150527142214.akz9k6wav40cwcoo@webmail.internethosting.com
Whole thread Raw
Responses Re: Constraint exclusion not working - need different constraints?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Good day,

I'm attempting to implement table partitioning with constraint exclusions,
but I'm not seeing the planner limit the plan to an appropriate set of
child tables.  I'm wondering if the functions in my constraints are making
the exclusion impossible.

My constraints look like this:

    ALTER TABLE response_data.queries_response_2015w23
      ADD CONSTRAINT queries_response_2015w23_timestamp_check
          CHECK (
             date_part('year'::text, "timestamp"::timestamp without time zone) = 2015::double precision AND
             date_part('week'::text, "timestamp"::timestamp without time zone) = 23::double precision
          );

And my query looks like this:

    explain select * from public.queries_response where age("timestamp"::timestamp) < '24 hours';
   
http://www.postgresql.org/docs/9.4/static/ddl-partitioning.html gives this caveat:

    "Constraint exclusion only works when the query's WHERE clause contains
    constants (or externally supplied parameters). For example, a comparison
    against a non-immutable function such as CURRENT_TIMESTAMP cannot be
    optimized, since the planner cannot know which partition the function
    value might fall into at run time."
   
Will I likely need to replace the date_part functions with actual dates to
make this work?

Thanks,
--
Doug Gorley | doug@gorley.ca


pgsql-general by date:

Previous
From: PT
Date:
Subject: Re: Fwd: Raster performance
Next
From: Steve Kehlet
Date:
Subject: 9.4.1 -> 9.4.2 problem: could not access status of transaction 1