建立两个索引是建立两个独立的B+树,多重索引则是建立一颗B+树,如果两颗B+树是独立的,怎么才能交叉利用呢?
还有下面这个例子,也不知道如何才能混合利用起来?
Consider a collection orders with the following indexes:
{ qty: 1 }
{ status: 1, ord_date: -1 }
To fulfill the following query which specifies a condition on both the qty field and the status field, MongoDB can use the intersection of the two indexes:
看问题似乎很神奇。。不过实际看过去也没啥变化。。
determine if MongoDB used index intersection, run explain(); the results of explain()will include either an AND_SORTED stage or an AND_HASH stage.
归并排序或hash 组合。 类似join的做法。
Stages are descriptive of the operation; e.g.
COLLSCAN for a collection scan
IXSCAN for scanning index keys
FETCH for retrieving documents
SHARD_MERGE for merging results from shards
Index Intersection
For an index intersection plan, the result will include either an AND_SORTED stage or an AND_HASH stage with an inputStages array that details the indexes; e.g.:
In previous versions of MongoDB, cursor.explain() returned the cursor field with the value of Complex Plan for index intersections.
转自:http://www.ihowandwhy.com/z/%E5%85%B3%E4%BA%8EMongoDB%E4%B8%AD%E7%B4%A2%E5%BC%95%E6%96%87%E6%A1%A3%E7%9A%84%E4%B8%80%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9F