has_many의 다형성 연관은 일반적으로 다음과 같은 색인됩니다 :Rails 앱에서 has_one 다형성 연관에 어떤 데이터베이스 색인을 사용해야합니까?
# The migration:
t.references :commentable, polymorphic: true, index: true
# Produces this in the schema:
add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type"
그러나, 나는이 has_one 다형성 협회 (세부 사항에 대한 this question 참조)이있다. 이 색인은 여전히 유용합니까? posting_detail_type
과 posting_detail_id
의 조합은 각각 하나씩 만 발생하므로 고유 할 것입니다. 그래서 인덱스가 유용하지 않을 것 같습니다.
이 경우 어떤 색인 생성을 사용해야합니까? posting_detail_type
열에 하나만 있습니까?