public inbox for [email protected]  
help / color / mirror / Atom feed
From: Kirill Reshke <[email protected]>
To: Soumya S Murali <[email protected]>
Cc: Andrey Borodin <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: Andres Freund <[email protected]>
Subject: Re: Fix gistkillitems & add regression test to microvacuum
Date: Wed, 18 Mar 2026 10:42:08 +0500
Message-ID: <CALdSSPirzFew+O0ZVDh81f8m_cwd7SMdRMZwGa-uy7zg078dGQ@mail.gmail.com> (raw)
In-Reply-To: <CAMtXxw_=fD6hAoLPagLT8fEPa6qe=oD-6ecXq2h1UmtBLv_GFA@mail.gmail.com>
References: <CALdSSPgZWX_D8+Fx4YQqRN5eW5iSx_rJdqQhCfdWTvqKXVfJ4w@mail.gmail.com>
	<CALdSSPgPs=gKWkKN0=4yBd49FBY=ijxBz4YGV64vfVMK7YQhpw@mail.gmail.com>
	<CALdSSPiaQptrccvRoHhP3=YqN9-K8duXfLHHm3G=+7FVL8A-Xw@mail.gmail.com>
	<CALdSSPh-QtT8NrhtKsNWwFVF3D4KX6Wy3qs-FPc16c6VAECEyg@mail.gmail.com>
	<CALdSSPgfFWUBc8RoOZe5PmoUGa4LJUDeMTcAT8HwXGCMGJ9uBA@mail.gmail.com>
	<[email protected]>
	<CALdSSPiGnqgvpfQDCydBf-=0hzyUs6Y0o0xNvd53BbcMWTVO=w@mail.gmail.com>
	<[email protected]>
	<CAMtXxw_=fD6hAoLPagLT8fEPa6qe=oD-6ecXq2h1UmtBLv_GFA@mail.gmail.com>

On Wed, 11 Feb 2026 at 17:18, Soumya S Murali
<[email protected]> wrote:
>
> Hi all,
>
> Thank you for the updated patch.
> I reproduced the issue locally by filling a GiST root page, deleting
> all tuples, and triggering a microvacuum by an index-only scan.
> With the patch, The root page is now handled consistently with other
> leaf pages. so->curBlkno and so->curPageLSN are properly set during
> scan, and gistkillitems() operates safely and correctly on the root
> page.
> Based on runtime validation and code inspection, the fix LGTM.
>



Rebased due to  f5eb854ab6d[0]

I have added a [0]committer to CC.

Andres, can you please take a look at this thread, if by chance you
have spare time for it? You have changed kill tuples-related logic
frequently, so you might be interested...

[0] https://git.postgresql.org/cgit/postgresql.git/commit/?id=f5eb854ab6d6281ec2d3143657944bdda6676341

-- 
Best regards,
Kirill Reshke


Attachments:

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

GiST index killitems feature misbehaves for single-page
(ROOT-only) GiST index. This is caused by GiST scan
"current block" variable not beign initialized for
very first-to-scan page (which is ROOT page).
Fix this by moving variable initialization in
read pgae utility function. Also adjust test output
that used to test exactly this bug (starting 377b7ab).

Reviewed-by: Andrey Borodin <[email protected]>
Reviewed-by: Soumya S Murali <[email protected]>

Discussion: https://postgr.es/m/CALdSSPgZWX_D8%2BFx4YQqRN5eW5iSx_rJdqQhCfdWTvqKXVfJ4w%40mail.gmail.com
Discussion: https://postgr.es/m/lxzj26ga6ippdeunz6kuncectr5gfuugmm2ry22qu6hcx6oid6@lzx3sjsqhmt6
---
 src/backend/access/gist/gistget.c              | 6 +++---
 src/test/modules/index/expected/killtuples.out | 2 +-
 src/test/modules/index/specs/killtuples.spec   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c
index 4d7c100d737..851d3679ce4 100644
--- a/src/backend/access/gist/gistget.c
+++ b/src/backend/access/gist/gistget.c
@@ -415,6 +415,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
 	 */
@@ -730,9 +733,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
diff --git a/src/test/modules/index/expected/killtuples.out b/src/test/modules/index/expected/killtuples.out
index a3db2c40936..1d944b493c2 100644
--- a/src/test/modules/index/expected/killtuples.out
+++ b/src/test/modules/index/expected/killtuples.out
@@ -223,7 +223,7 @@ step flush: SELECT FROM pg_stat_force_next_flush();
 step result: SELECT ((heap_blks_read + heap_blks_hit - counter.heap_accesses) > 0) AS has_new_heap_accesses FROM counter, pg_statio_all_tables WHERE relname = 'kill_prior_tuple';
 has_new_heap_accesses
 ---------------------
-t                    
+f                    
 (1 row)
 
 step drop_table: DROP TABLE IF EXISTS kill_prior_tuple;
diff --git a/src/test/modules/index/specs/killtuples.spec b/src/test/modules/index/specs/killtuples.spec
index 3b98ff9f76d..bd923c8bb00 100644
--- a/src/test/modules/index/specs/killtuples.spec
+++ b/src/test/modules/index/specs/killtuples.spec
@@ -96,7 +96,7 @@ permutation
   measure access flush result
   drop_table drop_ext_btree_gist
 
-# Test gist, but with fewer rows - shows that killitems doesn't work anymore!
+# Test gist, but with fewer rows - that killitems used to be buggy.
 permutation
   create_table fill_10 create_ext_btree_gist create_gist flush
   disable_seq disable_bitmap
-- 
2.25.1



view thread (6+ 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], [email protected], [email protected], [email protected]
  Subject: Re: Fix gistkillitems & add regression test to microvacuum
  In-Reply-To: <CALdSSPirzFew+O0ZVDh81f8m_cwd7SMdRMZwGa-uy7zg078dGQ@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