Transform queries like: ... WHERE EXISTS (SELECT 1 FROM inner_table WHERE inner_table.field = 2*outer_table.field AND maybe_something_else)... and ... WHERE NOT EXISTS (SELECT 1 FROM inner_table WHERE inner_table.field = 2*outer_table.field AND maybe_something_else)... into ... WHERE 2*outer_table.field IN (SELECT inner_table.field FROM inner_table WHERE 1 = 1 AND maybe_something_else).. ... WHERE NOT( 2*outer_table.field IS NOT NULL AND NOT 2*outer_table.field IN (SELECT inner_table.field FROM inner_table WHERE inner_table.field IS NOT NULL AND maybe_something_else)... To allow optimizations made for IN/ALL/ANY subqueries. Conversion is possible only if: 1)real NULL is not important (top element of WHERE/ON AND/OR list, i.e. NULL equal to FALSE) 2)the subquery has the only dependence which we bring out of it 3)the subquery is simple (has no aggregate function, GROUp BY, ORDER BY, LIMIT HAVING and so on) For NOT EXISTS conversion the subquery should be marked that its left part can't be NULL.
High Level Description modified. --- /tmp/wklog.245.old.13522 2012-01-03 11:30:19.000000000 +0000 +++ /tmp/wklog.245.new.13522 2012-01-03 11:30:19.000000000 +0000 @@ -13,9 +13,10 @@ ... WHERE 2*outer_table.field IN (SELECT inner_table.field FROM inner_table WHERE 1 = 1 AND maybe_something_else).. -... WHERE 2*outer_table.field IS NULL OR 2*outer_table.field IN (SELECT +... WHERE NOT( 2*outer_table.field IS NOT NULL AND NOT 2*outer_table.field IN +(SELECT inner_table.field FROM inner_table WHERE inner_table.field IS NOT NULL AND -maybe_something_else).. +maybe_something_else)... To allow optimizations made for IN/ALL/ANY subqueries.