Commit 9e596b65 authored by Peter Geoghegan's avatar Peter Geoghegan

Add "LP_DEAD item?" column to GiST pageinspect functions

This brings gist_page_items() and gist_page_items_bytea() in line with
nbtree's bt_page_items() function.

Minor follow-up to commit 756ab291, which added the GiST functions.

Author: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://postgr.es/m/E0794687-7315-4C29-A9C7-EC54D448596D@yandex-team.ru
parent fa41cf8f
...@@ -31,25 +31,25 @@ SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2)); ...@@ -31,25 +31,25 @@ SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2));
COMMIT; COMMIT;
SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx'); SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx');
itemoffset | ctid | itemlen | keys itemoffset | ctid | itemlen | dead | keys
------------+-----------+---------+------------------- ------------+-----------+---------+------+-------------------
1 | (1,65535) | 40 | (p)=((166,166)) 1 | (1,65535) | 40 | f | (p)=((166,166))
2 | (2,65535) | 40 | (p)=((332,332)) 2 | (2,65535) | 40 | f | (p)=((332,332))
3 | (3,65535) | 40 | (p)=((498,498)) 3 | (3,65535) | 40 | f | (p)=((498,498))
4 | (4,65535) | 40 | (p)=((664,664)) 4 | (4,65535) | 40 | f | (p)=((664,664))
5 | (5,65535) | 40 | (p)=((830,830)) 5 | (5,65535) | 40 | f | (p)=((830,830))
6 | (6,65535) | 40 | (p)=((996,996)) 6 | (6,65535) | 40 | f | (p)=((996,996))
7 | (7,65535) | 40 | (p)=((1000,1000)) 7 | (7,65535) | 40 | f | (p)=((1000,1000))
(7 rows) (7 rows)
SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 1), 'test_gist_idx') LIMIT 5; SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 1), 'test_gist_idx') LIMIT 5;
itemoffset | ctid | itemlen | keys itemoffset | ctid | itemlen | dead | keys
------------+-------+---------+------------- ------------+-------+---------+------+-------------
1 | (0,1) | 40 | (p)=((1,1)) 1 | (0,1) | 40 | f | (p)=((1,1))
2 | (0,2) | 40 | (p)=((2,2)) 2 | (0,2) | 40 | f | (p)=((2,2))
3 | (0,3) | 40 | (p)=((3,3)) 3 | (0,3) | 40 | f | (p)=((3,3))
4 | (0,4) | 40 | (p)=((4,4)) 4 | (0,4) | 40 | f | (p)=((4,4))
5 | (0,5) | 40 | (p)=((5,5)) 5 | (0,5) | 40 | f | (p)=((5,5))
(5 rows) (5 rows)
-- gist_page_items_bytea prints the raw key data as a bytea. The output of that is -- gist_page_items_bytea prints the raw key data as a bytea. The output of that is
......
...@@ -146,8 +146,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS) ...@@ -146,8 +146,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
offset <= maxoff; offset <= maxoff;
offset++) offset++)
{ {
Datum values[4]; Datum values[5];
bool nulls[4]; bool nulls[5];
ItemId id; ItemId id;
IndexTuple itup; IndexTuple itup;
bytea *tuple_bytea; bytea *tuple_bytea;
...@@ -170,7 +170,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS) ...@@ -170,7 +170,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
tuple_bytea = (bytea *) palloc(tuple_len + VARHDRSZ); tuple_bytea = (bytea *) palloc(tuple_len + VARHDRSZ);
SET_VARSIZE(tuple_bytea, tuple_len + VARHDRSZ); SET_VARSIZE(tuple_bytea, tuple_len + VARHDRSZ);
memcpy(VARDATA(tuple_bytea), itup, tuple_len); memcpy(VARDATA(tuple_bytea), itup, tuple_len);
values[3] = PointerGetDatum(tuple_bytea); values[3] = BoolGetDatum(ItemIdIsDead(id));
values[4] = PointerGetDatum(tuple_bytea);
tuplestore_putvalues(tupstore, tupdesc, values, nulls); tuplestore_putvalues(tupstore, tupdesc, values, nulls);
} }
...@@ -237,8 +238,8 @@ gist_page_items(PG_FUNCTION_ARGS) ...@@ -237,8 +238,8 @@ gist_page_items(PG_FUNCTION_ARGS)
offset <= maxoff; offset <= maxoff;
offset++) offset++)
{ {
Datum values[4]; Datum values[5];
bool nulls[4]; bool nulls[5];
ItemId id; ItemId id;
IndexTuple itup; IndexTuple itup;
Datum itup_values[INDEX_MAX_KEYS]; Datum itup_values[INDEX_MAX_KEYS];
...@@ -260,14 +261,15 @@ gist_page_items(PG_FUNCTION_ARGS) ...@@ -260,14 +261,15 @@ gist_page_items(PG_FUNCTION_ARGS)
values[0] = DatumGetInt16(offset); values[0] = DatumGetInt16(offset);
values[1] = ItemPointerGetDatum(&itup->t_tid); values[1] = ItemPointerGetDatum(&itup->t_tid);
values[2] = Int32GetDatum((int) IndexTupleSize(itup)); values[2] = Int32GetDatum((int) IndexTupleSize(itup));
values[3] = BoolGetDatum(ItemIdIsDead(id));
key_desc = BuildIndexValueDescription(indexRel, itup_values, itup_isnull); key_desc = BuildIndexValueDescription(indexRel, itup_values, itup_isnull);
if (key_desc) if (key_desc)
values[3] = CStringGetTextDatum(key_desc); values[4] = CStringGetTextDatum(key_desc);
else else
{ {
values[3] = (Datum) 0; values[4] = (Datum) 0;
nulls[3] = true; nulls[4] = true;
} }
tuplestore_putvalues(tupstore, tupdesc, values, nulls); tuplestore_putvalues(tupstore, tupdesc, values, nulls);
......
...@@ -22,6 +22,7 @@ CREATE FUNCTION gist_page_items_bytea(IN page bytea, ...@@ -22,6 +22,7 @@ CREATE FUNCTION gist_page_items_bytea(IN page bytea,
OUT itemoffset smallint, OUT itemoffset smallint,
OUT ctid tid, OUT ctid tid,
OUT itemlen smallint, OUT itemlen smallint,
OUT dead boolean,
OUT key_data bytea) OUT key_data bytea)
RETURNS SETOF record RETURNS SETOF record
AS 'MODULE_PATHNAME', 'gist_page_items_bytea' AS 'MODULE_PATHNAME', 'gist_page_items_bytea'
...@@ -35,6 +36,7 @@ CREATE FUNCTION gist_page_items(IN page bytea, ...@@ -35,6 +36,7 @@ CREATE FUNCTION gist_page_items(IN page bytea,
OUT itemoffset smallint, OUT itemoffset smallint,
OUT ctid tid, OUT ctid tid,
OUT itemlen smallint, OUT itemlen smallint,
OUT dead boolean,
OUT keys text) OUT keys text)
RETURNS SETOF record RETURNS SETOF record
AS 'MODULE_PATHNAME', 'gist_page_items' AS 'MODULE_PATHNAME', 'gist_page_items'
......
...@@ -714,15 +714,15 @@ test=# SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2)); ...@@ -714,15 +714,15 @@ test=# SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2));
the data stored in a page of a <acronym>GiST</acronym> index. For example: the data stored in a page of a <acronym>GiST</acronym> index. For example:
<screen> <screen>
test=# SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx'); test=# SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx');
itemoffset | ctid | itemlen | keys itemoffset | ctid | itemlen | dead | keys
------------+-----------+---------+------------------- ------------+-----------+---------+------+-------------------
1 | (1,65535) | 40 | (p)=((166,166)) 1 | (1,65535) | 40 | f | (p)=((166,166))
2 | (2,65535) | 40 | (p)=((332,332)) 2 | (2,65535) | 40 | f | (p)=((332,332))
3 | (3,65535) | 40 | (p)=((498,498)) 3 | (3,65535) | 40 | f | (p)=((498,498))
4 | (4,65535) | 40 | (p)=((664,664)) 4 | (4,65535) | 40 | f | (p)=((664,664))
5 | (5,65535) | 40 | (p)=((830,830)) 5 | (5,65535) | 40 | f | (p)=((830,830))
6 | (6,65535) | 40 | (p)=((996,996)) 6 | (6,65535) | 40 | f | (p)=((996,996))
7 | (7,65535) | 40 | (p)=((1000,1000)) 7 | (7,65535) | 40 | f | (p)=((1000,1000))
(7 rows) (7 rows)
</screen> </screen>
</para> </para>
...@@ -745,15 +745,15 @@ test=# SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gis ...@@ -745,15 +745,15 @@ test=# SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gis
example: example:
<screen> <screen>
test=# SELECT * FROM gist_page_items_bytea(get_raw_page('test_gist_idx', 0)); test=# SELECT * FROM gist_page_items_bytea(get_raw_page('test_gist_idx', 0));
itemoffset | ctid | itemlen | key_data itemoffset | ctid | itemlen | dead | key_data
------------+-----------+---------+-------------------------------------------&zwsp;----------------------------------------- ------------+-----------+---------+------+-----------------------------------------&zwsp;-------------------------------------------
1 | (1,65535) | 40 | \x00000100ffff28000000000000c0644000000000&zwsp;00c06440000000000000f03f000000000000f03f 1 | (1,65535) | 40 | f | \x00000100ffff28000000000000c0644000000000&zwsp;00c06440000000000000f03f000000000000f03f
2 | (2,65535) | 40 | \x00000200ffff28000000000000c0744000000000&zwsp;00c074400000000000e064400000000000e06440 2 | (2,65535) | 40 | f | \x00000200ffff28000000000000c0744000000000&zwsp;00c074400000000000e064400000000000e06440
3 | (3,65535) | 40 | \x00000300ffff28000000000000207f4000000000&zwsp;00207f400000000000d074400000000000d07440 3 | (3,65535) | 40 | f | \x00000300ffff28000000000000207f4000000000&zwsp;00207f400000000000d074400000000000d07440
4 | (4,65535) | 40 | \x00000400ffff28000000000000c0844000000000&zwsp;00c084400000000000307f400000000000307f40 4 | (4,65535) | 40 | f | \x00000400ffff28000000000000c0844000000000&zwsp;00c084400000000000307f400000000000307f40
5 | (5,65535) | 40 | \x00000500ffff28000000000000f0894000000000&zwsp;00f089400000000000c884400000000000c88440 5 | (5,65535) | 40 | f | \x00000500ffff28000000000000f0894000000000&zwsp;00f089400000000000c884400000000000c88440
6 | (6,65535) | 40 | \x00000600ffff28000000000000208f4000000000&zwsp;00208f400000000000f889400000000000f88940 6 | (6,65535) | 40 | f | \x00000600ffff28000000000000208f4000000000&zwsp;00208f400000000000f889400000000000f88940
7 | (7,65535) | 40 | \x00000700ffff28000000000000408f4000000000&zwsp;00408f400000000000288f400000000000288f40 7 | (7,65535) | 40 | f | \x00000700ffff28000000000000408f4000000000&zwsp;00408f400000000000288f400000000000288f40
(7 rows) (7 rows)
</screen> </screen>
</para> </para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment