• Tom Lane's avatar
    Fix bugs in gin_fuzzy_search_limit processing. · e41955fa
    Tom Lane authored
    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
    e41955fa
gin.sql 4.19 KB