pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Add functions to 'pageinspect' to inspect GiST indexes.
4+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2021-02-15 9e596b65f4 Add "LP_DEAD item?" column to GiST pageinspect functions
* pgsql: Add functions to 'pageinspect' to inspect GiST indexes.
@ 2021-01-13 08:36 Heikki Linnakangas <heikki.linnakangas@iki.fi>
2021-02-11 20:53 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 4+ messages in thread
From: Heikki Linnakangas @ 2021-01-13 08:36 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Add functions to 'pageinspect' to inspect GiST indexes.
Author: Andrey Borodin and me
Discussion: https://www.postgresql.org/message-id/3E4F9093-A1B5-4DF8-A292-0B48692E3954%40yandex-team.ru
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/756ab29124d7850d4392e2227b67b69b61576cd6
Modified Files
--------------
contrib/pageinspect/Makefile | 6 +-
contrib/pageinspect/expected/gist.out | 87 ++++++++
contrib/pageinspect/gistfuncs.c | 287 ++++++++++++++++++++++++++
contrib/pageinspect/pageinspect--1.8--1.9.sql | 41 ++++
contrib/pageinspect/pageinspect.control | 2 +-
contrib/pageinspect/sql/gist.sql | 18 ++
doc/src/sgml/pageinspect.sgml | 89 ++++++++
7 files changed, 527 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes.
2021-01-13 08:36 pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Heikki Linnakangas <heikki.linnakangas@iki.fi>
@ 2021-02-11 20:53 ` Peter Geoghegan <pg@bowt.ie>
2021-02-12 05:22 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Andrey Borodin <x4mmm@yandex-team.ru>
0 siblings, 1 reply; 4+ messages in thread
From: Peter Geoghegan @ 2021-02-11 20:53 UTC (permalink / raw)
To: Heikki Linnakangas <heikki.linnakangas@iki.fi>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>; Andrey Borodin <x4mmm@yandex-team.ru>
On Wed, Jan 13, 2021 at 12:36 AM Heikki Linnakangas
<heikki.linnakangas@iki.fi> wrote:
> Add functions to 'pageinspect' to inspect GiST indexes.
Is gist_page_items() robust with deleted pages? I think that it's
unsafe to assume that deleted pages will have index tuples, since the
page contents will actually be a GISTDeletedPageContents.
Simplest fix would be to assume maxoff is 0 for the page, perhaps.
Right now we just use PageGetMaxOffsetNumber(), which implicitly
assumes that the page uses slotted tuples with an array of line
pointers (actually it can also deal with a zeroed page, but that's not
relevant here).
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes.
2021-01-13 08:36 pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Heikki Linnakangas <heikki.linnakangas@iki.fi>
2021-02-11 20:53 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Peter Geoghegan <pg@bowt.ie>
@ 2021-02-12 05:22 ` Andrey Borodin <x4mmm@yandex-team.ru>
2021-02-15 04:12 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 4+ messages in thread
From: Andrey Borodin @ 2021-02-12 05:22 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Heikki Linnakangas <heikki.linnakangas@iki.fi>; pgsql-committers <pgsql-committers@lists.postgresql.org>
> 12 февр. 2021 г., в 01:53, Peter Geoghegan <pg@bowt.ie> написал(а):
>
> On Wed, Jan 13, 2021 at 12:36 AM Heikki Linnakangas
> <heikki.linnakangas@iki.fi> wrote:
>> Add functions to 'pageinspect' to inspect GiST indexes.
>
> Is gist_page_items() robust with deleted pages? I think that it's
> unsafe to assume that deleted pages will have index tuples, since the
> page contents will actually be a GISTDeletedPageContents.
>
> Simplest fix would be to assume maxoff is 0 for the page, perhaps.
> Right now we just use PageGetMaxOffsetNumber(), which implicitly
> assumes that the page uses slotted tuples with an array of line
> pointers (actually it can also deal with a zeroed page, but that's not
> relevant here).
Thanks, Peter! I agree that taking PageGetMaxOffsetNumber() seems
incorrect for deleted page, because we set pd_lower for the deleted page.
Also, there was an idea to add a column for LP_DEAD.
As long as we are dealing with deleted data anyway, maybe let's add this column?
PFW both patches.
Thanks!
Best regards, Andrey Borodin.
Attachments: download all (2 files, .tar.gz)
0001-Prevent-pageinspect-from-using-maxoffset-on-GiST-del.patch (application/octet-stream, 2.0K) download
From ca2993c4e46ea04cb3b008dbe948f4570cdf185d Mon Sep 17 00:00:00 2001
From: Andrey Borodin <amborodin@acm.org>
Date: Fri, 12 Feb 2021 10:08:50 +0500
Subject: [PATCH 1/2] Prevent pageinspect from using maxoffset on GiST deleted
pages
GistPageSetDeleted() sets pd_lower to indicate that page is occupied with
GISTDeletedPageContents. This value can be wrongfully interpreted as non-zero
maxoffset on deleted GiST page by pageinspect functions.
---
contrib/pageinspect/gistfuncs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.c
index d5da1ea839..6e7f8c8e5a 100644
--- a/contrib/pageinspect/gistfuncs.c
+++ b/contrib/pageinspect/gistfuncs.c
@@ -103,6 +103,7 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
Page page;
OffsetNumber offset;
+ OffsetNumber maxoff = InvalidOffsetNumber;
if (!superuser())
ereport(ERROR,
@@ -135,11 +136,14 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
page = get_page_from_raw(raw_page);
+ /* Maximum offset number may be incorrect on deleted page */
if (GistPageIsDeleted(page))
elog(NOTICE, "page is deleted");
+ else
+ maxoff = PageGetMaxOffsetNumber(page);
for (offset = FirstOffsetNumber;
- offset <= PageGetMaxOffsetNumber(page);
+ offset <= maxoff;
offset++)
{
Datum values[4];
@@ -187,6 +191,7 @@ gist_page_items(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
Page page;
OffsetNumber offset;
+ OffsetNumber maxoff = InvalidOffsetNumber;
if (!superuser())
ereport(ERROR,
@@ -222,11 +227,14 @@ gist_page_items(PG_FUNCTION_ARGS)
page = get_page_from_raw(raw_page);
+ /* Maximum offset number may be incorrect on deleted page */
if (GistPageIsDeleted(page))
elog(NOTICE, "page is deleted");
+ else
+ maxoff = PageGetMaxOffsetNumber(page);
for (offset = FirstOffsetNumber;
- offset <= PageGetMaxOffsetNumber(page);
+ offset <= maxoff;
offset++)
{
Datum values[4];
--
2.24.3 (Apple Git-128)
=
0002-Add-bool-column-for-LP_DEAF-flag-to-GiST-pageinspect.patch (application/octet-stream, 5.2K) download
From bf743c13c067ca472f9518738c7eb02b9dcb36e0 Mon Sep 17 00:00:00 2001
From: Andrey Borodin <amborodin@acm.org>
Date: Fri, 12 Feb 2021 10:03:14 +0500
Subject: [PATCH 2/2] Add bool column for LP_DEAF flag to GiST pageinspect
functions
---
contrib/pageinspect/expected/gist.out | 32 +++++++++----------
contrib/pageinspect/gistfuncs.c | 18 ++++++-----
contrib/pageinspect/pageinspect--1.8--1.9.sql | 2 ++
3 files changed, 28 insertions(+), 24 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 6e7f8c8e5a..a220ab19ab 100644
--- a/contrib/pageinspect/gistfuncs.c
+++ b/contrib/pageinspect/gistfuncs.c
@@ -146,8 +146,8 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
offset <= maxoff;
offset++)
{
- Datum values[4];
- bool nulls[4];
+ Datum values[5];
+ bool nulls[5];
ItemId id;
IndexTuple itup;
bytea *tuple_bytea;
@@ -170,7 +170,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);
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
}
@@ -237,8 +238,8 @@ gist_page_items(PG_FUNCTION_ARGS)
offset <= maxoff;
offset++)
{
- Datum values[4];
- bool nulls[4];
+ Datum values[5];
+ bool nulls[5];
ItemId id;
IndexTuple itup;
Datum itup_values[INDEX_MAX_KEYS];
@@ -260,14 +261,15 @@ gist_page_items(PG_FUNCTION_ARGS)
values[0] = DatumGetInt16(offset);
values[1] = ItemPointerGetDatum(&itup->t_tid);
values[2] = Int32GetDatum((int) IndexTupleSize(itup));
+ values[3] = BoolGetDatum(ItemIdIsDead(id));
key_desc = BuildIndexValueDescription(indexRel, itup_values, itup_isnull);
if (key_desc)
- values[3] = CStringGetTextDatum(key_desc);
+ values[4] = CStringGetTextDatum(key_desc);
else
{
- values[3] = (Datum) 0;
- nulls[3] = true;
+ values[4] = (Datum) 0;
+ nulls[4] = true;
}
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
diff --git a/contrib/pageinspect/pageinspect--1.8--1.9.sql b/contrib/pageinspect/pageinspect--1.8--1.9.sql
index b4248d791f..79a42a7b11 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)
=
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes.
2021-01-13 08:36 pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Heikki Linnakangas <heikki.linnakangas@iki.fi>
2021-02-11 20:53 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Peter Geoghegan <pg@bowt.ie>
2021-02-12 05:22 ` Re: pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Andrey Borodin <x4mmm@yandex-team.ru>
@ 2021-02-15 04:12 ` Peter Geoghegan <pg@bowt.ie>
0 siblings, 0 replies; 4+ messages in thread
From: Peter Geoghegan @ 2021-02-15 04:12 UTC (permalink / raw)
To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: Heikki Linnakangas <heikki.linnakangas@iki.fi>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Thu, Feb 11, 2021 at 9:22 PM Andrey Borodin <x4mmm@yandex-team.ru> wrote:
> Thanks, Peter! I agree that taking PageGetMaxOffsetNumber() seems
> incorrect for deleted page, because we set pd_lower for the deleted page.
> Also, there was an idea to add a column for LP_DEAD.
> As long as we are dealing with deleted data anyway, maybe let's add this column?
> PFW both patches.
I pushed both of your patches this evening.
Thanks!
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-02-15 04:12 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 08:36 pgsql: Add functions to 'pageinspect' to inspect GiST indexes. Heikki Linnakangas <heikki.linnakangas@iki.fi>
2021-02-11 20:53 ` Peter Geoghegan <pg@bowt.ie>
2021-02-12 05:22 ` Andrey Borodin <x4mmm@yandex-team.ru>
2021-02-15 04:12 ` Peter Geoghegan <pg@bowt.ie>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox