Follow up - improve sql query for searching notes
gitlab-ce!17513 added limits for search counts, but as Andreas pointed out (https://gitlab.com/gitlab-org/gitlab-ce/issues/43242#note_61416277) this query can be optimized further by using CTE in postgres, with something like:
WITH relevant_notes AS (
SELECT notes.note
FROM "notes"
WHERE "notes"."project_id" = 4088907
AND "notes"."noteable_type" = 'Issue'
AND "notes"."system" = 'f'
)
SELECT COUNT(count_column)
FROM (
SELECT 1 AS count_column
FROM relevant_notes
WHERE
"note" ILIKE '%Timed%'
AND "note" ILIKE '%out%'
AND "note" ILIKE '%waiting%'
LIMIT 1001
) subquery_for_count;
By using WITH
we can enforce filtering notes by project id and noteable type first, and then do search text on this subset.