postgresql/src
David Rowley 99c754129d Fix performance regression in tuplesort specializations
697492434 added 3 new qsort specialization functions aimed to improve the
performance of sorting many of the common pass-by-value data types when
they're the leading or only sort key.

Unfortunately, that has caused a performance regression when sorting
datasets where many of the values being compared were equal.  What was
happening here was that we were falling back to the standard sort
comparison function to handle tiebreaks.  When the two given Datums
compared equally we would incur both the overhead of an indirect function
call to the standard comparer to perform the tiebreak and also the
standard comparer function would go and compare the leading key needlessly
all over again.

Here improve the situation in the 3 new comparison functions.  We now
return 0 directly when the two Datums compare equally and we're performing
a 1-key sort.

Here we don't do anything to help the multi-key sort case where the
leading key uses one of the sort specializations functions.  On testing
this case, even when the leading key's values are all equal, there
appeared to be no performance regression.  Let's leave it up to future
work to optimize that case so that the tiebreak function no longer
re-compares the leading key over again.

Another possible fix for this would have been to add 3 additional sort
specialization functions to handle single-key sorts for these
pass-by-value types.  The reason we didn't do that here is that we may
deem some other sort specialization to be more useful than single-key
sorts.  It may be impractical to have sort specialization functions for
every single combination of what may be useful and it was already decided
that further analysis into which ones are the most useful would be delayed
until the v16 cycle.  Let's not let this regression force our hand into
trying to make that decision for v15.

Author: David Rowley
Reviewed-by: John Naylor
Discussion: https://postgr.es/m/CA+hUKGJRbzaAOUtBUcjF5hLtaSHnJUqXmtiaLEoi53zeWSizeA@mail.gmail.com
2022-04-22 16:02:15 +12:00
..
backend Fix performance regression in tuplesort specializations 2022-04-22 16:02:15 +12:00
bin Rethink method for assigning OIDs to the template0 and postgres DBs. 2022-04-21 16:23:15 -04:00
common Add missing error handling in pg_md5_hash(). 2022-04-18 20:04:55 -04:00
fe_utils Allow db.schema.table patterns, but complain about random garbage. 2022-04-20 11:37:29 -04:00
include Remove inadequate assertion check in CTE inlining. 2022-04-21 17:58:52 -04:00
interfaces Fix missed cases in libpq's error handling. 2022-04-21 17:12:49 -04:00
makefiles Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
pl Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
port Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
template Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
test Remove inadequate assertion check in CTE inlining. 2022-04-21 17:58:52 -04:00
timezone Update copyright for 2022 2022-01-07 19:04:57 -05:00
tools Build libpq test programs under MSVC 2022-04-16 09:36:08 -04:00
tutorial Update copyright for 2022 2022-01-07 19:04:57 -05:00
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Update Unicode data to CLDR 41 2022-04-06 08:17:33 +02:00
Makefile.shlib AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS. 2021-09-06 11:27:59 -07:00
nls-global.mk Improve frontend error logging style. 2022-04-08 14:55:14 -04:00