]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use ssup_datum_*_cmp in more places
authorJohn Naylor <john.naylor@postgresql.org>
Thu, 2 Jul 2026 08:53:44 +0000 (15:53 +0700)
committerJohn Naylor <john.naylor@postgresql.org>
Thu, 2 Jul 2026 08:55:11 +0000 (15:55 +0700)
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 <baji.pgdev@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CA+fm-RMyLC94NfrxCh273+dKs44U0ZJjRczznvzvgw=KtpPNVw@mail.gmail.com

src/backend/access/nbtree/nbtcompare.c

index 1d343377e9801a791ca14c277e51a89c3d6e78d4..795fded49d3b688059d98c3b36d773ac51db435e 100644 (file)
@@ -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();
 }