pgsql: Teach expr_is_nonnullable() to handle more expression types

Поиск
Список
Период
Сортировка
От Richard Guo
Тема pgsql: Teach expr_is_nonnullable() to handle more expression types
Дата
Msg-id E1vYKkr-002PHF-1A@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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 <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49UhPBjm+NRpxerjaeuFKyUZJ_AjM3NBcSYK2JgZ6VTEQ@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(-)


В списке pgsql-committers по дате отправления: