pgsql: Defer remove_useless_groupby_columns() work until query_planner( - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Defer remove_useless_groupby_columns() work until query_planner(
Date
Msg-id E1tLXuZ-002H2r-U9@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Defer remove_useless_groupby_columns() work until query_planner()

Traditionally, remove_useless_groupby_columns() was called during
grouping_planner() directly after the call to preprocess_groupclause().
While in many ways, it made sense to populate the field and remove the
functionally dependent columns from processed_groupClause at the same
time, it's just that doing so had the disadvantage that
remove_useless_groupby_columns() was being called before the RelOptInfos
were populated for the relations mentioned in the query.  Not having
RelOptInfos available meant we needed to manually query the catalog tables
to get the required details about the primary key constraint for the
table.

Here we move the remove_useless_groupby_columns() call to
query_planner() and put it directly after the RelOptInfos are populated.
This is fine to do as processed_groupClause still isn't final at this
point as it can still be modified inside standard_qp_callback() by
make_pathkeys_for_sortclauses_extended().

This commit is just a refactor and simply moves
remove_useless_groupby_columns() into initsplan.c.  A planned follow-up
commit will adjust that function so it uses RelOptInfo instead of doing
catalog lookups and also teach it how to use unique indexes as proofs to
expand the cases where we can remove functionally dependent columns from
the GROUP BY.

Reviewed-by: Andrei Lepikhov, jian he
Discussion: https://postgr.es/m/CAApHDvqLezKwoEBBQd0dp4Y9MDkFBDbny0f3SzEeqOFoU7Z5+A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/430a5952deb3bfbfe1e2537315d44427b7c41fb1

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c | 167 ++++++++++++++++++++++++++++++++-
src/backend/optimizer/plan/planmain.c  |   3 +
src/backend/optimizer/plan/planner.c   | 164 --------------------------------
src/include/optimizer/planmain.h       |   1 +
4 files changed, 170 insertions(+), 165 deletions(-)


pgsql-committers by date:

Previous
From: Masahiko Sawada
Date:
Subject: pgsql: Add UUID version 7 generation function.
Next
From: Michael Paquier
Date:
Subject: pgsql: Add some regression tests for missing DDL patterns