New semantics for explain():
explain should re-run all plans for that query but NOT mutate the cache.
----------
In a full explain, the "allPlans" field can report the index bounds used when the query shape was cached. This is misleading, as it appears that some of the alternative plans used the wrong index bounds:
> t = db.t test.t > t.drop() true > t.ensureIndex({a: 1}) WriteResult({ "nInserted" : 1 }) > t.ensureIndex({a: 1, b: 1}) WriteResult({ "nInserted" : 1 }) > t.find({a: "foo"}).explain() { "cursor" : "BtreeCursor a_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 0, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 1, "indexBounds" : { "a" : [ [ "foo", "foo" ] ] }, "server" : "localhost:27017", "filterSet" : false } > t.find({a: "bar"}).explain(true) { "cursor" : "BtreeCursor a_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 0, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "a" : [ [ "bar", "bar" ] ] }, "allPlans" : [ { "cursor" : "BtreeCursor a_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "scanAndOrder" : false, "indexOnly" : false, "nChunkSkips" : 0, "indexBounds" : { "a" : [ [ "bar", "bar" ] ] } }, { "cursor" : "BtreeCursor a_1_b_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "scanAndOrder" : false, "indexOnly" : false, "nChunkSkips" : 0, "indexBounds" : { "a" : [ [ "foo", "foo" ] ], "b" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] } }, { "cursor" : "BasicCursor", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "scanAndOrder" : false, "indexOnly" : false, "nChunkSkips" : 0 } ], "server" : "localhost:27017", "filterSet" : false, "stats" : {
In the above example, the second plan reported in "allPlans" reports index bounds using "foo" rather than "bar".
- is related to
-
SERVER-12830 query does not select best index - uses wrong bounds in full explain
- Closed
-
SERVER-12711 cached plan runner should provide explain info on all plans
- Closed