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

OR query does not use middle field of a compound index

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.8
    • Component/s: Index Maintenance
    • None
    • ALL
    • Hide
      db.test.insert({f1: 10, f2: 10, f3: 20 })
      db.test.insert({f1: 10, f2: 30, f3: 20 })
      db.test.createIndex({f2: 1, f1: 1, f3: 1})
      
      db.test.find({ f1: 10, $or: [ { f2: 10, f3: 20 }, {f2: 30, f3: 20 } ] })

      The query plan will have two index scans with the following bounds:

      "indexBounds" : {
              "f2" : [
                      "[30.0, 30.0]"
              ],
              "f1" : [
                      "[MinKey, MaxKey]"
              ],
              "f3" : [
                      "[20.0, 20.0]"
              ]
      }

      Note the [MinKey, MaxKey] on the bounds for f1. This should be [10, 10], from the condition in the query

      Show
      db.test.insert({f1: 10, f2: 10, f3: 20 }) db.test.insert({f1: 10, f2: 30, f3: 20 }) db.test.createIndex({f2: 1, f1: 1, f3: 1}) db.test.find({ f1: 10, $or: [ { f2: 10, f3: 20 }, {f2: 30, f3: 20 } ] }) The query plan will have two index scans with the following bounds: "indexBounds" : { "f2" : [ "[30.0, 30.0]" ], "f1" : [ "[MinKey, MaxKey]" ], "f3" : [ "[20.0, 20.0]" ] } Note the [MinKey, MaxKey] on the bounds for f1. This should be [10, 10] , from the condition in the query

      When doing an OR query with an equality match, if the equality match is on one of the fields of a compound index, bounds are not applied to that index correctly

            Assignee:
            Unassigned Unassigned
            Reporter:
            thecoop1984 Simon Cooper
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: