pgsql: Improve planner to drop constant-NULL inputs of AND/OR where it' - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve planner to drop constant-NULL inputs of AND/OR where it'
Date
Msg-id E1WfBaZ-0001ng-1s@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Improve planner to drop constant-NULL inputs of AND/OR where it's legal.

In general we can't discard constant-NULL inputs, since they could change
the result of the AND/OR to be NULL.  But at top level of WHERE, we do not
need to distinguish a NULL result from a FALSE result, so it's okay to
treat NULL as FALSE and then simplify AND/OR accordingly.

This is a very ancient oversight, but in 9.2 and later it can lead to
failure to optimize queries that previous releases did optimize, as a
result of more aggressive parameter substitution rules making it possible
to reduce more subexpressions to NULL constants.  This is the root cause of
bug #10171 from Arnold Scheffler.  We could alternatively have fixed that
by teaching orclauses.c to ignore constant-NULL OR arms, but it seems
better to get rid of them globally.

I resisted the temptation to back-patch this change into all active
branches, but it seems appropriate to back-patch as far as 9.2 so that
there will not be performance regressions of the kind shown in this bug.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/95811032d782049642a672e3db0a5382616ab084

Modified Files
--------------
src/backend/optimizer/prep/prepqual.c      |   79 +++++++++++++++++++++++-----
src/test/regress/expected/create_index.out |   11 ++++
src/test/regress/sql/create_index.sql      |    7 +++
3 files changed, 85 insertions(+), 12 deletions(-)


pgsql-committers by date:

Previous
From: Greg Stark
Date:
Subject: pgsql: Remove unnecessary cast causing a warning
Next
From: Tom Lane
Date:
Subject: pgsql: Improve planner to drop constant-NULL inputs of AND/OR where it'