diff options
Diffstat (limited to 'src/backend/access/gin/ginget.c')
-rw-r--r-- | src/backend/access/gin/ginget.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c index b9de54a717e..fec3a8fb9d5 100644 --- a/src/backend/access/gin/ginget.c +++ b/src/backend/access/gin/ginget.c @@ -801,9 +801,8 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, /* A bitmap result */ BlockNumber advancePastBlk = GinItemPointerGetBlockNumber(&advancePast); OffsetNumber advancePastOff = GinItemPointerGetOffsetNumber(&advancePast); - bool gotitem = false; - do + for (;;) { /* * If we've exhausted all items on this block, move to next block @@ -852,7 +851,6 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, * estimate number of results on this page to support correct * reducing of result even if it's enabled. */ - gotitem = true; break; } @@ -865,7 +863,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, /* * First, do a quick check against the last offset on the * page. If that's > advancePast, so are all the other - * offsets. + * offsets, so just go back to the top to get the next page. */ if (entry->matchResult->offsets[entry->matchResult->ntuples - 1] <= advancePastOff) { @@ -882,8 +880,11 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, entry->matchResult->blockno, entry->matchResult->offsets[entry->offset]); entry->offset++; - gotitem = true; - } while (!gotitem || (entry->reduceResult == true && dropItem(entry))); + + /* Done unless we need to reduce the result */ + if (!entry->reduceResult || !dropItem(entry)) + break; + } } else if (!BufferIsValid(entry->buffer)) { @@ -891,7 +892,7 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, * A posting list from an entry tuple, or the last page of a posting * tree. */ - do + for (;;) { if (entry->offset >= entry->nlist) { @@ -901,13 +902,20 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, } entry->curItem = entry->list[entry->offset++]; - } while (ginCompareItemPointers(&entry->curItem, &advancePast) <= 0); - /* XXX: shouldn't we apply the fuzzy search limit here? */ + + /* If we're not past advancePast, keep scanning */ + if (ginCompareItemPointers(&entry->curItem, &advancePast) <= 0) + continue; + + /* Done unless we need to reduce the result */ + if (!entry->reduceResult || !dropItem(entry)) + break; + } } else { /* A posting tree */ - do + for (;;) { /* If we've processed the current batch, load more items */ while (entry->offset >= entry->nlist) @@ -923,8 +931,20 @@ entryGetItem(GinState *ginstate, GinScanEntry entry, entry->curItem = entry->list[entry->offset++]; - } while (ginCompareItemPointers(&entry->curItem, &advancePast) <= 0 || - (entry->reduceResult == true && dropItem(entry))); + /* If we're not past advancePast, keep scanning */ + if (ginCompareItemPointers(&entry->curItem, &advancePast) <= 0) + continue; + + /* Done unless we need to reduce the result */ + if (!entry->reduceResult || !dropItem(entry)) + break; + + /* + * Advance advancePast (so that entryLoadMoreItems will load the + * right data), and keep scanning + */ + advancePast = entry->curItem; + } } } |