考虑 Mongo 的Compound Indexing示例:
Example Given the following index:
{ "item": 1, "location": 1, "stock": 1 }
MongoDB can use this index to support queries that include:
- the item field, and
- the item field and the location field, and
- the item field and the location field and the stock field.
MongoDB cannot use this index to support queries that include:
- only the location field,
- only the stock field,
- only the location and stock fields, and
- only the item and stock fields.
与简单的排列相比,是否有更好的最小索引数才能支持项目、位置和库存的任何“精确匹配”查询组合?
编辑
为了解决上面缺少的索引,我可以添加Location
、Stock
、Location-Stock
和Item-Stock
索引。请注意,最后 2 个是复合索引,用于处理我的问题中列出的所有查询。
但是,在尝试处理 N 个字段的所有排列时是否有一般规则?