Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8747

In explain output, per plan 'n' count is not updated after an out of order plan wins

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
    • Operating System:
      ALL

      Description

      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"
      }

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: