spgist-mem-fix.diff

text/plain

Filename: spgist-mem-fix.diff
Type: text/plain
Part: 0
Message: IndexJoin memory problem using spgist and boxes

Patch

Format: unified
File+
src/backend/access/spgist/spgscan.c 4 3
diff --git a/src/backend/access/spgist/spgscan.c b/src/backend/access/spgist/spgscan.c
index 854032d..7e86cec 100644
--- a/src/backend/access/spgist/spgscan.c
+++ b/src/backend/access/spgist/spgscan.c
@@ -209,6 +209,9 @@ spgrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
 {
 	SpGistScanOpaque so = (SpGistScanOpaque) scan->opaque;
 
+	/* clear temp context before proceeding to the next scan */
+	MemoryContextReset(so->tempCxt);
+
 	/* copy scankeys into local storage */
 	if (scankey && scan->numberOfKeys > 0)
 	{
@@ -463,7 +466,7 @@ redirect:
 			in.scankeys = so->keyData;
 			in.nkeys = so->numberOfKeys;
 			in.reconstructedValue = stackEntry->reconstructedValue;
-			in.traversalMemoryContext = oldCtx;
+			in.traversalMemoryContext = so->tempCxt;
 			in.traversalValue = stackEntry->traversalValue;
 			in.level = stackEntry->level;
 			in.returnData = so->want_itup;
@@ -547,8 +550,6 @@ redirect:
 
 		/* done with this scan stack entry */
 		freeScanStackEntry(so, stackEntry);
-		/* clear temp context before proceeding to the next one */
-		MemoryContextReset(so->tempCxt);
 	}
 
 	if (buffer != InvalidBuffer)