Indices on `has_and_belongs_to_many` join-tables
When using a join-table [:left_id, 开发者_开发百科:right_id]
in Rails, what indices should it have?
I googled for the answer and have only found that people suggest single index containing both keys. But in most cases there's no need to search by both keys simultaneously. You either look up @left.rights
, or @right.lefts
. Am I missing something?
It's easier if you try to look up that problem with RDBMS semantics (many-to-many relation).
Refer to this question on SO: How to properly index a linking table for many-to-many connection in MySQL?. Depends on the use-case.
精彩评论