pgsql: Transform OR clauses to ANY expression

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Transform OR clauses to ANY expression
Date: 2024-04-07 22:28:06
Message-ID: E1rtaze-0011lv-55@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)ribackina(at)yandex(dot)ru>
Author: Andrey Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>
Reviewed-by: Peter Geoghegan <pg(at)bowt(dot)ie>
Reviewed-by: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Reviewed-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Reviewed-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)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(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Melanie Plageman 2024-04-07 22:35:21 Re: pgsql: Transform OR clauses to ANY expression
Previous Message Daniel Gustafsson 2024-04-07 22:26:06 pgsql: Change debug printing to log filename