summaryrefslogtreecommitdiff
path: root/lib/gitlab/sql
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-10-02 10:14:23 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-10-02 15:31:59 +0200
commitc16b99a49c58161971d1a86613930be439385f02 (patch)
treeefe023f415f4df81b27a8c895b848a71a8c21bff /lib/gitlab/sql
parent147c46cca195f13ef10ec8fc2db160a833121914 (diff)
downloadgitlab-ce-c16b99a49c58161971d1a86613930be439385f02.tar.gz
Use a UNION ALL for getting merge request notesmerge-request-notes-performance
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.rb9
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