diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-10-02 11:14:23 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-10-02 16:31:59 +0300 |
commit | c16b99a49c58161971d1a86613930be439385f02 (patch) | |
tree | efe023f415f4df81b27a8c895b848a71a8c21bff /lib/gitlab/sql | |
parent | 147c46cca195f13ef10ec8fc2db160a833121914 (diff) |
Use a UNION ALL for getting merge request notes
In this particular case the use of UNION ALL leads to a better query
plan compared to using 1 big query that uses an OR statement to combine
different data sources.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/38508 for more
information.
Diffstat (limited to 'lib/gitlab/sql')
-rw-r--r-- | lib/gitlab/sql/union.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/gitlab/sql/union.rb b/lib/gitlab/sql/union.rb index 222021e8802..f30c771837a 100644 --- a/lib/gitlab/sql/union.rb +++ b/lib/gitlab/sql/union.rb @@ -12,8 +12,9 @@ module Gitlab # # Project.where("id IN (#{sql})") class Union - def initialize(relations) + def initialize(relations, remove_duplicates: true) @relations = relations + @remove_duplicates = remove_duplicates end def to_sql @@ -25,7 +26,11 @@ module Gitlab @relations.map { |rel| rel.reorder(nil).to_sql }.reject(&:blank?) end - fragments.join("\nUNION\n") + fragments.join("\n#{union_keyword}\n") + end + + def union_keyword + @remove_duplicates ? 'UNION' : 'UNION ALL' end end end |