• Sean McGivern's avatar
    Force Postgres to avoid trigram indexes when in a group · c03386c3
    Sean McGivern authored
    When filtering issues with a search string in a group, we observed on GitLab.com
    that Postgres was using an inefficient query plan, preferring the (global)
    trigram indexes on description and title, rather than using a filter on the
    restricted set of issues within the group.
    
    Change the callers of the IssuableFinder to use a CTE in this case to fence the
    rest of the query from the LIKE filters, so that the optimiser is forced to
    perform the filter in the order we prefer.
    
    This will only force the use of a CTE when:
    
    1. The use_cte_for_search params is truthy.
    2. We are using Postgres.
    3. We have passed the `search` param.
    
    The third item is important - searching issues using the search box does not use
    the finder in this way, but contructs a query and appends `full_search` to
    that. For some reason, this query does not suffer from the same issue.
    
    Currenly, we only pass this param when filtering issuables (issues or MRs) in a
    group context.
    c03386c3