그래서 다음 중 어느 것이 더 효율적인지 알고 싶습니다. 가장 좋은 대답은 실제로 나 자신을 위해 어떻게 미래에 알아낼 수 있을까요?레일 3에서 주문 쿼리의 효율성
두 쿼리는 다음과 같습니다
# id integer
# created_at datetime
# collection_id integer
# updated_at datetime
class Post < ActiveRecord::Base
belongs_to :collection
end
Post.where(:collection_id => collection_id).order(:updated_at).last
그래서
Post.where(:collection_id => collection_id).order("updated_at DESC").first
대, 2 부 질문 :
1) 그 문장 중 어느 것이 더 효율적입니다? (오타가없는 한 그들은 동등해야합니다.)
2) 어떻게이 질문에 대답 할 수 있었습니까?
색인이없는 것으로 가정합니다. 또한 쿼리의 collect_id 부분에 대한 결과 집합의 예상 크기에 따라 대답이 변경되는지 궁금합니다.