From 871ec0e33673ad9719760131b71a02ecbda82e12 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 3 Feb 2017 16:28:13 -0500
Subject: [PATCH] pageinspect: More type-sanity surgery on the new hash index
 code.

Uniformly expose unsigned quantities using the next-wider signed
integer type (since we have no unsigned types at the SQL level).
At the SQL level, this results a change to report itemoffset as
int4 rather than int2.  Also at the SQL level, report one value
that is an OID as type oid.  Under the hood, uniformly use macros
that match the SQL output type as to both width and signedness.
---
 contrib/pageinspect/hashfuncs.c               | 36 +++++++++----------
 contrib/pageinspect/pageinspect--1.5--1.6.sql |  4 +--
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 49cb12e5189..08663c109d1 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -346,11 +346,11 @@ hash_page_items(PG_FUNCTION_ARGS)
 		MemSet(nulls, 0, sizeof(nulls));
 
 		j = 0;
-		values[j++] = UInt16GetDatum(uargs->offset);
+		values[j++] = Int32GetDatum((int32) uargs->offset);
 		values[j++] = PointerGetDatum(&itup->t_tid);
 
 		hashkey = _hash_get_indextuple_hashkey(itup);
-		values[j] = UInt64GetDatum((uint64) hashkey);
+		values[j] = Int64GetDatum((int64) hashkey);
 
 		tuple = heap_form_tuple(fctx->attinmeta->tupdesc, values, nulls);
 		result = HeapTupleGetDatum(tuple);
@@ -466,7 +466,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
 	MemSet(nulls, 0, sizeof(nulls));
 
 	j = 0;
-	values[j++] = UInt64GetDatum((uint64) bitmapblkno);
+	values[j++] = Int64GetDatum((int64) bitmapblkno);
 	values[j++] = Int32GetDatum(bitmapbit);
 	values[j++] = BoolGetDatum(bit);
 
@@ -515,30 +515,30 @@ hash_metapage_info(PG_FUNCTION_ARGS)
 	MemSet(nulls, 0, sizeof(nulls));
 
 	j = 0;
-	values[j++] = UInt64GetDatum(metad->hashm_magic);
-	values[j++] = UInt64GetDatum(metad->hashm_version);
+	values[j++] = Int64GetDatum((int64) metad->hashm_magic);
+	values[j++] = Int64GetDatum((int64) metad->hashm_version);
 	values[j++] = Float8GetDatum(metad->hashm_ntuples);
-	values[j++] = UInt32GetDatum(metad->hashm_ffactor);
-	values[j++] = UInt32GetDatum(metad->hashm_bsize);
-	values[j++] = UInt32GetDatum(metad->hashm_bmsize);
-	values[j++] = UInt32GetDatum(metad->hashm_bmshift);
-	values[j++] = UInt64GetDatum(metad->hashm_maxbucket);
-	values[j++] = UInt64GetDatum(metad->hashm_highmask);
-	values[j++] = UInt64GetDatum(metad->hashm_lowmask);
-	values[j++] = UInt64GetDatum(metad->hashm_ovflpoint);
-	values[j++] = UInt64GetDatum(metad->hashm_firstfree);
-	values[j++] = UInt64GetDatum(metad->hashm_nmaps);
-	values[j++] = UInt32GetDatum(metad->hashm_procid);
+	values[j++] = Int32GetDatum((int32) metad->hashm_ffactor);
+	values[j++] = Int32GetDatum((int32) metad->hashm_bsize);
+	values[j++] = Int32GetDatum((int32) metad->hashm_bmsize);
+	values[j++] = Int32GetDatum((int32) metad->hashm_bmshift);
+	values[j++] = Int64GetDatum((int64) metad->hashm_maxbucket);
+	values[j++] = Int64GetDatum((int64) metad->hashm_highmask);
+	values[j++] = Int64GetDatum((int64) metad->hashm_lowmask);
+	values[j++] = Int64GetDatum((int64) metad->hashm_ovflpoint);
+	values[j++] = Int64GetDatum((int64) metad->hashm_firstfree);
+	values[j++] = Int64GetDatum((int64) metad->hashm_nmaps);
+	values[j++] = ObjectIdGetDatum((Oid) metad->hashm_procid);
 
 	for (i = 0; i < HASH_MAX_SPLITPOINTS; i++)
-		spares[i] = UInt64GetDatum(metad->hashm_spares[i]);
+		spares[i] = Int64GetDatum((int8) metad->hashm_spares[i]);
 	values[j++] = PointerGetDatum(construct_array(spares,
 												  HASH_MAX_SPLITPOINTS,
 												  INT8OID,
 												  8, FLOAT8PASSBYVAL, 'd'));
 
 	for (i = 0; i < HASH_MAX_BITMAPS; i++)
-		mapp[i] = UInt64GetDatum(metad->hashm_mapp[i]);
+		mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]);
 	values[j++] = PointerGetDatum(construct_array(mapp,
 												  HASH_MAX_BITMAPS,
 												  INT8OID,
diff --git a/contrib/pageinspect/pageinspect--1.5--1.6.sql b/contrib/pageinspect/pageinspect--1.5--1.6.sql
index a22438d3c33..ac3956882c9 100644
--- a/contrib/pageinspect/pageinspect--1.5--1.6.sql
+++ b/contrib/pageinspect/pageinspect--1.5--1.6.sql
@@ -35,7 +35,7 @@ LANGUAGE C STRICT PARALLEL SAFE;
 -- hash_page_items()
 --
 CREATE FUNCTION hash_page_items(IN page bytea,
-	OUT itemoffset smallint,
+	OUT itemoffset int4,
 	OUT ctid tid,
 	OUT data int8)
 RETURNS SETOF record
@@ -70,7 +70,7 @@ CREATE FUNCTION hash_metapage_info(IN page bytea,
     OUT ovflpoint int8,
     OUT firstfree int8,
     OUT nmaps int8,
-    OUT procid int4,
+    OUT procid oid,
     OUT spares int8[],
     OUT mapp int8[])
 AS 'MODULE_PATHNAME', 'hash_metapage_info'
-- 
GitLab