Re: Canonicalization of WHERE clauses considered harmful - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: Canonicalization of WHERE clauses considered harmful
Date
Msg-id 20031210220439.GA19976@wolff.to
Whole thread Raw
In response to Canonicalization of WHERE clauses considered harmful  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Canonicalization of WHERE clauses considered harmful  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wed, Dec 10, 2003 at 16:54:54 -0500, Tom Lane <tgl@sss.pgh.pa.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
?


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Canonicalization of WHERE clauses considered harmful
Next
From: Tom Lane
Date:
Subject: Re: Canonicalization of WHERE clauses considered harmful