pgsql: Make group_similar_or_args() reorder clause list as little as po

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make group_similar_or_args() reorder clause list as little as po
Date: 2025-03-28 21:37:55
Message-ID: E1tyHOl-001U4I-15@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make group_similar_or_args() reorder clause list as little as possible

Currently, group_similar_or_args() permutes original positions of clauses
independently on whether it manages to find any groups of similar clauses.
While we are not providing any strict warranties on saving the original order
of OR-clauses, it is preferred that the original order be modified as little
as possible.

This commit changes the reordering algorithm of group_similar_or_args() in
the following way. We reorder each group of similar clauses so that the
first item of the group stays in place, but all the other items are moved
after it. So, if there are no similar clauses, the order of clauses stays
the same. When there are some groups, only required reordering happens while
the rest of the clauses remain in their places.

Reported-by: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Discussion: https://postgr.es/m/3ac7c436-81e1-4191-9caf-b0dd70b51511%40gmail.com
Reviewed-by: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Reviewed-by: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Reviewed-by: Alena Rybakina <a(dot)rybakina(at)postgrespro(dot)ru>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/775a06d44c04e323158826ec256386e7211e154d

Modified Files
--------------
src/backend/optimizer/path/indxpath.c | 59 +++++++++++++++++++++++++++-
src/test/regress/expected/create_index.out | 49 ++++++++++++++++++-----
src/test/regress/expected/join.out | 52 ++++++++++++------------
src/test/regress/expected/partition_join.out | 12 +++---
src/test/regress/sql/create_index.sql | 11 ++++++
5 files changed, 141 insertions(+), 42 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2025-03-28 23:16:19 pgsql: Matview statistics depend on matview data.
Previous Message Nathan Bossart 2025-03-28 21:20:42 pgsql: Optimize popcount functions with ARM SVE intrinsics.