Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions - Mailing list pgsql-performance

From Tom Lane
Subject Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
Date
Msg-id 25440.1316404770@sss.pgh.pa.us
Whole thread Raw
In response to Constraint exclusion on UNION ALL subqueries with WHERE conditions  (Gunnlaugur Þór Briem <gunnlaugur@gmail.com>)
Responses Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions  (Gunnlaugur Þór Briem <gunnlaugur@gmail.com>)
List pgsql-performance
=?ISO-8859-1?Q?Gunnlaugur_=DE=F3r_Briem?= <gunnlaugur@gmail.com> writes:
> I did this:

> CREATE VIEW unionview AS
>   SELECT col, otherstuff FROM (heavy subquery)
>   WHERE col BETWEEN 1 AND 3
>   UNION ALL
>   SELECT col, otherstuff FROM (another heavy subquery)
>   WHERE col BETWEEN 4 AND 6;

> hoping that the planner could use the WHERE conditions (like it would use check constraints on tables) to exclude one
ofthe subqueries, for a query like: 

> SELECT * FROM unionview WHERE col=2;

> But it doesn't. (In PostgreSQL 8.4.5, at least.)

Works for me in 8.4.8.  Do you have constraint_exclusion set to ON?

            regards, tom lane

pgsql-performance by date:

Previous
From: Jeff Janes
Date:
Subject: Re: How to make hash indexes fast
Next
From: Vitalii Tymchyshyn
Date:
Subject: Re: PostgreSQL-related topics of theses and seminary works sought (Was: Hash index use presently(?) discouraged...)