Teach expr_is_nonnullable() to handle more expression types
Currently, the function expr_is_nonnullable() checks only Const and
Var expressions to determine if an expression is non-nullable. This
patch extends the detection logic to handle more expression types.
This can enable several downstream optimizations, such as reducing
NullTest quals to constant truth values (e.g., "COALESCE(var, 1) IS
NULL" becomes FALSE) and converting "COUNT(expr)" to the more
efficient "COUNT(*)" when the expression is proven non-nullable.
This breaks a test case in test_predtest.sql, since we now simplify
"ARRAY[] IS NULL" to constant FALSE, preventing it from weakly
refuting a strict ScalarArrayOpExpr ("x = any(ARRAY[])"). To ensure
the refutation logic is still exercised as intended, wrap the array
argument in opaque_array().
Author: Richard Guo <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Matheus Alcantara <[email protected]>
Discussion:
https://postgr.es/m/cambws49uhpbjm+nrpxerjaeufkyuzj_ajm3nbcsyk2jgz6v...@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c8d2f68cc800e02f858f8f59e3e9ba46ce43e880
Modified Files
--------------
src/backend/optimizer/util/clauses.c | 123 ++++++++++++++++++++-
.../test_predtest/expected/test_predtest.out | 2 +-
.../modules/test_predtest/sql/test_predtest.sql | 2 +-
src/test/regress/expected/predicate.out | 117 +++++++++++++++++++-
src/test/regress/sql/predicate.sql | 50 ++++++++-
5 files changed, 284 insertions(+), 10 deletions(-)