public inbox for [email protected]  
help / color / mirror / Atom feed
From: Kirill Reshke <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Fix gistkillitems & add regression test to microvacuum
Date: Thu, 15 Jan 2026 12:00:38 +0500
Message-ID: <CALdSSPgZWX_D8+Fx4YQqRN5eW5iSx_rJdqQhCfdWTvqKXVfJ4w@mail.gmail.com> (raw)

Hi hackers.

While looking at [0] I noticed that XLOG_GIST_DELETE &  XLOG_GIST_PAGE_DELETE
records are not covered.

This thread addresses XLOG_GIST_DELETE, which is also known as a
microvacuum feature.

test.sql contains regression test that trigger this code to be
exercised in stream_regress.pl TAP test.

Test is as follows: we create a gist index on the table, then we
insert exactly 407 records, making the root page full (next insert
will trigger page split). Then I delete all tuples from relation and
trigger Index Only scan to do kill-on-select (killtuples). It marks
gist 0 page (which is root and is leaf) as has_garbage. Then, the next
insertion triggers xlog_gist_delete record.

To verify this I use pageinspect and pg_waldimp (locally). Also this
test is dependent on block size being 8192 which is not good.


And all of this does not work actually without v1-0001, because there
is a bug in GiST which does not call gistkillitmes for the very first
(root) page.

There is also test2.sql which inserts a single tuple, not 407. It can
be used to verify v1-0001.

[0] coverage.postgresql.org/src/backend/access/gist/gistxlog.c.gcov.html


-- 
Best regards,
Kirill Reshke


Attachments:

  [application/octet-stream] test2.sql (501B, 2-test2.sql)
  download

  [application/octet-stream] test.sql (529B, 3-test.sql)
  download

  [application/octet-stream] v1-0001-Fix-gistkillitems-for-GiST-ROOT-page.patch (1.6K, 4-v1-0001-Fix-gistkillitems-for-GiST-ROOT-page.patch)
  download | inline diff:
From 84b0fb6e1ce58c7b917fbcc32e73cadcd265d535 Mon Sep 17 00:00:00 2001
From: reshke <[email protected]>
Date: Thu, 15 Jan 2026 06:34:42 +0000
Subject: [PATCH v1] Fix gistkillitems for GiST  ROOT page.

---
 src/backend/access/gist/gist.c    | 1 +
 src/backend/access/gist/gistget.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 9c219cadf07..2f341df9058 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -1681,6 +1681,7 @@ gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel)
 				maxoff;
 
 	Assert(GistPageIsLeaf(page));
+	Assert(BufferIsLockedByMeInMode(buffer, BUFFER_LOCK_EXCLUSIVE));
 
 	/*
 	 * Scan over all items to see which ones need to be deleted according to
diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c
index 11b214eb99b..7dc34680e2d 100644
--- a/src/backend/access/gist/gistget.c
+++ b/src/backend/access/gist/gistget.c
@@ -407,6 +407,9 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
 	 */
 	so->curPageLSN = BufferGetLSNAtomic(buffer);
 
+	/* save current item BlockNumber for gistkillitems() call */
+	so->curBlkno = pageItem->blkno;
+
 	/*
 	 * check all tuples on page
 	 */
@@ -722,9 +725,6 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
 
 				CHECK_FOR_INTERRUPTS();
 
-				/* save current item BlockNumber for next gistkillitems() call */
-				so->curBlkno = item->blkno;
-
 				/*
 				 * While scanning a leaf page, ItemPointers of matching heap
 				 * tuples are stored in so->pageData.  If there are any on
-- 
2.43.0



view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Fix gistkillitems & add regression test to microvacuum
  In-Reply-To: <CALdSSPgZWX_D8+Fx4YQqRN5eW5iSx_rJdqQhCfdWTvqKXVfJ4w@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox