Commit 4de4d351 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '331089-issue-search-materialized-cte' into 'master'

Fix issuable search optimization in PG12

See merge request gitlab-org/gitlab!61880
parents fe2e5641 93a80b7f
......@@ -334,8 +334,7 @@ class IssuableFinder
return items if items.is_a?(ActiveRecord::NullRelation)
if use_cte_for_search?
cte = Gitlab::SQL::RecursiveCTE.new(klass.table_name)
cte << items
cte = Gitlab::SQL::CTE.new(klass.table_name, items)
items = klass.with(cte.to_arel).from(klass.table_name)
end
......
---
title: Fix issuable search optimization in PG12
merge_request: 61880
author:
type: fixed
......@@ -1178,6 +1178,7 @@ RSpec.describe IssuesFinder do
it 'returns true' do
expect(finder.use_cte_for_search?).to be_truthy
expect(finder.execute.to_sql).to match(/^WITH "issues" AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported}/)
end
end
......@@ -1186,6 +1187,7 @@ RSpec.describe IssuesFinder do
it 'returns true' do
expect(finder.use_cte_for_search?).to be_truthy
expect(finder.execute.to_sql).to match(/^WITH "issues" AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported}/)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment