mongodb复合索引的ESR原则

For compound indexes, this rule of thumb is helpful in deciding the order of fields in the index:

  1. First, add those fields against which Equality queries are run.
  2. The next fields to be indexed should reflect the Sort order of the query.
  3. The last fields represent the Range of data to be accessed.

出处:https://www.mongodb.com/blog/post/performance-best-practices-indexing
简单来说就是索引的字段顺序应该是等值查询字段最前面,然后是排序字段,最后是范围查询字段。
这是一个超级有用的小原则。关于mongodb查询性能优化,这系列文章讲得还挺不错的。这篇也有提到一个小技巧:

To determine whether a query is a covered query, use the explain() method. If the explain() output displays totalDocsExamined as 0, this shows the query is covered by an index.

实用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值