From f907a58a7139b871fc353368fe8c52e3fcfbcf6f Mon Sep 17 00:00:00 2001 From: Andrey Borodin Date: Thu, 14 Jan 2021 14:49:29 +0500 Subject: [PATCH] Add bool column for LP_DEAF flag to GiST pageinspect functions --- contrib/pageinspect/expected/gist.out | 32 +++++++++---------- contrib/pageinspect/gistfuncs.c | 14 ++++---- contrib/pageinspect/pageinspect--1.8--1.9.sql | 2 ++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/contrib/pageinspect/expected/gist.out b/contrib/pageinspect/expected/gist.out index 5f7d8cea71..86c9e9caa9 100644 --- a/contrib/pageinspect/expected/gist.out +++ b/contrib/pageinspect/expected/gist.out @@ -31,25 +31,25 @@ SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2)); COMMIT; SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx'); - itemoffset | ctid | itemlen | keys -------------+-----------+---------+------------------- - 1 | (1,65535) | 40 | (p)=((166,166)) - 2 | (2,65535) | 40 | (p)=((332,332)) - 3 | (3,65535) | 40 | (p)=((498,498)) - 4 | (4,65535) | 40 | (p)=((664,664)) - 5 | (5,65535) | 40 | (p)=((830,830)) - 6 | (6,65535) | 40 | (p)=((996,996)) - 7 | (7,65535) | 40 | (p)=((1000,1000)) + itemoffset | ctid | itemlen | dead | keys +------------+-----------+---------+------+------------------- + 1 | (1,65535) | 40 | f | (p)=((166,166)) + 2 | (2,65535) | 40 | f | (p)=((332,332)) + 3 | (3,65535) | 40 | f | (p)=((498,498)) + 4 | (4,65535) | 40 | f | (p)=((664,664)) + 5 | (5,65535) | 40 | f | (p)=((830,830)) + 6 | (6,65535) | 40 | f | (p)=((996,996)) + 7 | (7,65535) | 40 | f | (p)=((1000,1000)) (7 rows) SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 1), 'test_gist_idx') LIMIT 5; - itemoffset | ctid | itemlen | keys -------------+-------+---------+------------- - 1 | (0,1) | 40 | (p)=((1,1)) - 2 | (0,2) | 40 | (p)=((2,2)) - 3 | (0,3) | 40 | (p)=((3,3)) - 4 | (0,4) | 40 | (p)=((4,4)) - 5 | (0,5) | 40 | (p)=((5,5)) + itemoffset | ctid | itemlen | dead | keys +------------+-------+---------+------+------------- + 1 | (0,1) | 40 | f | (p)=((1,1)) + 2 | (0,2) | 40 | f | (p)=((2,2)) + 3 | (0,3) | 40 | f | (p)=((3,3)) + 4 | (0,4) | 40 | f | (p)=((4,4)) + 5 | (0,5) | 40 | f | (p)=((5,5)) (5 rows) -- gist_page_items_bytea prints the raw key data as a bytea. The output of that is diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.c index 146b2e91b6..fc35b49024 100644 --- a/contrib/pageinspect/gistfuncs.c +++ b/contrib/pageinspect/gistfuncs.c @@ -151,8 +151,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS) OffsetNumber offset = inter_call_data->offset; HeapTuple resultTuple; Datum result; - Datum values[4]; - bool nulls[4]; + Datum values[5]; + bool nulls[5]; ItemId id; IndexTuple itup; bytea *tuple_bytea; @@ -175,7 +175,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS) tuple_bytea = (bytea *) palloc(tuple_len + VARHDRSZ); SET_VARSIZE(tuple_bytea, tuple_len + VARHDRSZ); memcpy(VARDATA(tuple_bytea), itup, tuple_len); - values[3] = PointerGetDatum(tuple_bytea); + values[3] = BoolGetDatum(ItemIdIsDead(id)); + values[4] = PointerGetDatum(tuple_bytea); /* Build and return the result tuple. */ resultTuple = heap_form_tuple(inter_call_data->tupd, values, nulls); @@ -245,8 +246,8 @@ gist_page_items(PG_FUNCTION_ARGS) OffsetNumber offset = inter_call_data->offset; HeapTuple resultTuple; Datum result; - Datum values[4]; - bool nulls[4]; + Datum values[5]; + bool nulls[5]; ItemId id; IndexTuple itup; Datum itup_values[INDEX_MAX_KEYS]; @@ -271,7 +272,8 @@ gist_page_items(PG_FUNCTION_ARGS) values[0] = DatumGetInt16(offset); values[1] = ItemPointerGetDatum(&itup->t_tid); values[2] = Int32GetDatum((int) IndexTupleSize(itup)); - values[3] = CStringGetTextDatum(key_desc); + values[3] = BoolGetDatum(ItemIdIsDead(id)); + values[4] = CStringGetTextDatum(key_desc); /* Build and return the result tuple. */ resultTuple = heap_form_tuple(inter_call_data->tupd, values, nulls); diff --git a/contrib/pageinspect/pageinspect--1.8--1.9.sql b/contrib/pageinspect/pageinspect--1.8--1.9.sql index 9dc342fabc..e2a704b6e8 100644 --- a/contrib/pageinspect/pageinspect--1.8--1.9.sql +++ b/contrib/pageinspect/pageinspect--1.8--1.9.sql @@ -22,6 +22,7 @@ CREATE FUNCTION gist_page_items_bytea(IN page bytea, OUT itemoffset smallint, OUT ctid tid, OUT itemlen smallint, + OUT dead boolean, OUT key_data bytea) RETURNS SETOF record AS 'MODULE_PATHNAME', 'gist_page_items_bytea' @@ -35,6 +36,7 @@ CREATE FUNCTION gist_page_items(IN page bytea, OUT itemoffset smallint, OUT ctid tid, OUT itemlen smallint, + OUT dead boolean, OUT keys text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'gist_page_items' -- 2.24.3 (Apple Git-128)