pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-performance@postgresql.org
Subject: Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
Date: Sun, 18 Sep 2011 23:59:30 -0400
Message-ID: <25440.1316404770@sss.pgh.pa.us> (raw)
In-Reply-To: <bd6669a0-5da6-410c-b3a2-4a1c01777003@glegroupsg2000goo.googlegroups.com>
References: <bd6669a0-5da6-410c-b3a2-4a1c01777003@glegroupsg2000goo.googlegroups.com>

=?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 of the 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



view thread (5+ messages)  latest in thread

Message-ID: <25440.1316404770@sss.pgh.pa.us>
Permalink:  ../25440.1316404770@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25440.1316404770@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
  In-Reply-To: <25440.1316404770@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox