0001-Use-ssup_datum_-_cmp-for-int2-oid-and-oid8-sort-supp.patch
application/octet-stream
Filename: 0001-Use-ssup_datum_-_cmp-for-int2-oid-and-oid8-sort-supp.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch 0001
Subject: Use ssup_datum_*_cmp for int2, oid and oid8 sort support
| File | + | − |
|---|---|---|
| src/backend/access/nbtree/nbtcompare.c | 3 | 40 |
From e23fc1c9a28435f56cbb24e6fc23c85dde4062da Mon Sep 17 00:00:00 2001
From: Baji Shaik <baji.pgdev@gmail.com>
Date: Wed, 27 May 2026 01:48:05 +0000
Subject: [PATCH] Use ssup_datum_*_cmp for int2, oid and oid8 sort support
The int2, oid, and oid8 sortsupport functions used custom fastcmp
helpers that are functionally equivalent to ssup_datum_int32_cmp (for
int2) and ssup_datum_unsigned_cmp (for oid, oid8). This prevented
these types from using the radix sort fast path added in commit
ef3c3cf6d02, which dispatches based on the comparator pointer.
Switching to the existing helpers makes int2, oid, and oid8 column
sorts eligible for radix sort, bringing them to parity with int4/int8
baseline.
Author: Baji Shaik <baji.pgdev@gmail.com>
Reviewed-by:
Discussion:
---
src/backend/access/nbtree/nbtcompare.c | 43 ++------------------------
1 file changed, 3 insertions(+), 40 deletions(-)
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();
}
--
2.50.1