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 b3d0d5e8315fca52ea73a1a7177bd2628ef6d667..73e46d32c376c18edc3c9f4ad075b849e45db558 100644 (file)
@@ -134,6 +134,9 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
 
        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 5e982a844845ecb4d5837ba04245f031510b3501..29491ff19a42e82bdfea0a7e548894a703f91e0a 100644 (file)
@@ -98,9 +98,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 5c48db871e15ae9b7e7c82f050f4fdc3eb1a9b9a..eafd4b49a2577579050e7739b2893e47b451bcc0 100644 (file)
@@ -73,6 +73,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;