Project

General

Profile

Actions

Defect #32612

open

Distinct can be removed due to unique constraint in database

Added by jwjw yy about 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

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.

No data to display

Actions

Also available in: Atom PDF