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

query optimizer does not choose appropriate partial index when matching "expression" is in $elemMatch

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query
    • ALL

      Example involves index on array of key/value structures.

      db.foo.drop();
      db.foo.insert({"a":[ {"k":"x", "v":"y"},  {"k":"z", "v":1} ] })
      db.foo.createIndex({"a.k":1, "a.v":1},{partialFilterExpression:{"a.k":{$exists:true}}})
      db.foo.explain().find({"a":{$elemMatch:{"k":"x","v":"y"}}})
      // results in collection scan
      db.foo.explain().find({"a":{$elemMatch:{"k":"x","v":"y"}},"a.k":"x"})
      // does use partial index as expected, but the redundant condition should not be necessary
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: