we found a problem in GiST with massive insert/update operations
authorBruce Momjian
Tue, 15 May 2001 14:14:49 +0000 (14:14 +0000)
committerBruce Momjian
Tue, 15 May 2001 14:14:49 +0000 (14:14 +0000)
with many NULLs ( inserting of NULL into indexed field cause
ERROR: MemoryContextAlloc: invalid request size)
As a workaround 'vacuum analyze' could be used.

This patch resolves the problem, please upply to 7.1.1 sources and
current cvs tree.

Oleg Bartunov

src/backend/access/gist/gist.c
src/backend/access/gist/gistget.c

index 8e7b530dea5c012031bd9b374b3c3675b4c5b420..4b239c76c8b9c893a9d8cc23edc3f880924d9121 100644 (file)
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.75 2001/05/15 03:49:34 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.76 2001/05/15 14:14:49 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1199,13 +1199,17 @@ gistdentryinit(GISTSTATE *giststate, GISTENTRY *e, char *pr, Relation r,
    gistentryinit(*e, pr, r, pg, o, b, l);
    if (giststate->haskeytype)
    {
-       dep = (GISTENTRY *)
-           DatumGetPointer(FunctionCall1(&giststate->decompressFn,
+       if ( b ) {
+           dep = (GISTENTRY *)
+               DatumGetPointer(FunctionCall1(&giststate->decompressFn,
                                          PointerGetDatum(e)));
-       gistentryinit(*e, dep->pred, dep->rel, dep->page, dep->offset, dep->bytes,
+           gistentryinit(*e, dep->pred, dep->rel, dep->page, dep->offset, dep->bytes,
                      dep->leafkey);
-       if (dep != e)
-           pfree(dep);
+           if (dep != e)
+               pfree(dep);
+       } else {
+           gistentryinit(*e, (char*)NULL, r, pg, o, 0, l);
+       }
    }
 }
 
index 8f3b5dd475c96ce0c1b4cacddb51d0ceeae2264b..d6fac6f4e2050eaf5e117b9217fb31787078a676 100644 (file)
@@ -241,16 +241,16 @@ gistindex_keytest(IndexTuple tuple,
                              1,
                              tupdesc,
                              &isNull);
-       gistdentryinit(giststate, &de, (char *) datum, r, p, offset,
-                      IndexTupleSize(tuple) - sizeof(IndexTupleData),
-                      FALSE);
-
-       if (isNull)
+       if (isNull || IndexTupleSize(tuple) == sizeof(IndexTupleData) )
        {
            /* XXX eventually should check if SK_ISNULL */
            return false;
        }
 
+       gistdentryinit(giststate, &de, (char *) datum, r, p, offset,
+                      IndexTupleSize(tuple) - sizeof(IndexTupleData),
+                      FALSE);
+
        if (key[0].sk_flags & SK_COMMUTE)
        {
            test = FunctionCall3(&key[0].sk_func,
@@ -266,6 +266,9 @@ gistindex_keytest(IndexTuple tuple,
                                 ObjectIdGetDatum(key[0].sk_procedure));
        }
 
+       if ( (char*)de.pred != (char*)datum )
+           if ( de.pred ) pfree( de.pred );
+
        if (DatumGetBool(test) == !!(key[0].sk_flags & SK_NEGATE))
            return false;