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

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 47f99a4) | patch
Allow planner to use Merge Append to efficiently implement UNION
2024年3月25日 01:31:14 +0000 (14:31 +1300)
2024年3月25日 01:31:14 +0000 (14:31 +1300)
commit 66c0185a3d14bbbf51d0fc9d267093ffec735231
Allow planner to use Merge Append to efficiently implement UNION

Until now, UNION queries have often been suboptimal as the planner has
only ever considered using an Append node and making the results unique
by either using a Hash Aggregate, or by Sorting the entire Append result
and running it through the Unique operator. Both of these methods
always require reading all rows from the union subqueries.

Here we adjust the union planner so that it can request that each subquery
produce results in target list order so that these can be Merge Appended
together and made unique with a Unique node. This can improve performance
significantly as the union child can make use of the likes of btree
indexes and/or Merge Joins to provide the top-level UNION with presorted
input. This is especially good if the top-level UNION contains a LIMIT
node that limits the output rows to a small subset of the unioned rows as
cheap startup plans can be used.

Author: David Rowley
Reviewed-by: Richard Guo, Andy Fan
Discussion: https://postgr.es/m/CAApHDvpb_63XQodmxKUF8vb9M7CxyUyT4sWvEgqeQU-GB7QFoQ@mail.gmail.com
15 files changed:
contrib/postgres_fdw/expected/postgres_fdw.out diff | blob | blame | history
contrib/postgres_fdw/sql/postgres_fdw.sql diff | blob | blame | history
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/optimizer/prep/prepunion.c diff | blob | blame | history
src/backend/parser/analyze.c diff | blob | blame | history
src/include/nodes/pathnodes.h diff | blob | blame | history
src/include/optimizer/paths.h diff | blob | blame | history
src/include/optimizer/prep.h diff | blob | blame | history
src/test/regress/expected/collate.icu.utf8.out diff | blob | blame | history
src/test/regress/expected/incremental_sort.out diff | blob | blame | history
src/test/regress/expected/union.out diff | blob | blame | history
src/test/regress/sql/collate.icu.utf8.sql diff | blob | blame | history
src/test/regress/sql/union.sql diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

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