From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: Canonicalization of WHERE clauses considered harmful |
Date: | 2003-12-10 22:04:39 |
Message-ID: | 20031210220439.GA19976@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Dec 10, 2003 at 16:54:54 -0500,
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> In other words, we'd like the optimizer to transform
> (a AND b) OR (a AND c)
> to
> a AND (b OR c)
>
> Currently, this is accomplished by the roundabout method of converting
> the WHERE clause to CNF (AND-of-ORs) and then simplifying duplicate
> sub-clauses within an OR:
> (a AND b) OR (a AND c)
> expands by repeated application of the distributive law to
> (a OR a) AND (a OR c) AND (b OR a) AND (b OR c)
> and then qual_cleanup notices that (a OR a) is redundant, leaving
> a AND (a OR c) AND (b OR a) AND (b OR c)
> So we manage to pull out "a" all right, but we've left the query cluttered
> with additional, redundant clauses --- there is no logic that will notice
> that this could be simplified to
> a AND (b OR c)
> The extra clauses make for useless work during planning and during
> execution; they also screw up selectivity estimates (since the selectivity
> estimator doesn't realize they are redundant). This is bad.
>
> Comments?
Shouldn't it be possible to simplify
a AND (a OR c) AND (b OR a) AND (b OR c)
to
a AND (b or c)
using
a AND (a OR x) == a
?
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-12-10 22:14:22 | Re: Canonicalization of WHERE clauses considered harmful |
Previous Message | Tom Lane | 2003-12-10 22:01:48 | Re: Strange permission problem regarding pg_settings |