On Wed, Dec 10, 2003 at 16:54:54 -0500, Tom Lane <[EMAIL PROTECTED]> 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 ? ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster