开发者

Indices on `has_and_belongs_to_many` join-tables

开发者 https://www.devze.com 2023-03-08 15:45 出处:网络
When using a join-table [:left_id, 开发者_开发百科:right_id] in Rails, what indices should it have?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消