pgsql: Fix bugs in gin_fuzzy_search_limit processing. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix bugs in gin_fuzzy_search_limit processing.
Date
Msg-id E1jKPvE-0004M2-6V@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix bugs in gin_fuzzy_search_limit processing.

entryGetItem()'s three code paths each contained bugs associated
with filtering the entries for gin_fuzzy_search_limit.

The posting-tree path failed to advance "advancePast" after having
decided to filter an item.  If we ran out of items on the current
page and needed to advance to the next, what would actually happen
is that entryLoadMoreItems() would re-load the same page.  Eventually,
the random dropItem() test would accept one of the same items it'd
previously rejected, and we'd move on --- but it could take awhile
with small gin_fuzzy_search_limit.  To add insult to injury, this
case would inevitably cause entryLoadMoreItems() to decide it needed
to re-descend from the root, making things even slower.

The posting-list path failed to implement gin_fuzzy_search_limit
filtering at all, so that all entries in the posting list would
be returned.

The bitmap-result path used a "gotitem" variable that it failed to
update in the one place where it'd actually make a difference, ie
at the one "continue" statement.  I think this was unreachable in
practice, because if we'd looped around then it shouldn't be the
case that the entries on the new page are before advancePast.
Still, the "gotitem" variable was contributing nothing to either
clarity or correctness, so get rid of it.

Refactor all three loops so that the termination conditions are
more alike and less unreadable.

The code coverage report showed that we had no coverage at all for
the re-descend-from-root code path in entryLoadMoreItems(), which
seems like a very bad thing, so add a test case that exercises it.
We also had exactly no coverage for gin_fuzzy_search_limit, so add a
simplistic test case that at least hits those code paths a little bit.

Back-patch to all supported branches.

Adé Heyward and Tom Lane

Discussion: https://postgr.es/m/CAEknJCdS-dE1Heddptm7ay2xTbSeADbkaQ8bU2AXRCVC2LdtKQ@mail.gmail.com

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/49b0d13d7646bc3c5af2e98772ddca493b4b86ea

Modified Files
--------------
src/backend/access/gin/ginget.c   | 44 ++++++++++++++++++++++++++++-----------
src/test/regress/expected/gin.out | 40 ++++++++++++++++++++++++++++++++++-
src/test/regress/sql/gin.sql      | 18 +++++++++++++++-
3 files changed, 88 insertions(+), 14 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: Re: pgsql: Document color support
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Include information on buffer usage during planning phase, in EX