Actions
Patch #38319
closedOptimize IssueQuery#sql_for_assigned_to_role_field for PostgreSQL performance
Description
In our installation, with plenty of issues and projects, we met a performance issue with the assigned_to_role
filter on issues.
The SQL query was very slow when using this filter.
So, here is a patch to make this request a lot faster:
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index eb7684cc2..ec3d5ec62 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -575,8 +575,9 @@ class IssueQuery < Query
end
sw = operator == "!" ? 'NOT' : ''
nl = operator == "!" ? "#{Issue.table_name}.assigned_to_id IS NULL OR" : ''
- "(#{nl} #{Issue.table_name}.assigned_to_id #{sw} IN (SELECT DISTINCT #{Member.table_name}.user_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, #{Issue.table_name}.project_id) #{sw} IN (" +
+ " SELECT DISTINCT #{Member.table_name}.user_id, #{Member.table_name}.project_id FROM #{Member.table_name}, #{MemberRole.table_name}" +
+ " WHERE #{Member.table_name}.id = #{MemberRole.table_name}.member_id AND #{role_cond}))"
end
end
Thank you for considering this change.
Files
Related issues
Actions