postgresql/src/include
David Rowley 3226f47282 Add enable_presorted_aggregate GUC
1349d279 added query planner support to allow more efficient execution of
aggregate functions which have an ORDER BY or a DISTINCT clause.  Prior to
that commit, the planner would only request that the lower planner produce
a plan with the order required for the GROUP BY clause and it would be
left up to nodeAgg.c to perform the final sort of records within each
group so that the aggregate transition functions were called in the
correct order.  Now that the planner requests the lower planner produce a
plan with the GROUP BY and the ORDER BY / DISTINCT aggregates in mind,
there is the possibility that the planner chooses a plan which could be
less efficient than what would have been produced before 1349d279.

While developing 1349d279, I had in mind that Incremental Sort would help
us in cases where an index exists only on the GROUP BY column(s).
Incremental Sort would just replace the implicit tuplesorts which are
being performed in nodeAgg.c.  However, because the planner has the
flexibility to instead choose a plan which just performs a full sort on
both the GROUP BY and ORDER BY / DISTINCT aggregate columns, there is
potential for the planner to make a bad choice.  The costing for
Incremental Sort is not perfect as it assumes an even distribution of rows
to sort within each sort group.

Here we add an escape hatch in the form of the enable_presorted_aggregate
GUC.  This will allow users to get the pre-PG16 behavior in cases where
they have no other means to convince the query planner to produce a plan
which only sorts on the GROUP BY column(s).

Discussion: https://postgr.es/m/CAApHDvr1Sm+g9hbv4REOVuvQKeDWXcKUAhmbK5K+dfun0s9CvA@mail.gmail.com
2022-12-20 22:28:58 +13:00
..
access Static assertions cleanup 2022-12-15 10:10:32 +01:00
backup Reduce basebackup_sink.h inclusion footprint 2022-10-12 09:42:20 +02:00
bootstrap Harmonize more lexer function parameter names. 2022-09-22 13:27:16 -07:00
catalog Add pg_dissect_walfile_name() 2022-12-20 13:36:27 +09:00
commands Add grantable MAINTAIN privilege and pg_maintain role. 2022-12-13 17:33:28 -08:00
common Remove hardcoded dependency to cryptohash type in the internals of SCRAM 2022-12-20 08:53:22 +09:00
datatype Fix overflow hazards in interval input and output conversions. 2022-04-02 16:12:29 -04:00
executor Rework query relation permission checking 2022-12-06 16:09:24 +01:00
fe_utils Revert 56-bit relfilenode change and follow-up commits. 2022-09-28 09:55:28 -04:00
foreign Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
jit Add central declarations for dlsym()ed symbols 2022-07-17 17:23:42 -07:00
lib Fix wording in comment 2022-11-17 13:17:19 +01:00
libpq Remove hardcoded dependency to cryptohash type in the internals of SCRAM 2022-12-20 08:53:22 +09:00
mb Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
nodes Doc: update pg_list.h header comments to include XidLists. 2022-12-17 10:31:25 -05:00
optimizer Add enable_presorted_aggregate GUC 2022-12-20 22:28:58 +13:00
parser Rework query relation permission checking 2022-12-06 16:09:24 +01:00
partitioning Move PartitioPruneInfo out of plan nodes into PlannedStmt 2022-12-01 12:56:21 +01:00
pch meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
port mingw: Define PGDLLEXPORT as __declspec (dllexport) as done for msvc 2022-09-30 10:50:05 -07:00
portability Fix obsolete comments in instr_time.h. 2022-08-09 11:50:03 +12:00
postmaster Provide options for postmaster to kill child processes with SIGABRT. 2022-11-21 11:59:29 -05:00
regex Consistently use named parameters in regex code. 2022-09-19 15:10:24 -07:00
replication Avoid unnecessary streaming of transactions during logical replication. 2022-12-08 06:05:09 +05:30
rewrite Rework query relation permission checking 2022-12-06 16:09:24 +01:00
snowball Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
statistics Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
storage Expose some information about backend subxact status. 2022-12-19 14:43:09 -05:00
tcop Speed up creation of command completion tags 2022-12-16 10:31:25 +13:00
tsearch Replace link to Hunspell with the current homepage 2022-11-21 23:25:48 +01:00
utils Fix comment that was missing a word. 2022-12-19 15:59:24 -05:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Static assertions cleanup 2022-12-15 10:10:32 +01:00
fmgr.h Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
funcapi.h Remove compatibility declarations for InitMaterializedSRF() 2022-10-18 10:44:02 +09:00
getopt_long.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
Makefile Move gramparse.h to src/backend/parser 2022-09-14 10:57:13 +07:00
meson.build meson: Add basic PGXS compatibility 2022-12-06 18:56:46 -08:00
miscadmin.h Remove AssertArg and AssertState 2022-10-28 09:19:06 +02:00
pg_config.h.in Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Remove our artificial PG_SOMAXCONN limit on listen queue length. 2022-08-23 10:15:06 -04:00
pg_getopt.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
pg_trace.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgstat.h Generate pg_stat_get*() functions for databases using macros 2022-12-07 09:11:48 +09:00
pgtar.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgtime.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
port.h pg_basebackup: Fix cross-platform tablespace relocation. 2022-10-21 08:21:55 -04:00
postgres.h Simplify our Assert infrastructure a little. 2022-10-10 15:16:56 -04:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
windowapi.h Update copyright for 2022 2022-01-07 19:04:57 -05:00