【问题标题】:Indices on `has_and_belongs_to_many` join-tables`has_and_belongs_to_many` 连接表的索引
【发布时间】:2011-09-02 04:02:45
【问题描述】:

在 Rails 中使用连接表 [:left_id, :right_id] 时,它应该有哪些索引?

我搜索了答案,只发现人们建议包含两个键的单个索引。但在大多数情况下,不需要同时按两个键进行搜索。您要么查找@left.rights,要么查找@right.lefts。我错过了什么吗?

【问题讨论】:

    标签: ruby-on-rails indexing has-and-belongs-to-many jointable


    【解决方案1】:

    如果您尝试使用 RDBMS 语义(多对多关系)查找该问题会更容易。

    请参考这个问题:How to properly index a linking table for many-to-many connection in MySQL?。取决于用例。

    【讨论】:

    • 好的,我会在那里继续讨论。谢谢你的链接。
    猜你喜欢
    • 1970-01-01
    • 2011-05-21
    • 2010-10-21
    • 2010-11-10
    • 2011-12-02
    • 2016-03-10
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多