From 737ab85cc08c888d8f8817073909ec0ecdf62d18 Mon Sep 17 00:00:00 2001
From: "Vadim B. Mikheev" <vadim4o@yahoo.com>
Date: Thu, 22 May 1997 16:01:33 +0000
Subject: [PATCH] 1. Pass GISTENTRYs to giststate->penaltyFn by pointers, not
 by vals. 2. Re-initialize keys in gistrescan (if gist used in inner scan).

---
 src/backend/access/gist/gist.c     | 2 +-
 src/backend/access/gist/gistscan.c | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index cc14a2e4487..f5338424c90 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -987,7 +987,7 @@ gistchoose(Relation r, Page p, IndexTuple it, /* it has compressed entry */
 	size = IndexTupleSize(datum) - sizeof(IndexTupleData);
 	datum += sizeof(IndexTupleData);
 	gistdentryinit(giststate,&entry,datum,r,p,i,size,FALSE);
-	(giststate->penaltyFn)(entry, identry, &usize);
+	(giststate->penaltyFn)(&entry, &identry, &usize);
 	if (which_grow < 0 || usize < which_grow) {
 	    which = i;
 	    which_grow = usize;
diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
index 4629de12922..c877538472c 100644
--- a/src/backend/access/gist/gistscan.c
+++ b/src/backend/access/gist/gistscan.c
@@ -118,6 +118,13 @@ gistrescan(IndexScanDesc s, bool fromEnd, ScanKey key)
 	gistfreestack(p->s_markstk);
 	p->s_stack = p->s_markstk = (GISTSTACK *) NULL;
 	p->s_flags = 0x0;
+	for (i = 0; i < s->numberOfKeys; i++)
+	{
+	    s->keyData[i].sk_procedure 
+		= RelationGetGISTStrategy(s->relation, s->keyData[i].sk_attno, 
+					  s->keyData[i].sk_procedure);
+	    s->keyData[i].sk_func = p->giststate->consistentFn;
+	}
     } else {
 	/* initialize opaque data */
 	p = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData));
-- 
GitLab