GIN function of pageinspect has inconsistency data type.
Hi all,
I noticed while using gin function of pageinspect that there are some
inconsistency data types.
For example, data type of GinMetaPageData.head, and tail is
BlockNumber, i.g, uint32.
But in ginfunc.c, we get that value as int64.
So I think the output is odd a little. Is it intentional?
- Before
postgres(1)=# select pending_head, pending_tail from
gin_metapage_info(get_raw_page('trgm_idx'::text, 0));
pending_head | pending_tail
--------------------+--------------
4294967295 | 4294967295
(1 row)
- After attaching patch
postgres(1)=# select pending_head, pending_tail from
gin_metapage_info(get_raw_page('trgm_idx'::text, 0));
pending_head | pending_tail
--------------------+------------------
-1 | -1
There are some similar cases except above, so the fixing patch around
ginfunc.c is attached.
Regards,
-------
Sawada Masahiko
Attachments:
fix_pageinspect_inconsistency_data_type.patchapplication/octet-stream; name=fix_pageinspect_inconsistency_data_type.patchDownload
diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index c0de3be..c3951de 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -69,16 +69,16 @@ gin_metapage_info(PG_FUNCTION_ARGS)
memset(nulls, 0, sizeof(nulls));
- values[0] = Int64GetDatum(metadata->head);
- values[1] = Int64GetDatum(metadata->tail);
- values[2] = Int32GetDatum(metadata->tailFreeSize);
- values[3] = Int64GetDatum(metadata->nPendingPages);
+ values[0] = UInt32GetDatum(metadata->head);
+ values[1] = UInt32GetDatum(metadata->tail);
+ values[2] = UInt32GetDatum(metadata->tailFreeSize);
+ values[3] = UInt32GetDatum(metadata->nPendingPages);
values[4] = Int64GetDatum(metadata->nPendingHeapTuples);
/* statistics, updated by VACUUM */
- values[5] = Int64GetDatum(metadata->nTotalPages);
- values[6] = Int64GetDatum(metadata->nEntryPages);
- values[7] = Int64GetDatum(metadata->nDataPages);
+ values[5] = UInt32GetDatum(metadata->nTotalPages);
+ values[6] = UInt32GetDatum(metadata->nEntryPages);
+ values[7] = UInt32GetDatum(metadata->nDataPages);
values[8] = Int64GetDatum(metadata->nEntries);
values[9] = Int32GetDatum(metadata->ginVersion);
@@ -151,8 +151,8 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
memset(nulls, 0, sizeof(nulls));
- values[0] = Int64GetDatum(opaq->rightlink);
- values[1] = Int64GetDatum(opaq->maxoff);
+ values[0] = UInt32GetDatum(opaq->rightlink);
+ values[1] = UInt16GetDatum(opaq->maxoff);
values[2] = PointerGetDatum(
construct_array(flags, nflags, TEXTOID, -1, false, 'i'));
diff --git a/contrib/pageinspect/pageinspect--1.2--1.3.sql b/contrib/pageinspect/pageinspect--1.2--1.3.sql
index 9c55a6e..684e047 100644
--- a/contrib/pageinspect/pageinspect--1.2--1.3.sql
+++ b/contrib/pageinspect/pageinspect--1.2--1.3.sql
@@ -47,14 +47,14 @@ LANGUAGE C STRICT;
-- gin_metapage_info()
--
CREATE FUNCTION gin_metapage_info(IN page bytea,
- OUT pending_head bigint,
- OUT pending_tail bigint,
+ OUT pending_head int4,
+ OUT pending_tail int4,
OUT tail_free_size int4,
- OUT n_pending_pages bigint,
+ OUT n_pending_pages int4,
OUT n_pending_tuples bigint,
- OUT n_total_pages bigint,
- OUT n_entry_pages bigint,
- OUT n_data_pages bigint,
+ OUT n_total_pages int4,
+ OUT n_entry_pages int4,
+ OUT n_data_pages int4,
OUT n_entries bigint,
OUT version int4)
AS 'MODULE_PATHNAME', 'gin_metapage_info'
@@ -64,8 +64,8 @@ LANGUAGE C STRICT;
-- gin_page_opaque_info()
--
CREATE FUNCTION gin_page_opaque_info(IN page bytea,
- OUT rightlink bigint,
- OUT maxoff int4,
+ OUT rightlink int4,
+ OUT maxoff int2,
OUT flags text[])
AS 'MODULE_PATHNAME', 'gin_page_opaque_info'
LANGUAGE C STRICT;
diff --git a/contrib/pageinspect/pageinspect--1.3.sql b/contrib/pageinspect/pageinspect--1.3.sql
index a99e058..3e17e44 100644
--- a/contrib/pageinspect/pageinspect--1.3.sql
+++ b/contrib/pageinspect/pageinspect--1.3.sql
@@ -154,14 +154,14 @@ LANGUAGE C STRICT;
-- gin_metapage_info()
--
CREATE FUNCTION gin_metapage_info(IN page bytea,
- OUT pending_head bigint,
- OUT pending_tail bigint,
+ OUT pending_head int4,
+ OUT pending_tail int4,
OUT tail_free_size int4,
- OUT n_pending_pages bigint,
+ OUT n_pending_pages int4,
OUT n_pending_tuples bigint,
- OUT n_total_pages bigint,
- OUT n_entry_pages bigint,
- OUT n_data_pages bigint,
+ OUT n_total_pages int4,
+ OUT n_entry_pages int4,
+ OUT n_data_pages int4,
OUT n_entries bigint,
OUT version int4)
AS 'MODULE_PATHNAME', 'gin_metapage_info'
@@ -171,8 +171,8 @@ LANGUAGE C STRICT;
-- gin_page_opaque_info()
--
CREATE FUNCTION gin_page_opaque_info(IN page bytea,
- OUT rightlink bigint,
- OUT maxoff int4,
+ OUT rightlink int4,
+ OUT maxoff int2,
OUT flags text[])
AS 'MODULE_PATHNAME', 'gin_page_opaque_info'
LANGUAGE C STRICT;
On 6/16/15 8:26 AM, Sawada Masahiko wrote:
I noticed while using gin function of pageinspect that there are some
inconsistency data types.
For example, data type of GinMetaPageData.head, and tail is
BlockNumber, i.g, uint32.
But in ginfunc.c, we get that value as int64.
You can't put a uint32 into a signed int32 (which is what the SQL int
is). That's why it's returning a bigint.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jun 17, 2015 at 4:11 PM, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
On 6/16/15 8:26 AM, Sawada Masahiko wrote:
I noticed while using gin function of pageinspect that there are some
inconsistency data types.
For example, data type of GinMetaPageData.head, and tail is
BlockNumber, i.g, uint32.
But in ginfunc.c, we get that value as int64.You can't put a uint32 into a signed int32 (which is what the SQL int is).
That's why it's returning a bigint.
I understood why it's returning a bigint.
Thanks!
Regards,
--
Sawada Masahiko
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers