-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.2.3
-
Component/s: Querying
-
ALL
If an out of order query plan (one with results that must be sorted in memory after being identified) becomes a winning plan, the 'n' value reported in per plan explain output for this plan is not updated to include matching documents identified after the query plan won. This is in contrast to other attributes like nscanned and nscannedObjects that are updated after the plan wins. And it is in contrast to the behavior of an in order query plan that wins.
Test
c = db.c; c.drop(); c.ensureIndex( { a:1 } ); c.ensureIndex( { b:1 } ); for( i = 0; i < 1000; ++i ) { c.save( { a:i, b:i } ); } printjson( c.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).explain( true ) ); printjson( c.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).sort( { z:1 } ).explain( true ) );
Output with bug pointed out
{ "cursor" : "BtreeCursor a_1", "isMultiKey" : false, "n" : 1000, "nscannedObjects" : 1000, "nscanned" : 1000, "nscannedObjectsAllPlans" : 1202, "nscannedAllPlans" : 1202, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 33, "indexBounds" : { "a" : [ [ 0, 1.7976931348623157e+308 ] ] }, "allPlans" : [ { "cursor" : "BtreeCursor a_1", "n" : 1000, <-- plan 'n' for whole query "nscannedObjects" : 1000, <-- plan 'nscannedObjects' for whole query "nscanned" : 1000, <-- plan 'nscanned' for whole query "indexBounds" : { "a" : [ [ 0, 1.7976931348623157e+308 ] ] } }, { "cursor" : "BtreeCursor b_1", "n" : 101, "nscannedObjects" : 101, "nscanned" : 101, "indexBounds" : { "b" : [ [ 0, 1.7976931348623157e+308 ] ] } }, { "cursor" : "BasicCursor", "n" : 101, "nscannedObjects" : 101, "nscanned" : 101, "indexBounds" : { } } ], "server" : "Aarons-MacBook-Pro.local:27017" } { "cursor" : "BtreeCursor a_1", "isMultiKey" : false, "n" : 1000, "nscannedObjects" : 1000, "nscanned" : 1000, "nscannedObjectsAllPlans" : 1202, "nscannedAllPlans" : 1202, "scanAndOrder" : true, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 75, "indexBounds" : { "a" : [ [ 0, 1.7976931348623157e+308 ] ] }, "allPlans" : [ { "cursor" : "BtreeCursor a_1", "n" : 101, <-- -bug- plan 'n' just until plan on a:1 index wins "nscannedObjects" : 1000, <-- plan 'nscannedObjects' for whole query "nscanned" : 1000, <-- plan 'nscanned' for whole query "indexBounds" : { "a" : [ [ 0, 1.7976931348623157e+308 ] ] } }, { "cursor" : "BtreeCursor b_1", "n" : 101, "nscannedObjects" : 101, "nscanned" : 101, "indexBounds" : { "b" : [ [ 0, 1.7976931348623157e+308 ] ] } }, { "cursor" : "BasicCursor", "n" : 101, "nscannedObjects" : 101, "nscanned" : 101, "indexBounds" : { } } ], "server" : "Aarons-MacBook-Pro.local:27017" }
- is related to
-
SERVER-7945 use plan ordering when reporting "winning" plan at the top of explain
- Closed
- related to
-
SERVER-10448 Revamp explain() formatting
- Closed