From aa9210b67d0088564d49d65309091c8efad0f841 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Fri, 17 Oct 2008 17:02:42 +0000 Subject: [PATCH] During repeated rescan of GiST index it's possible that scan key 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 | 3 +++ src/backend/access/gist/gistscan.c | 12 +++++++++++- src/include/access/gist_private.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c index b3d0d5e831..73e46d32c3 100644 --- a/src/backend/access/gist/gistget.c +++ b/src/backend/access/gist/gistget.c @@ -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 */ diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index 5e982a8448..29491ff19a 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -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(); diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h index 5c48db871e..eafd4b49a2 100644 --- a/src/include/access/gist_private.h +++ b/src/include/access/gist_private.h @@ -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; -- 2.39.5