aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gist/gistutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/gist/gistutil.c')
-rw-r--r--src/backend/access/gist/gistutil.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c
index 0ae4176132e..806f229800f 100644
--- a/src/backend/access/gist/gistutil.c
+++ b/src/backend/access/gist/gistutil.c
@@ -23,12 +23,6 @@
#include "storage/bufmgr.h"
#include "utils/rel.h"
-/*
- * static *S used for temrorary storage (saves stack and palloc() call)
- */
-
-static Datum attrS[INDEX_MAX_KEYS];
-static bool isnullS[INDEX_MAX_KEYS];
/*
* Write itup vector to page, has no control of free space.
@@ -150,12 +144,12 @@ gistfillitupvec(IndexTuple *vec, int veclen, int *memlen)
}
/*
- * Make unions of keys in IndexTuple vector, return FALSE if itvec contains
- * invalid tuple. Resulting Datums aren't compressed.
+ * Make unions of keys in IndexTuple vector (one union datum per index column).
+ * Union Datums are returned into the attr/isnull arrays.
+ * Resulting Datums aren't compressed.
*/
-
void
-gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startkey,
+gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len,
Datum *attr, bool *isnull)
{
int i;
@@ -164,19 +158,12 @@ gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startke
evec = (GistEntryVector *) palloc((len + 2) * sizeof(GISTENTRY) + GEVHDRSZ);
- for (i = startkey; i < giststate->tupdesc->natts; i++)
+ for (i = 0; i < giststate->tupdesc->natts; i++)
{
int j;
+ /* Collect non-null datums for this column */
evec->n = 0;
- if (!isnull[i])
- {
- gistentryinit(evec->vector[evec->n], attr[i],
- NULL, NULL, (OffsetNumber) 0,
- FALSE);
- evec->n++;
- }
-
for (j = 0; j < len; j++)
{
Datum datum;
@@ -194,7 +181,7 @@ gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startke
evec->n++;
}
- /* If this tuple vector was all NULLs, the union is NULL */
+ /* If this column was all NULLs, the union is NULL */
if (evec->n == 0)
{
attr[i] = (Datum) 0;
@@ -204,6 +191,7 @@ gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startke
{
if (evec->n == 1)
{
+ /* unionFn may expect at least two inputs */
evec->n = 2;
evec->vector[1] = evec->vector[0];
}
@@ -226,11 +214,12 @@ gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, int startke
IndexTuple
gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
{
- memset(isnullS, TRUE, sizeof(bool) * giststate->tupdesc->natts);
+ Datum attr[INDEX_MAX_KEYS];
+ bool isnull[INDEX_MAX_KEYS];
- gistMakeUnionItVec(giststate, itvec, len, 0, attrS, isnullS);
+ gistMakeUnionItVec(giststate, itvec, len, attr, isnull);
- return gistFormTuple(giststate, r, attrS, isnullS, false);
+ return gistFormTuple(giststate, r, attr, isnull, false);
}
/*
@@ -242,12 +231,15 @@ gistMakeUnionKey(GISTSTATE *giststate, int attno,
GISTENTRY *entry2, bool isnull2,
Datum *dst, bool *dstisnull)
{
-
+ /* we need a GistEntryVector with room for exactly 2 elements */
+ union
+ {
+ GistEntryVector gev;
+ char padding[2 * sizeof(GISTENTRY) + GEVHDRSZ];
+ } storage;
+ GistEntryVector *evec = &storage.gev;
int dstsize;
- static char storage[2 * sizeof(GISTENTRY) + GEVHDRSZ];
- GistEntryVector *evec = (GistEntryVector *) storage;
-
evec->n = 2;
if (isnull1 && isnull2)
@@ -323,6 +315,8 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
addentries[INDEX_MAX_KEYS];
bool oldisnull[INDEX_MAX_KEYS],
addisnull[INDEX_MAX_KEYS];
+ Datum attr[INDEX_MAX_KEYS];
+ bool isnull[INDEX_MAX_KEYS];
IndexTuple newtup = NULL;
int i;
@@ -337,19 +331,20 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
gistMakeUnionKey(giststate, i,
oldentries + i, oldisnull[i],
addentries + i, addisnull[i],
- attrS + i, isnullS + i);
+ attr + i, isnull + i);
if (neednew)
/* we already need new key, so we can skip check */
continue;
- if (isnullS[i])
+ if (isnull[i])
/* union of key may be NULL if and only if both keys are NULL */
continue;
if (!addisnull[i])
{
- if (oldisnull[i] || gistKeyIsEQ(giststate, i, oldentries[i].key, attrS[i]) == false)
+ if (oldisnull[i] ||
+ !gistKeyIsEQ(giststate, i, oldentries[i].key, attr[i]))
neednew = true;
}
}
@@ -357,7 +352,7 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
if (neednew)
{
/* need to update key */
- newtup = gistFormTuple(giststate, r, attrS, isnullS, false);
+ newtup = gistFormTuple(giststate, r, attr, isnull, false);
newtup->t_tid = oldtup->t_tid;
}