Transform OR clauses to ANY expression

Replace (expr op C1) OR (expr op C2) ... with expr op ANY(ARRAY[C1, C2, ...])
on the preliminary stage of optimization when we are still working with the
expression tree.

Here Cn is a n-th constant expression, 'expr' is non-constant expression, 'op'
is an operator which returns boolean result and has a commuter (for the case
of reverse order of constant and non-constant parts of the expression,
like 'Cn op expr').

Sometimes it can lead to not optimal plan.  This is why there is a
or_to_any_transform_limit GUC.  It specifies a threshold value of length of
arguments in an OR expression that triggers the OR-to-ANY transformation.
Generally, more groupable OR arguments mean that transformation will be more
likely to win than to lose.

Discussion: https://postgr.es/m/567ED6CA.2040504%40sigaev.ru
Author: Alena Rybakina <lena.riback...@yandex.ru>
Author: Andrey Lepikhov <a.lepik...@postgrespro.ru>
Reviewed-by: Peter Geoghegan <p...@bowt.ie>
Reviewed-by: Ranier Vilela <ranier...@gmail.com>
Reviewed-by: Alexander Korotkov <aekorot...@gmail.com>
Reviewed-by: Robert Haas <robertmh...@gmail.com>
Reviewed-by: Jian He <jian.universal...@gmail.com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/72bd38cc99a15da6f97373fae98027c908c398ea

Modified Files
--------------
doc/src/sgml/config.sgml                      |  57 ++++
src/backend/nodes/queryjumblefuncs.c          |  27 ++
src/backend/optimizer/prep/prepqual.c         | 399 +++++++++++++++++++++++++-
src/backend/utils/misc/guc_tables.c           |  12 +
src/backend/utils/misc/postgresql.conf.sample |   1 +
src/include/nodes/queryjumble.h               |   1 +
src/include/optimizer/optimizer.h             |   2 +
src/test/regress/expected/create_index.out    | 159 ++++++++++
src/test/regress/expected/join.out            |  50 ++++
src/test/regress/expected/partition_prune.out |  37 +--
src/test/regress/sql/create_index.sql         |  45 +++
src/test/regress/sql/join.sql                 |  11 +
src/test/regress/sql/partition_prune.sql      |   2 +
src/tools/pgindent/typedefs.list              |   2 +
14 files changed, 785 insertions(+), 20 deletions(-)

Reply via email to