public inbox for [email protected]  
help / color / mirror / Atom feed
From: Vinod Sridharan <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Add a check for interrupts in ginInsert
Date: Thu, 12 Mar 2026 13:26:14 -0700
Message-ID: <CAFMdLD6mQvAuStiOGvBJxAEfo6wdjZhj3+JveTLxOX8MVn4zmA@mail.gmail.com> (raw)

Hello,
Please find attached a small patch that adds the ability to check for
interrupts during the insert into the GIN index. Currently, ginInsert
can generate a large number of entries for a given input tuple from
extractEntries. In the case of Json/Jsonb for instance, the standard
opclasses may generate 1 term per path & value (which may be large).
During index build, the build process does check for interrupts in
between the inserts of each entry into the index (since there may be a
large number of entries to insert). However, the same loop during
insert was not checking for interrupts. This patch adds an interrupt
check to allow for early termination if the overall request is
abandoned. I believe this should be a safe point for checking for
interrupts since we should not be in the middle of modifying the index
tree in between entries.

Thanks and Regards,
Vinod Sridharan
[Microsoft]


Attachments:

  [application/octet-stream] v1-0001-Check-for-interrupts-during-gin-insert.patch (1.4K, 2-v1-0001-Check-for-interrupts-during-gin-insert.patch)
  download | inline diff:
From fb27aeab3ec25061ce02cb0f9ca3edf9a0ee328f Mon Sep 17 00:00:00 2001
From: Vinod Sridharan <[email protected]>
Date: Thu, 12 Mar 2026 19:32:02 +0000
Subject: [PATCH v1] Check for interrupts during gin insert. The GIN index
 extractEntries can produce a lot of terms for a given tuple. This is true for
 opclasses like json/jsonb which can have a term per path & value. During the
 build phase of the gin index, we do check for interrupts and ensure that we
 can bail if there are many entries generated. However, during the insert
 phase, this check doesn't exist and we continue on even if there was a
 cancellation. This adds a check for cancellation in between terms. This seems
 like a safe place to do it since at this point, we aren't in the middle of
 modifiying the index tree.

---
 src/backend/access/gin/gininsert.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index c7e38dbe193..97cea5f7d4e 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -850,8 +850,12 @@ ginHeapTupleInsert(GinState *ginstate, OffsetNumber attnum,
 								&nentries, &categories);
 
 	for (i = 0; i < nentries; i++)
+	{
+		/* there could be many entries, so be willing to abort here */
+		CHECK_FOR_INTERRUPTS();
 		ginEntryInsert(ginstate, attnum, entries[i], categories[i],
 					   item, 1, NULL);
+	}
 }
 
 bool
-- 
2.43.0



view thread (2+ 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]
  Subject: Re: Add a check for interrupts in ginInsert
  In-Reply-To: <CAFMdLD6mQvAuStiOGvBJxAEfo6wdjZhj3+JveTLxOX8MVn4zmA@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