From c03386c3914feca56802e6f99bbd0fd08d269472 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 5 Jun 2018 18:31:32 +0100 Subject: Force Postgres to avoid trigram indexes when in a group 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. --- app/controllers/concerns/issuable_collections.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/concerns/issuable_collections.rb') diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index 98a8939a4d0..2ef2ee76855 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -95,6 +95,7 @@ module IssuableCollections elsif @group @filter_params[:group_id] = @group.id @filter_params[:include_subgroups] = true + @filter_params[:use_cte_for_search] = true end @filter_params.permit(finder_type.valid_params) -- cgit v1.2.1