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

Multi-key index prevents bounds being used for non-multi-key part

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

      db.multikey.insert({accounts:[1, 2], day:ISODate('2013-01-01')})
      db.multikey.insert({accounts:[1, 2], day:ISODate('2013-01-02')})
      db.multikey.insert({accounts:[1, 2], day:ISODate('2013-01-03')})
      db.multikey.ensureIndex({accounts:1, day:1})
      db.multikey.find({accounts:1, day:{$gte: ISODate('2013-01-01'), $lt: ISODate('2013-01-02')}}).explain()
      {
              "cursor" : "BtreeCursor accounts_1_day_1",
              "isMultiKey" : true,
              "n" : 1,
              "nscannedObjects" : 3,
              "nscanned" : 3,
              "nscannedObjectsAllPlans" : 3,
              "nscannedAllPlans" : 3,
              "scanAndOrder" : false,
              "indexOnly" : false,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "millis" : 0,
              "indexBounds" : {
                      "accounts" : [
                              [
                                      1,
                                      1
                              ]
                      ],
                      "day" : [
                              [
                                      ISODate("2013-01-01T00:00:00Z"),
                                      ISODate("292278995-01--2147483647T07:12:56.808Z")
                              ]
                      ]
              },
              "server" : "vagrant-ubuntu:27017"
      }
      

      I would have expected the upper bound on day to still be sane - day is not multivalue, only accounts is. Alternatively, I would expect the query not to scan so many documents and stop as soon as it finds one that doesn't match the query.

            Assignee:
            Unassigned Unassigned
            Reporter:
            colinhowe Colin Howe
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: