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

index on date range on embedded collection is not used correctly

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.8, 2.6.3
    • Component/s: Index Maintenance, Querying
    • None
    • ALL

      given the following collection:

      db.test.find().pretty()
      {
      	"_id" : ObjectId("53fe2798a3cfa2769eb8ca96"),
      	"name" : "jon",
      	"a" : [
      		{
      			"someDate" : ISODate("2011-02-28T12:49:00Z")
      		},
      		{
      			"someDate" : ISODate("2011-03-31T11:56:00Z")
      		},
      		{
      			"someDate" : ISODate("2012-12-03T20:22:00Z")
      		}
      	]
      }
      

      and the following indexes:

      db.test.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"ns" : "db.test",
      		"name" : "_id_"
      	},
      	{
      		"v" : 1,
      		"key" : {
      			"a.someDate" : 1
      		},
      		"ns" : "db.test",
      		"name" : "a.someDate_1"
      	}
      ]
      

      here is the explain of the query:

      db.test.find({'a' :{$elemMatch : {'someDate':{$gte:ISODate("2011-03-01T00:00:00"), $lte:ISODate("2011-05-01T00:00:00")}}}}).explain()
      {
      	"cursor" : "BtreeCursor a.someDate_1",
      	"isMultiKey" : true,
      	"n" : 1,
      	"nscannedObjects" : 2,
      	"nscanned" : 2,
      	"nscannedObjectsAllPlans" : 2,
      	"nscannedAllPlans" : 2,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"a.someDate" : [
      			[
      				ISODate("2011-03-01T00:00:00Z"),
      				ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")
      			]
      		]
      	},
      	"server" : "local":27017"
      }
      

      1. the collection is being scanned twice
      2. upper index bound is NaN

      I would expect the index to be used for this range query with proper lower/upper bounds.

            Assignee:
            Unassigned Unassigned
            Reporter:
            romio Roman Gavrilov
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: