agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: John Naylor <john.naylor@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add ssup_datum_uint32_cmp for comparing OIDs
Date: Mon, 10 Aug 2026 10:30:20 +0000
Message-ID: <E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org> (raw)
Add ssup_datum_uint32_cmp for comparing OIDs
Commit 51cd5d6f0 used ssup_datum_unsigned_cmp for the OID comparator,
which compares entire Datums. That gave wrong results, since the upper
half of a Datum containing a 32-bit type is not reliably zero-extended:
values fetched from tuples are sign-extended, while values returned
by e.g. oidin() are zero-extended. An OID with the high bit set could
therefore compare as larger or smaller depending on its source.
Fix by adding a sort support comparator that only looks at the low 32
bits. Also teach radix sort to normalize Datums the same way. This keeps
OID eligible for radix sort. Add a regression test that sorts OIDs above
2^31 from both kinds of source, taken from Peter Geoghegan's report.
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reported-by: Peter Geoghegan <pg@bowt.ie>
Suggested-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFM2afRzSLJJiWKnRjqPwL7Scm2Wd1xXu140diJGuJtzGg@mail.gmail.com
Discussion: https://postgr.es/m/CAH2-WznvXyKRah=MQ3ONGHiN8ahJcqpmtyikxCOO96A4usDPpg@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/94d32ce1a63c67bce7b811207095ee6d41d4caed
Modified Files
--------------
src/backend/access/nbtree/nbtcompare.c | 2 +-
src/backend/utils/sort/tuplesort.c | 38 ++++++++++++++++++++++++----------
src/include/utils/sortsupport.h | 1 +
src/test/regress/expected/oid.out | 16 ++++++++++++++
src/test/regress/sql/oid.sql | 4 ++++
5 files changed, 49 insertions(+), 12 deletions(-)
Message-ID: <E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org>
Permalink: ../E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: john.naylor@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Add ssup_datum_uint32_cmp for comparing OIDs
In-Reply-To: <E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox