Hi, > Hmm, v1 looks good and self-contained to me. Like, anyway, making two > commits (one for signed Int8 and one for unsigned) here is better for > sake of atomicy? > Anyway, I can see there are users of UInt8GetDatum, which are [0] and > forks of Greenplum. So, I am not super-sure removing UInt8* is > desirable.
Fair enough. Let it be a separate patch then. -- Best regards, Aleksander Alekseev
From 728184910b7274d64c4ea25ed3fd2bbfb875b8b7 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Wed, 7 Jan 2026 16:36:36 +0300 Subject: [PATCH v2 2/2] Remove DatumGetUInt8 and UInt8GetDatum These functions were rarely used and created some confusion. Replace the few existing usages with more appropriate alternatives: - use Int16GetDatum in heapfuncs.c - use CharGetDatum/DatumGetChar in nbtcompare.c Also update the char increment/decrement functions to use proper SCHAR_MIN and SCHAR_MAX boundaries instead of 0/UCHAR_MAX. Author: Aleksander Alekseev <[email protected]> Suggested-by: Tom Lane <[email protected]> Suggested-by: David Rowley <[email protected]> Discussion: https://postgr.es/m/CALdSSPhFyb9qLSHee73XtZm1CBWJNo9%2BJzFNf-zUEWCRW5yEiQ%40mail.gmail.com --- contrib/pageinspect/heapfuncs.c | 2 +- src/backend/access/nbtree/nbtcompare.c | 16 ++++++++-------- src/include/postgres.h | 19 ------------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c index 1cf0b44e731..8b35b3c337a 100644 --- a/contrib/pageinspect/heapfuncs.c +++ b/contrib/pageinspect/heapfuncs.c @@ -223,7 +223,7 @@ heap_page_items(PG_FUNCTION_ARGS) values[7] = PointerGetDatum(&tuphdr->t_ctid); values[8] = UInt32GetDatum(tuphdr->t_infomask2); values[9] = UInt32GetDatum(tuphdr->t_infomask); - values[10] = UInt8GetDatum(tuphdr->t_hoff); + values[10] = Int16GetDatum(tuphdr->t_hoff); /* * We already checked that the item is completely within the raw diff --git a/src/backend/access/nbtree/nbtcompare.c b/src/backend/access/nbtree/nbtcompare.c index 8425805a292..2a123082d86 100644 --- a/src/backend/access/nbtree/nbtcompare.c +++ b/src/backend/access/nbtree/nbtcompare.c @@ -617,9 +617,9 @@ btcharcmp(PG_FUNCTION_ARGS) static Datum char_decrement(Relation rel, Datum existing, bool *underflow) { - uint8 cexisting = DatumGetUInt8(existing); + char cexisting = DatumGetChar(existing); - if (cexisting == 0) + if (cexisting == SCHAR_MIN) { /* return value is undefined */ *underflow = true; @@ -627,15 +627,15 @@ char_decrement(Relation rel, Datum existing, bool *underflow) } *underflow = false; - return CharGetDatum((uint8) cexisting - 1); + return CharGetDatum(cexisting - 1); } static Datum char_increment(Relation rel, Datum existing, bool *overflow) { - uint8 cexisting = DatumGetUInt8(existing); + char cexisting = DatumGetChar(existing); - if (cexisting == UCHAR_MAX) + if (cexisting == SCHAR_MAX) { /* return value is undefined */ *overflow = true; @@ -643,7 +643,7 @@ char_increment(Relation rel, Datum existing, bool *overflow) } *overflow = false; - return CharGetDatum((uint8) cexisting + 1); + return CharGetDatum(cexisting + 1); } Datum @@ -655,8 +655,8 @@ btcharskipsupport(PG_FUNCTION_ARGS) sksup->increment = char_increment; /* btcharcmp compares chars as unsigned */ - sksup->low_elem = UInt8GetDatum(0); - sksup->high_elem = UInt8GetDatum(UCHAR_MAX); + sksup->low_elem = CharGetDatum(SCHAR_MIN); + sksup->high_elem = CharGetDatum(SCHAR_MAX); PG_RETURN_VOID(); } diff --git a/src/include/postgres.h b/src/include/postgres.h index 1affc0565bc..b59b6b41e54 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -134,25 +134,6 @@ CharGetDatum(char X) return (Datum) X; } -/* - * DatumGetUInt8 - * Returns 8-bit unsigned integer value of a datum. - */ -static inline uint8 -DatumGetUInt8(Datum X) -{ - return (uint8) X; -} - -/* - * UInt8GetDatum - * Returns datum representation for an 8-bit unsigned integer. - */ -static inline Datum -UInt8GetDatum(uint8 X) -{ - return (Datum) X; -} /* * DatumGetInt16 -- 2.43.0
From 8ccd133cd06d66416c9f718b10ce889a27046724 Mon Sep 17 00:00:00 2001 From: reshke <[email protected]> Date: Tue, 6 Jan 2026 14:03:49 +0000 Subject: [PATCH v2 1/2] Remove Int8GetDatum function. We have no uses of Int8GetDatum in our tree and did not have for a long time (or never). Suggested-by: Tom Lane <[email protected]> --- src/include/postgres.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/include/postgres.h b/src/include/postgres.h index 7d93fbce709..1affc0565bc 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -134,16 +134,6 @@ CharGetDatum(char X) return (Datum) X; } -/* - * Int8GetDatum - * Returns datum representation for an 8-bit integer. - */ -static inline Datum -Int8GetDatum(int8 X) -{ - return (Datum) X; -} - /* * DatumGetUInt8 * Returns 8-bit unsigned integer value of a datum. -- 2.43.0
