Commit d1f5a92e authored by Tom Lane's avatar Tom Lane

Fix two small bugs in new gistget.c logic.

1. Complain, rather than silently doing nothing, if an "invalid" tuple
is found on a leaf page.  Per off-list discussion with Heikki.

2. Fix oversight in code that removes a GISTSearchItem from the search
queue: we have to reset lastHeap if this was the last heap item in the
parent GISTSearchTreeItem.  Otherwise subsequent additions will do the
wrong thing.  This was probably masked in early testing because in typical
cases the parent item would now be completely empty and would be deleted on
next call.  You'd need a queued non-leaf page at exactly the same distance
as a heap tuple to expose the bug.
parent 387e468b
...@@ -70,9 +70,10 @@ gistindex_keytest(IndexScanDesc scan, ...@@ -70,9 +70,10 @@ gistindex_keytest(IndexScanDesc scan,
{ {
int i; int i;
if (GistPageIsLeaf(page)) /* shouldn't happen */
elog(ERROR, "invalid GIST tuple found on leaf page");
for (i = 0; i < scan->numberOfOrderBys; i++) for (i = 0; i < scan->numberOfOrderBys; i++)
so->distances[i] = -get_float8_infinity(); so->distances[i] = -get_float8_infinity();
*recheck_p = true; /* probably unnecessary */
return true; return true;
} }
...@@ -403,6 +404,8 @@ getNextGISTSearchItem(GISTScanOpaque so) ...@@ -403,6 +404,8 @@ getNextGISTSearchItem(GISTScanOpaque so)
{ {
/* Delink item from chain */ /* Delink item from chain */
so->curTreeItem->head = item->next; so->curTreeItem->head = item->next;
if (item == so->curTreeItem->lastHeap)
so->curTreeItem->lastHeap = NULL;
/* Return item; caller is responsible to pfree it */ /* Return item; caller is responsible to pfree it */
return item; return item;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment