| From: | John Naylor <john(dot)naylor(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Add ssup_datum_uint32_cmp for comparing OIDs |
| Date: | 2026-08-10 10:30:20 |
| Message-ID: | E1wtNGu-00000000wmh-06Nd@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(dot)parragi(at)percona(dot)com>
Reported-by: Peter Geoghegan <pg(at)bowt(dot)ie>
Suggested-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | John Naylor | 2026-08-10 10:35:10 | pgsql: Rename sort support integer comparators for clarity |
| Previous Message | Peter Eisentraut | 2026-08-10 10:30:14 | pgsql: Translation updates |