]> source.dussan.org Git - redmine.git/commitdiff
Optimize IssueQuery#sql_for_assigned_to_role_field for PostgreSQL (#38319).
authorGo MAEDA <maeda@farend.jp>
Mon, 9 Oct 2023 05:30:04 +0000 (05:30 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 9 Oct 2023 05:30:04 +0000 (05:30 +0000)
Contributed by Vincent Robert.

git-svn-id: https://svn.redmine.org/redmine/trunk@22334 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb

index 672785cc10d25d80114073f2c46d9e4785816e96..235bf2fbe4f293e27883df451baee6a837af9530 100644 (file)
@@ -581,10 +581,10 @@ class IssueQuery < Query
       sw = operator == "!" ? 'NOT' : ''
       nl = operator == "!" ? "#{Issue.table_name}.assigned_to_id IS NULL OR" : ''
       subquery =
-        "SELECT DISTINCT #{Member.table_name}.user_id" +
+        "SELECT DISTINCT #{Member.table_name}.user_id, #{Member.table_name}.project_id" +
         " FROM #{Member.table_name}, #{MemberRole.table_name}" +
-        " WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id AND #{Member.table_name}.id = #{MemberRole.table_name}.member_id AND #{role_cond}"
-      "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (#{subquery}))"
+        " WHERE #{Member.table_name}.id = #{MemberRole.table_name}.member_id AND #{role_cond}"
+      "(#{nl} (#{Issue.table_name}.assigned_to_id, #{Issue.table_name}.project_id) #{sw} IN (#{subquery}))"
     end
   end