$all clause with elemMatch uses wider bounds than needed

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.6.10, 2.8.0-rc2
    • Affects Version/s: 2.6.5
    • Component/s: Querying
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      When using $all with $elemMatch criteria, the query uses wider bounds than what it should have used (v2.4 behaves correctly in selecting narrow bounds). Following are steps indicates the wider bounds being queried on the array field "bc":

      db.x.drop();
      db.x.ensureIndex({a: 1, "dims.b": 1, "dims.c": 1});
      db.x.insert({a: 1, bc: [{b: "abc", c: "xyz"}, {b: "gsh", c: "ysh"]});
      db.x.find({
              "a" : 1,
              "bc" : {
                      "$all" : [
                              {
                                      "$elemMatch" : {
                                              "b" : "pl",
                                              "c" : "tgit"
                                      }
                              },
                              {
                                      "$elemMatch" : {
                                              "b" : "xy",
                                              "c" : "ak"
                                              }
                               }
                      ]
              }
      }).explain();
      

      Explain with $all:

      {
      	"cursor" : "BtreeCursor a_1_bc.b_1_bc.c_1",
      	"isMultiKey" : true,
      	"n" : 0,
      	"nscannedObjects" : 2,
      	"nscanned" : 3,
      	"nscannedObjectsAllPlans" : 2,
      	"nscannedAllPlans" : 3,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"a" : [
      			[
      				1,
      				1
      			]
      		],
      		"bc.b" : [
      			[
      				{
      					"$minElement" : 1
      				},
      				{
      					"$maxElement" : 1
      				}
      			]
      		],
      		"bc.c" : [
      			[
      				{
      					"$minElement" : 1
      				},
      				{
      					"$maxElement" : 1
      				}
      			]
      		]
      	},
      	"filterSet" : false
      }
      

            Assignee:
            David Storch
            Reporter:
            Anil Kumar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: