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

query does not select best index - uses wrong bounds in full explain

    • ALL

      Collection has index

      {o:1}

      and also

      {o:1, m:1}

      where m is an array.
      Optimizer picks o_1 instread of o_1_m_1 even though the latter results in no documents looked at and former results in 100 looked it...

      test@local(2.6.0-rc0) > db.multi.find({o:"c",m:99999}).explain(true)
      {
      	"cursor" : "BtreeCursor o_1",
      	"isMultiKey" : false,
      	"n" : 0,
      	"nscannedObjects" : 100,
      	"nscanned" : 100,
      	"nscannedObjectsAllPlans" : 100,
      	"nscannedAllPlans" : 103,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"o" : [
      			[
      				"c",
      				"c"
      			]
      		]
      	},
      	"allPlans" : [
      		{
      			"cursor" : "BtreeCursor o_1",
      			"isMultiKey" : false,
      			"n" : 0,
      			"nscannedObjects" : 100,
      			"nscanned" : 100,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nChunkSkips" : 0,
      			"indexBounds" : {
      				"o" : [
      					[
      						"c",
      						"c"
      					]
      				]
      			}
      		},
      		{
      			"cursor" : "BtreeCursor o_1_m_1",
      			"isMultiKey" : true,
      			"n" : 0,
      			"nscannedObjects" : 0,
      			"nscanned" : 0,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nChunkSkips" : 0,
      			"indexBounds" : {
      				"o" : [
      					[
      						"a",
      						"a"
      					]
      				],
      				"m" : [
      					[
      						99999,
      						99999
      					]
      				]
      			}
      		},
      		{
      			"cursor" : "BtreeCursor m_1",
      			"isMultiKey" : true,
      			"n" : 0,
      			"nscannedObjects" : 0,
      			"nscanned" : 0,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nChunkSkips" : 0,
      			"indexBounds" : {
      				"m" : [
      					[
      						99999,
      						99999
      					]
      				]
      			}
      		},
      		{
      			"cursor" : "Complex Plan",
      			"n" : 0,
      			"nscannedObjects" : 0,
      			"nscanned" : 1,
      			"nChunkSkips" : 0
      		},
      		{
      			"cursor" : "Complex Plan",
      			"n" : 0,
      			"nscannedObjects" : 0,
      			"nscanned" : 2,
      			"nChunkSkips" : 0
      		},
      		{
      			"cursor" : "BasicCursor",
      			"isMultiKey" : false,
      			"n" : 0,
      			"nscannedObjects" : 0,
      			"nscanned" : 0,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nChunkSkips" : 0
      		}
      	],
      	"server" : "asyasmacbook.local:27017",
      	"filterSet" : false,
      	"stats" : {
      		"type" : "FETCH",
      		"works" : 101,
      		"yields" : 0,
      		"unyields" : 0,
      		"invalidates" : 0,
      		"advanced" : 0,
      		"needTime" : 100,
      		"needFetch" : 0,
      		"isEOF" : 1,
      		"alreadyHasObj" : 0,
      		"forcedFetches" : 0,
      		"matchTested" : 0,
      		"children" : [
      			{
      				"type" : "IXSCAN",
      				"works" : 100,
      				"yields" : 0,
      				"unyields" : 0,
      				"invalidates" : 0,
      				"advanced" : 100,
      				"needTime" : 0,
      				"needFetch" : 0,
      				"isEOF" : 1,
      				"keyPattern" : "{ o: 1.0 }",
      				"boundsVerbose" : "field #0['o']: [\"c\", \"c\"]",
      				"isMultiKey" : 0,
      				"yieldMovedCursor" : 0,
      				"dupsTested" : 0,
      				"dupsDropped" : 0,
      				"seenInvalidated" : 0,
      				"matchTested" : 0,
      				"keysExamined" : 100,
      				"children" : [ ]
      			}
      		]
      	}
      }
      test@local(2.6.0-rc0) > db.multi.find({o:"c",m:99999}).explain()
      {
      	"cursor" : "BtreeCursor o_1",
      	"isMultiKey" : false,
      	"n" : 0,
      	"nscannedObjects" : 100,
      	"nscanned" : 100,
      	"nscannedObjectsAllPlans" : 100,
      	"nscannedAllPlans" : 103,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"o" : [
      			[
      				"c",
      				"c"
      			]
      		]
      	},
      	"server" : "asyasmacbook.local:27017",
      	"filterSet" : false
      }
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: