During repeated rescan of GiST index it's possible that scan key
authorTeodor Sigaev <teodor@sigaev.ru>
Fri, 17 Oct 2008 17:02:42 +0000 (17:02 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Fri, 17 Oct 2008 17:02:42 +0000 (17:02 +0000)
is NULL but SK_SEARCHNULL is not set. Add checking IS NULL of keys
to set during key initialization. If key is NULL and SK_SEARCHNULL is not
set then nothnig can be satisfied.
With assert-enabled compilation that causes coredump.

Bug was introduced in 8.3 by support of IS NULL index scan.

src/backend/access/gist/gistget.c
src/backend/access/gist/gistscan.c
src/include/access/gist_private.h

index 9a9927ca05f9764c1fc715efb93def05dbe21350..20bc99482dd838896073379f75cc5e8090c912a2 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.69.2.1 2008/08/23 10:40:03 teodor Exp $
+ *   $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.69.2.2 2008/10/17 17:02:42 teodor Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -127,6 +127,9 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids,
 
    so = (GISTScanOpaque) scan->opaque;
 
+   if ( so->qual_ok == false )
+       return 0;
+
    if (ItemPointerIsValid(&so->curpos) == false)
    {
        /* Being asked to fetch the first entry, so start at the root */
index 88e1c6ecbee16075f4c083095d5a0c849b177466..31fb549e53fc34c423a68f5d4b0085a7c387544b 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.68.2.1 2008/08/23 10:40:03 teodor Exp $
+ *   $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.68.2.2 2008/10/17 17:02:42 teodor Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -96,9 +96,19 @@ gistrescan(PG_FUNCTION_ARGS)
         * function in the form of its strategy number, which is available
         * from the sk_strategy field, and its subtype from the sk_subtype
         * field.
+        *
+        * Next, if any of keys is a NULL and that key is not marked with
+        * SK_SEARCHNULL then nothing can be found.
         */
-       for (i = 0; i < scan->numberOfKeys; i++)
+       so->qual_ok = true;
+       for (i = 0; i < scan->numberOfKeys; i++) {
            scan->keyData[i].sk_func = so->giststate->consistentFn[scan->keyData[i].sk_attno - 1];
+
+           if ( scan->keyData[i].sk_flags & SK_ISNULL ) {
+               if ( (scan->keyData[i].sk_flags & SK_SEARCHNULL) == 0 )
+                   so->qual_ok = false;
+           }
+       }
    }
 
    PG_RETURN_VOID();
index e823928c3e2ba4d45b9e911e2b1b3daf69391dfb..1f4ceab37e950dc6fe40a42976799c92fb20b6cd 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.28.2.1 2008/08/23 10:40:03 teodor Exp $
+ * $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.28.2.2 2008/10/17 17:02:42 teodor Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -69,6 +69,7 @@ typedef struct GISTScanOpaqueData
    GISTSearchStack *stack;
    GISTSearchStack *markstk;
    uint16      flags;
+   bool        qual_ok;        /* false if qual can never be satisfied */
    GISTSTATE  *giststate;
    MemoryContext tempCxt;
    Buffer      curbuf;