git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 7ab80ac) | patch
Explore alternative orderings of group-by pathkeys during optimization.
2024年1月21日 20:21:36 +0000 (22:21 +0200)
2024年1月21日 20:21:36 +0000 (22:21 +0200)
commit 0452b461bc405e6d35d8a14c02813c15e28ae516
Explore alternative orderings of group-by pathkeys during optimization.

When evaluating a query with a multi-column GROUP BY clause, we can minimize
sort operations or avoid them if we synchronize the order of GROUP BY clauses
with the ORDER BY sort clause or sort order, which comes from the underlying
query tree. Grouping does not imply any ordering, so we can compare
the keys in arbitrary order, and a Hash Agg leverages this. But for Group Agg,
we simply compared keys in the order specified in the query. This commit
explores alternative ordering of the keys, trying to find a cheaper one.

The ordering of group keys may interact with other parts of the query, some of
which may not be known while planning the grouping. For example, there may be
an explicit ORDER BY clause or some other ordering-dependent operation higher up
in the query, and using the same ordering may allow using either incremental
sort or even eliminating the sort entirely.

The patch always keeps the ordering specified in the query, assuming the user
might have additional insights.

This introduces a new GUC enable_group_by_reordering so that the optimization
may be disabled if needed.

Discussion: https://postgr.es/m/7c79e6a5-8597-74e8-0671-1c39d124c9d6%40sigaev.ru
Author: Andrei Lepikhov, Teodor Sigaev
Reviewed-by: Tomas Vondra, Claudio Freire, Gavin Flower, Dmitry Dolgov
Reviewed-by: Robert Haas, Pavel Borisov, David Rowley, Zhihong Yu
Reviewed-by: Tom Lane, Alexander Korotkov, Richard Guo, Alena Rybakina
src/backend/optimizer/path/equivclass.c diff | blob | blame | history
src/backend/optimizer/path/pathkeys.c diff | blob | blame | history
src/backend/optimizer/plan/planner.c diff | blob | blame | history
src/backend/utils/misc/guc_tables.c diff | blob | blame | history
src/backend/utils/misc/postgresql.conf.sample diff | blob | blame | history
src/include/nodes/pathnodes.h diff | blob | blame | history
src/include/optimizer/paths.h diff | blob | blame | history
src/test/regress/expected/aggregates.out diff | blob | blame | history
src/test/regress/expected/sysviews.out diff | blob | blame | history
src/test/regress/sql/aggregates.sql diff | blob | blame | history
src/tools/pgindent/typedefs.list diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /