A question about the index document in MongoDB?
-
To illustrate index intersection, consider a collection orders which has the following indexes:
{Qty:1} {Item:1}
MongoDB can use the intersection of the indexes to the following query:
Db.orders.find ({item: "Abc123", Qty: {$gt: 15}})
The above is the index of MongoDB document, said the following query can be used to cross the above two indexes to optimize, but according to my understanding, need to establish a multi-index before the line, as follows:
{qty:1, item:1}
Building two indexes is to build two separate B + trees, multiple indexes are to build a B + tree, if two B + trees are independent, how can cross-use it?
And here's an example of how you can mix and use it.
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 indexes:
Db.orders.find ({qty: {$gt: ten}, Status: "A"})
It seems amazing to see the question. But the actual look of the past has not changed.
Determine if MongoDB used index intersection, run explain (); The results of explain () would include either an and_sorted stage or an and_hash stage.
Merge sort or hash combination. Similar to join practices.
Stages is 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 would include either an AND_SORTED
stage or a AND_HASH
stage with a inputStages
array that D Etails the indexes; e.g.:
{ "stage" : "and_sorted" span class= "s2" > "inputstages" : [{ "stage" : "IXSCAN" ... }, { "stage" : "IXSCAN" } ]} /span>
In previous versions of MongoDB, returned the field with the value of a for cursor.explain()
cursor
Complex Plan
index intersections.
Transferred from: 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
MongoDB and query may overlap when encountering multiple index--unlike composite indexes