postgresql/contrib
David Rowley 4a29eabd1d Remove pessimistic cost penalization from Incremental Sort
When incremental sorts were added in v13 a 1.5x pessimism factor was added
to the cost modal.  Seemingly this was done because the cost modal only
has an estimate of the total number of input rows and the number of
presorted groups.  It assumes that the input rows will be evenly
distributed throughout the presorted groups.  The 1.5x pessimism factor
was added to slightly reduce the likelihood of incremental sorts being
used in the hope to avoid performance regressions where an incremental
sort plan was picked and turned out slower due to a large skew in the
number of rows in the presorted groups.

An additional quirk with the path generation code meant that we could
consider both a sort and an incremental sort on paths with presorted keys.
This meant that with the pessimism factor, it was possible that we opted
to perform a sort rather than an incremental sort when the given path had
presorted keys.

Here we remove the 1.5x pessimism factor to allow incremental sorts to
have a fairer chance at being chosen against a full sort.

Previously we would generally create a sort path on the cheapest input
path (if that wasn't sorted already) and incremental sort paths on any
path which had presorted keys.  This meant that if the cheapest input path
wasn't completely sorted but happened to have presorted keys, we would
create a full sort path *and* an incremental sort path on that input path.
Here we change this logic so that if there are presorted keys, we only
create an incremental sort path, and create sort paths only when a full
sort is required.

Both the removal of the cost pessimism factor and the changes made to the
path generation make it more likely that incremental sorts will now be
chosen.  That, of course, as with teaching the planner any new tricks,
means an increased likelihood that the planner will perform an incremental
sort when it's not the best method.  Our standard escape hatch for these
cases is an enable_* GUC.  enable_incremental_sort already exists for
this.

This came out of a report by Pavel Luzanov where he mentioned that the
master branch was choosing to perform a Seq Scan -> Sort -> Group
Aggregate for his query with an ORDER BY aggregate function.  The v15 plan
for his query performed an Index Scan -> Group Aggregate, of course, the
aggregate performed the final sort internally in nodeAgg.c for the
aggregate's ORDER BY.  The ideal plan would have been to use the index,
which provided partially sorted input then use an incremental sort to
provide the aggregate with the sorted input.  This was not being chosen
due to the pessimism in the incremental sort cost modal, so here we remove
that and rationalize the path generation so that sort and incremental sort
plans don't have to needlessly compete.  We assume that it's senseless
to ever use a full sort on a given input path where an incremental sort
can be performed.

Reported-by: Pavel Luzanov
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/9f61ddbf-2989-1536-b31e-6459370a6baa%40postgrespro.ru
2022-12-16 15:22:23 +13:00
..
adminpack Allow DateTimeParseError to handle bad-timezone error messages. 2022-12-09 13:30:47 -05:00
amcheck Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
auth_delay Clean up some inconsistencies with GUC declarations 2022-10-31 12:44:48 +09:00
auto_explain meson: Add windows resource files 2022-10-05 09:56:05 -07:00
basebackup_to_shell basebackup_to_shell: Add some const qualifiers for consistency 2022-12-13 10:39:44 +01:00
basic_archive meson: Add 'running' test setup, as a replacement for installcheck 2022-12-07 12:13:35 -08:00
bloom If wait_for_catchup fails under has_wal_read_bug, skip balance of test. 2022-11-12 11:19:50 -08:00
bool_plperl meson: Add windows resource files 2022-10-05 09:56:05 -07:00
btree_gin Produce more-optimal plans for bitmap scans on boolean columns. 2022-11-08 10:36:04 -05:00
btree_gist Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
citext meson: Add windows resource files 2022-10-05 09:56:05 -07:00
cube Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
dblink Refactor aclcheck functions 2022-11-13 09:02:41 +01:00
dict_int meson: Add windows resource files 2022-10-05 09:56:05 -07:00
dict_xsyn meson: Add windows resource files 2022-10-05 09:56:05 -07:00
earthdistance meson: Add windows resource files 2022-10-05 09:56:05 -07:00
file_fdw Fix final warnings produced by -Wshadow=compatible-local 2022-10-07 13:13:27 +13:00
fuzzystrmatch Remove AssertArg and AssertState 2022-10-28 09:19:06 +02:00
hstore Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
hstore_plperl meson: Add windows resource files 2022-10-05 09:56:05 -07:00
hstore_plpython meson: Add windows resource files 2022-10-05 09:56:05 -07:00
intagg meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
intarray Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
isn meson: Add windows resource files 2022-10-05 09:56:05 -07:00
jsonb_plperl meson: Add windows resource files 2022-10-05 09:56:05 -07:00
jsonb_plpython meson: Add windows resource files 2022-10-05 09:56:05 -07:00
lo meson: Add windows resource files 2022-10-05 09:56:05 -07:00
ltree Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
ltree_plpython meson: Add windows resource files 2022-10-05 09:56:05 -07:00
oid2name meson: Add windows resource files 2022-10-05 09:56:05 -07:00
old_snapshot meson: Add windows resource files 2022-10-05 09:56:05 -07:00
pageinspect Mark pageinspect's disk-accessing functions as parallel restricted. 2022-11-21 15:37:10 -05:00
passwordcheck tests: Rename conflicting role names 2022-10-05 10:43:13 -07:00
pg_buffercache pg_buffercache: Add pg_buffercache_summary() 2022-10-13 09:55:46 -07:00
pg_freespacemap meson: Add 'running' test setup, as a replacement for installcheck 2022-12-07 12:13:35 -08:00
pg_prewarm Clean up some inconsistencies with GUC declarations 2022-10-31 12:44:48 +09:00
pg_stat_statements meson: Add 'running' test setup, as a replacement for installcheck 2022-12-07 12:13:35 -08:00
pg_surgery Refactor ownercheck functions 2022-11-13 08:12:37 +01:00
pg_trgm Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
pg_visibility meson: Add windows resource files 2022-10-05 09:56:05 -07:00
pg_walinspect meson: Add 'running' test setup, as a replacement for installcheck 2022-12-07 12:13:35 -08:00
pgcrypto Remove redundant memset call following palloc0 2022-10-13 23:18:00 +02:00
pgrowlocks Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
pgstattuple meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
postgres_fdw Remove pessimistic cost penalization from Incremental Sort 2022-12-16 15:22:23 +13:00
seg Use fabsf() instead of Abs() or fabs() where appropriate 2022-10-08 13:43:26 +02:00
sepgsql Rework query relation permission checking 2022-12-06 16:09:24 +01:00
spi meson: Add windows resource files 2022-10-05 09:56:05 -07:00
sslinfo meson: Add windows resource files 2022-10-05 09:56:05 -07:00
start-scripts Remove contrib/start-scripts/osx/. 2017-11-17 12:53:20 -05:00
tablefunc meson: Add windows resource files 2022-10-05 09:56:05 -07:00
tcn meson: Add windows resource files 2022-10-05 09:56:05 -07:00
test_decoding meson: Add 'running' test setup, as a replacement for installcheck 2022-12-07 12:13:35 -08:00
tsm_system_rows meson: Add windows resource files 2022-10-05 09:56:05 -07:00
tsm_system_time meson: Add windows resource files 2022-10-05 09:56:05 -07:00
unaccent meson: Add windows resource files 2022-10-05 09:56:05 -07:00
uuid-ossp meson: Add windows resource files 2022-10-05 09:56:05 -07:00
vacuumlo meson: Add windows resource files 2022-10-05 09:56:05 -07:00
xml2 Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
contrib-global.mk Respect TEMP_CONFIG when pg_regress_check and friends are called 2016-02-27 12:28:21 -05:00
Makefile Add contrib/pg_walinspect. 2022-04-08 00:26:44 -07:00
meson.build meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.