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

OR query does not use middle field of a compound index

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.2.8
    • Fix Version/s: None
    • Component/s: Indexing
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: