Vote #80542
未完了Distinct can be removed due to unique constraint in database
0%
説明
Hi, we are a research team that aims to detect and fix performance and data constraints problems in application built upon ORM framework, such as Rails. Redmine provides us with a good platform.
There are two queries can be improved by removing the distinct keyword based on the unique constraint created in database.
@principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
@users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?",
constraint is redmine/db/migrate/20101104182107_add_unique_index_on_members.rb
add_index :members, [:user_id, :project_id], :unique => true
which means (user_id, project_id) will be unique. so this will make above two queries return distinct results without the distinct
call.
表示するデータがありません