From: Go MAEDA Date: Mon, 9 Oct 2023 05:30:04 +0000 (+0000) Subject: Optimize IssueQuery#sql_for_assigned_to_role_field for PostgreSQL (#38319). X-Git-Tag: 5.1.0~63 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bfe619ae7e531db8a003f4a623ff29f120ac0755;p=redmine.git Optimize IssueQuery#sql_for_assigned_to_role_field for PostgreSQL (#38319). Contributed by Vincent Robert. git-svn-id: https://svn.redmine.org/redmine/trunk@22334 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 672785cc1..235bf2fbe 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -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