From: Gunnlaugur Þór Briem <gunnlaugur@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
Date: Tue, 20 Sep 2011 02:15:30 -0700 (PDT)
Message-ID: <12971543.2235.1316510130842.JavaMail.geo-discussion-forums@yqcd38> (raw)
In-Reply-To: <25440.1316404770@sss.pgh.pa.us>
References: <bd6669a0-5da6-410c-b3a2-4a1c01777003@glegroupsg2000goo.googlegroups.com>
<25440.1316404770@sss.pgh.pa.us>
On Monday, September 19, 2011 3:59:30 AM UTC, Tom Lane wrote:
> Works for me in 8.4.8. Do you have constraint_exclusion set to ON?
I did try with constraint_exclusion set to on, though the docs suggest partition should be enough ("examine constraints only for ... UNION ALL subqueries")
Here's a minimal test case (which I should have supplied in the original post, sorry), tried just now in 8.4.8:
CREATE OR REPLACE VIEW v_heavy_view
AS SELECT (random()*1e5)::integer col
FROM generate_series(1, 1e6::integer);
CREATE OR REPLACE VIEW v_test_constraint_exclusion AS
SELECT col FROM v_heavy_view WHERE col < 3
UNION ALL SELECT col FROM v_heavy_view WHERE col >= 3;
EXPLAIN SELECT * FROM v_test_constraint_exclusion WHERE col=2;
QUERY PLAN
--------------------------------------------------------------------------
Result (cost=0.00..70.04 rows=4 width=4)
-> Append (cost=0.00..70.04 rows=4 width=4)
-> Subquery Scan v_heavy_view (cost=0.00..35.00 rows=2 width=4)
Filter: ((v_heavy_view.col < 3) AND (v_heavy_view.col = 2))
-> Function Scan on generate_series (cost=0.00..20.00 rows=1000 width=0)
-> Subquery Scan v_heavy_view (cost=0.00..35.00 rows=2 width=4)
Filter: ((v_heavy_view.col >= 3) AND (v_heavy_view.col = 2))
-> Function Scan on generate_series (cost=0.00..20.00 rows=1000 width=0)
I want the planner to notice that (v_heavy_view.col >= 3) AND (v_heavy_view.col = 2) can never be satisfied, and skip that subquery.
Regards,
- Gulli
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: gunnlaugur@gmail.com
Subject: Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
In-Reply-To: <12971543.2235.1316510130842.JavaMail.geo-discussion-forums@yqcd38>
* 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