From fbf9dce954ce3f07247114726f894292f18ccb1e Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Sun, 9 Aug 2026 16:00:02 -0400 Subject: [PATCH] Add test showing oid sort support mis-orders values above 2^31 btoidsortsupport() uses ssup_datum_unsigned_cmp(), which compares all 64 bits of the Datum. fetch_att() sign-extends every 4-byte pass-by-value attribute, so a deformed oid at or above 2^31 carries 0xFFFFFFFF in the high half of its Datum, while ObjectIdGetDatum() zero-extends. A sort that sees both representations of the same type orders them wrongly. The removed btoidfastcmp() was not exposed to this, because DatumGetObjectId() truncates to 32 bits first. The new test fails as of 51cd5d6f. Co-Authored-By: Claude Opus 5 (1M context) --- src/test/regress/expected/oid.out | 16 ++++++++++++++++ src/test/regress/sql/oid.sql | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/test/regress/expected/oid.out b/src/test/regress/expected/oid.out index b80cb47e0..756024b79 100644 --- a/src/test/regress/expected/oid.out +++ b/src/test/regress/expected/oid.out @@ -181,4 +181,20 @@ SELECT o.* FROM OID_TBL o WHERE o.f1 > '1234'; 99999999 (3 rows) +-- sort support must order oids above 2^31 the way btoidcmp does +SELECT f1 FROM (SELECT f1 FROM OID_TBL UNION ALL SELECT '4294967000'::oid) ss + ORDER BY f1; + f1 +------------ + 5 + 10 + 15 + 987 + 1234 + 1235 + 99999999 + 4294966256 + 4294967000 +(9 rows) + DROP TABLE OID_TBL; diff --git a/src/test/regress/sql/oid.sql b/src/test/regress/sql/oid.sql index a96b2aa1e..d949e2eb1 100644 --- a/src/test/regress/sql/oid.sql +++ b/src/test/regress/sql/oid.sql @@ -54,4 +54,8 @@ SELECT o.* FROM OID_TBL o WHERE o.f1 >= '1234'; SELECT o.* FROM OID_TBL o WHERE o.f1 > '1234'; +-- sort support must order oids above 2^31 the way btoidcmp does +SELECT f1 FROM (SELECT f1 FROM OID_TBL UNION ALL SELECT '4294967000'::oid) ss + ORDER BY f1; + DROP TABLE OID_TBL; -- 2.53.0