Small patch fixing a query correctness issue in Gin with operator classes implementing Consistent functions

Started by Vinod Sridharan9 months ago1 messages
#1Vinod Sridharan
vsridh90@gmail.com
1 attachment(s)

Hi All,

Please find a small patch to fix an existing bug in the GIN index that
impacts correctness of query results for operator classes that use a
consistentFunction and do not specify a triConsistent function. This
patch is against the master and fixes an issue not in any release
branches.

Please find the thread discussing this issue and the fix here:
/messages/by-id/CAFMdLD4Ks5b=CbBh1PjFSytm0zdNv9-ddyeE+opusAKCVph7=g@mail.gmail.com

--
Thanks and Regards,
Vinod Sridharan
[Microsoft]

Attachments:

v1-0001-Fix-shimTriConsistentFn-mutating-the-entryRes-val.patchapplication/octet-stream; name=v1-0001-Fix-shimTriConsistentFn-mutating-the-entryRes-val.patchDownload
From 5684bf43cdc15cc54a906d28fb06bd926d481898 Mon Sep 17 00:00:00 2001
From: Vinod Sridharan <vsridh90@gmail.com>
Date: Fri, 11 Apr 2025 16:28:36 -0700
Subject: [PATCH v1] Fix shimTriConsistentFn mutating the entryRes values for
 MAYBE entries

---
 src/backend/access/gin/ginlogic.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/gin/ginlogic.c b/src/backend/access/gin/ginlogic.c
index 665ff9b9810..b3d66acba97 100644
--- a/src/backend/access/gin/ginlogic.c
+++ b/src/backend/access/gin/ginlogic.c
@@ -200,13 +200,20 @@ shimTriConsistentFn(GinScanKey key)
 		recheck |= key->recheckCurItem;
 
 		if (curResult != boolResult)
-			return GIN_MAYBE;
+		{
+			curResult = GIN_MAYBE;
+			break;
+		}
 	}
 
 	/* TRUE with recheck is taken to mean MAYBE */
 	if (curResult == GIN_TRUE && recheck)
 		curResult = GIN_MAYBE;
 
+	/* Restore the maybe entry state */
+	for (i = 0; i < nmaybe; i++)
+		key->entryRes[maybeEntries[i]] = GIN_MAYBE;
+
 	return curResult;
 }
 
-- 
2.25.1