From 86627050a0aed7490b3d39c7c7082290a404455d Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Thu, 19 Jun 2025 10:11:40 +0900
Subject: [PATCH v1 06/12] Switch pg_column_toast_chunk_id() return value from
 oid to bigint

This is required for a follow-up patch that will add support for 8-byte
TOAST values, with this function being changed so as it is able to
support the largest TOAST value type available.
---
 src/include/catalog/pg_proc.dat | 2 +-
 src/backend/utils/adt/varlena.c | 4 +++-
 doc/src/sgml/func.sgml          | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index bdfdddd76fc7..5ff493420658 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -7723,7 +7723,7 @@
   proargtypes => 'any', prosrc => 'pg_column_compression' },
 { oid => '6316', descr => 'chunk ID of on-disk TOASTed value',
   proname => 'pg_column_toast_chunk_id', provolatile => 's',
-  prorettype => 'oid', proargtypes => 'any',
+  prorettype => 'int8', proargtypes => 'any',
   prosrc => 'pg_column_toast_chunk_id' },
 { oid => '2322',
   descr => 'total disk space usage for the specified tablespace',
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 3e4d5568bde8..093994b1070f 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -5318,6 +5318,7 @@ pg_column_toast_chunk_id(PG_FUNCTION_ARGS)
 	int			typlen;
 	struct varlena *attr;
 	struct varatt_external toast_pointer;
+	uint64		toast_valueid;
 
 	/* On first call, get the input type's typlen, and save at *fn_extra */
 	if (fcinfo->flinfo->fn_extra == NULL)
@@ -5345,8 +5346,9 @@ pg_column_toast_chunk_id(PG_FUNCTION_ARGS)
 		PG_RETURN_NULL();
 
 	VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr);
+	toast_valueid = toast_pointer.va_valueid;
 
-	PG_RETURN_OID(toast_pointer.va_valueid);
+	PG_RETURN_UINT64(toast_valueid);
 }
 
 /*
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index ce982c210371..11736a181918 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -30066,7 +30066,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
          <primary>pg_column_toast_chunk_id</primary>
         </indexterm>
         <function>pg_column_toast_chunk_id</function> ( <type>"any"</type> )
-        <returnvalue>oid</returnvalue>
+        <returnvalue>bigint</returnvalue>
        </para>
        <para>
         Shows the <structfield>chunk_id</structfield> of an on-disk
-- 
2.49.0

