好奇心からですが、実行したときに大きなパフォーマンスの違いがあるかどうかは誰にもわかりません...
Select something Where foo=1
...と...
Select something Where foo In(1) #just one item not multiple
...単一または結合された SQL クエリでの Mysql と Postgresql の両方。
問題は、 Ruby on Rails スコープを構築していて、どちらのアプローチが優れているのか疑問に思っていることです。
複数のアイテム (IN) に対して 1 つのスコープを作成し、等しい (=) を使用する単一のアイテムに対して 1 つのスコープを作成します。
scope :with_owner_ids, lambda{|owner_class, *ids| where(owner_type: owner_class.model_name, owner_id: ids.flatten)}
scope :with_owner, lambda{|owner| where(owner_type: owner.class.model_name, owner_id: owner.id)}
#... where `foos`.`owner_class`='User' and `foos`.`owner_id` = 15
またはよりきれいに、複数のアイテムのスコープを作成し(IN)、このスコープを単一のアイテムの他のスコープに渡すだけではありません(INも)
scope :with_owner_ids, lambda{|owner_class, *ids| where(owner_type: owner_class.model_name, owner_id: ids.flatten)}
scope :with_owner, lambda{|owner| with_owner_ids(owner.class, owner.id)}
#... where `foos`.`owner_class`='User' and `foos`.`owner_id` IN (15)