public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aleksander Alekseev <[email protected]>
To: pgsql-hackers <[email protected]>
Cc: Kirill Reshke <[email protected]>
Cc: David Rowley <[email protected]>
Cc: Tom Lane <[email protected]>
Subject: Re: Define DatumGetInt8 function.
Date: Wed, 7 Jan 2026 17:03:19 +0300
Message-ID: <CAJ7c6TM4zecvHj0F9Xk-V1gKqjYQOR4EjerTVkrZ18+w-6JN3Q@mail.gmail.com> (raw)
In-Reply-To: <CALdSSPjSaTvQL28csVo-8hNg8xJ5=YFr6qwtF=JAMLb1eJO2gQ@mail.gmail.com>
References: <CALdSSPhFyb9qLSHee73XtZm1CBWJNo9+JzFNf-zUEWCRW5yEiQ@mail.gmail.com>
	<[email protected]>
	<CALdSSPg6UgK+6LJmFQ6G3av4J6dbngN7=QwQEuFZApnpmXgVWQ@mail.gmail.com>
	<CAApHDvoShMiWPSkV8zE3tu7uo9GEmuoe=gTpM0+GfOFh2iDmmw@mail.gmail.com>
	<CALdSSPjmukA1WGyYVqJMPD8080Rm9oXPVLn5T64xFCj6wKAenQ@mail.gmail.com>
	<CAJ7c6TPsaLW7O67vqv8YyV_qUUjF0pncDB7dCQJFDw0so7wrdw@mail.gmail.com>
	<CALdSSPjSaTvQL28csVo-8hNg8xJ5=YFr6qwtF=JAMLb1eJO2gQ@mail.gmail.com>

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


Attachments:

  [text/x-patch] v2-0002-Remove-DatumGetUInt8-and-UInt8GetDatum.patch (3.7K, 2-v2-0002-Remove-DatumGetUInt8-and-UInt8GetDatum.patch)
  download | inline diff:
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



  [text/x-patch] v2-0001-Remove-Int8GetDatum-function.patch (875B, 3-v2-0001-Remove-Int8GetDatum-function.patch)
  download | inline diff:
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



view thread (6+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Define DatumGetInt8 function.
  In-Reply-To: <CAJ7c6TM4zecvHj0F9Xk-V1gKqjYQOR4EjerTVkrZ18+w-6JN3Q@mail.gmail.com>

* 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