mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
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
This commit is contained in:
@@ -119,26 +119,12 @@ btint4cmp(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT32(A_LESS_THAN_B);
|
||||
}
|
||||
|
||||
static int
|
||||
btint4fastcmp(Datum x, Datum y, SortSupport ssup)
|
||||
{
|
||||
int32 a = DatumGetInt32(x);
|
||||
int32 b = DatumGetInt32(y);
|
||||
|
||||
if (a > b)
|
||||
return A_GREATER_THAN_B;
|
||||
else if (a == b)
|
||||
return 0;
|
||||
else
|
||||
return A_LESS_THAN_B;
|
||||
}
|
||||
|
||||
Datum
|
||||
btint4sortsupport(PG_FUNCTION_ARGS)
|
||||
{
|
||||
SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
|
||||
|
||||
ssup->comparator = btint4fastcmp;
|
||||
ssup->comparator = ssup_datum_int32_cmp;
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
@@ -156,6 +142,7 @@ btint8cmp(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT32(A_LESS_THAN_B);
|
||||
}
|
||||
|
||||
#ifndef USE_FLOAT8_BYVAL
|
||||
static int
|
||||
btint8fastcmp(Datum x, Datum y, SortSupport ssup)
|
||||
{
|
||||
@@ -169,13 +156,18 @@ btint8fastcmp(Datum x, Datum y, SortSupport ssup)
|
||||
else
|
||||
return A_LESS_THAN_B;
|
||||
}
|
||||
#endif
|
||||
|
||||
Datum
|
||||
btint8sortsupport(PG_FUNCTION_ARGS)
|
||||
{
|
||||
SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
|
||||
|
||||
#ifdef USE_FLOAT8_BYVAL
|
||||
ssup->comparator = ssup_datum_signed_cmp;
|
||||
#else
|
||||
ssup->comparator = btint8fastcmp;
|
||||
#endif
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user