diff options
author | John Naylor <john.naylor@postgresql.org> | 2022-04-02 15:22:25 +0700 |
---|---|---|
committer | John Naylor <john.naylor@postgresql.org> | 2022-04-02 15:22:25 +0700 |
commit | 6974924347c908335607a4a2f252213d58e21b7c (patch) | |
tree | aa8d5fa5f4aba89f846957410dc0176556180397 /src/backend/utils/adt/timestamp.c | |
parent | db086de5abe5d87b07cddd030092b1f81f99c5ea (diff) | |
download | postgresql-6974924347c908335607a4a2f252213d58e21b7c.tar.gz postgresql-6974924347c908335607a4a2f252213d58e21b7c.zip |
Specialize tuplesort routines for different kinds of abbreviated keys
Previously, the specialized tuplesort routine inlined handling for
reverse-sort and NULLs-ordering but called the datum comparator via a
pointer in the SortSupport struct parameter. Testing has showed that we
can get a useful performance gain by specializing datum comparison for
the different representations of abbreviated keys -- signed and unsigned
64-bit integers and signed 32-bit integers. Almost all abbreviatable data
types will benefit -- the only exception for now is numeric, since the
datum comparison is more complex. The performance gain depends on data
type and input distribution, but often falls in the range of 10-20% faster.
Thomas Munro
Reviewed by Peter Geoghegan, review and performance testing by me
Discussion:
https://www.postgresql.org/message-id/CA%2BhUKGKKYttZZk-JMRQSVak%3DCXSJ5fiwtirFf%3Dn%3DPAbumvn1Ww%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index ae36ff33285..2ba8d41284f 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -37,6 +37,7 @@ #include "utils/datetime.h" #include "utils/float.h" #include "utils/numeric.h" +#include "utils/sortsupport.h" /* * gcc's -ffast-math switch breaks routines that expect exact results from @@ -2155,6 +2156,7 @@ timestamp_cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); } +#ifndef USE_FLOAT8_BYVAL /* note: this is used for timestamptz also */ static int timestamp_fastcmp(Datum x, Datum y, SortSupport ssup) @@ -2164,13 +2166,22 @@ timestamp_fastcmp(Datum x, Datum y, SortSupport ssup) return timestamp_cmp_internal(a, b); } +#endif Datum timestamp_sortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); +#ifdef USE_FLOAT8_BYVAL + /* + * If this build has pass-by-value timestamps, then we can use a standard + * comparator function. + */ + ssup->comparator = ssup_datum_signed_cmp; +#else ssup->comparator = timestamp_fastcmp; +#endif PG_RETURN_VOID(); } |