From: John Naylor Date: Thu, 2 Jul 2026 08:53:44 +0000 (+0700) Subject: Use ssup_datum_*_cmp in more places X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=51cd5d6f052306e9288ff8c162ca9596432a5d2e;p=thirdparty%2Fpostgresql.git Use ssup_datum_*_cmp in more places The int2, oid, and oid8 "fastcmp" comparators are functionally equivalent to the ssup_datum_int32_cmp (for int2) and ssup_datum_unsigned_cmp (for oid, oid8) functions added by commit 697492434, so simplify by using the latter instead. This has the added benefit of making these types eligible for radix sort. Author: Baji Shaik Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/CA+fm-RMyLC94NfrxCh273+dKs44U0ZJjRczznvzvgw=KtpPNVw@mail.gmail.com --- diff --git a/src/backend/access/nbtree/nbtcompare.c b/src/backend/access/nbtree/nbtcompare.c index 1d343377e98..795fded49d3 100644 --- a/src/backend/access/nbtree/nbtcompare.c +++ b/src/backend/access/nbtree/nbtcompare.c @@ -134,21 +134,12 @@ btint2cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32((int32) a - (int32) b); } -static int -btint2fastcmp(Datum x, Datum y, SortSupport ssup) -{ - int16 a = DatumGetInt16(x); - int16 b = DatumGetInt16(y); - - return (int) a - (int) b; -} - Datum btint2sortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); - ssup->comparator = btint2fastcmp; + ssup->comparator = ssup_datum_int32_cmp; PG_RETURN_VOID(); } @@ -431,26 +422,12 @@ btoidcmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(A_LESS_THAN_B); } -static int -btoidfastcmp(Datum x, Datum y, SortSupport ssup) -{ - Oid a = DatumGetObjectId(x); - Oid b = DatumGetObjectId(y); - - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; -} - Datum btoidsortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); - ssup->comparator = btoidfastcmp; + ssup->comparator = ssup_datum_unsigned_cmp; PG_RETURN_VOID(); } @@ -513,26 +490,12 @@ btoid8cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(A_LESS_THAN_B); } -static int -btoid8fastcmp(Datum x, Datum y, SortSupport ssup) -{ - Oid8 a = DatumGetObjectId8(x); - Oid8 b = DatumGetObjectId8(y); - - if (a > b) - return A_GREATER_THAN_B; - else if (a == b) - return 0; - else - return A_LESS_THAN_B; -} - Datum btoid8sortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); - ssup->comparator = btoid8fastcmp; + ssup->comparator = ssup_datum_unsigned_cmp; PG_RETURN_VOID(); }