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

Partial indexes should support point queries over single field ranges

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • Hide
      db.foo.ensureIndex({a:1}, {filter:{a:{$gt:5, $lt:10}}})
      db.foo.insert({a:6})
      
      Show
      db.foo.ensureIndex({a:1}, {filter:{a:{$gt:5, $lt:10}}}) db.foo.insert({a:6})
    • Quint Iteration 3

      The code only checks whether an AND-expression filter is satisfied if the query is also an AND-expression. This means that querying for an explicit value of a will not be able to use the partial index.

      > db.foo.find({a:6}).explain().queryPlanner
      {
        "plannerVersion" : 1,
        "namespace" : "test.foo",
        "indexFilterSet" : false,
        "parsedQuery" : {
          "a" : {
            "$eq" : 6
          }
        },
        "winningPlan" : {
          "stage" : "COLLSCAN",
          "filter" : {
            "a" : {
              "$eq" : 6
            }
          },
          "direction" : "forward"
        },
        "rejectedPlans" : [ ]
      }
      

      But specifying a fake AND-expression in the query will allow the partial index to be used.

      > db.foo.find({$and: [{a:6}, {a:6}]}).explain().queryPlanner
      {
        "plannerVersion" : 1,
        "namespace" : "test.foo",
        "indexFilterSet" : false,
        "parsedQuery" : {
          "$and" : [
            {
              "a" : {
                "$eq" : 6
              }
            },
            {
              "a" : {
                "$eq" : 6
              }
            }
          ]
        },
        "winningPlan" : {
          "stage" : "FETCH",
          "inputStage" : {
            "stage" : "IXSCAN",
            "keyPattern" : {
              "a" : 1
            },
            "indexName" : "a_1",
            "isMultiKey" : false,
            "indexVersion" : 1,
            "direction" : "forward",
            "indexBounds" : {
              "a" : [
                "[6.0, 6.0]"
              ]
            }
          }
        },
        "rejectedPlans" : [ ]
      }
      

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: