v1-0001-Check-for-interrupts-during-gin-insert.patch

application/octet-stream

Filename: v1-0001-Check-for-interrupts-during-gin-insert.patch
Type: application/octet-stream
Part: 0
Message: Add a check for interrupts in ginInsert

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: 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.
File+
src/backend/access/gin/gininsert.c 4 0
From fb27aeab3ec25061ce02cb0f9ca3edf9a0ee328f Mon Sep 17 00:00:00 2001
From: Vinod Sridharan <vsridh90@gmail.com>
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