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

Plan for query with negation predicates below an $elemMatch value not considered

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.0, 2.6.3
    • Fix Version/s: 2.7.5
    • Component/s: Querying
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

       
       
      db.elem.insert({arr: [ 1, 2, 3], a: {arr: [9,8,7]}, b:3 })
      db.elem.insert({arr: [ 4,5,6], a: {arr: [19,18,17]}, b:5 })
      db.elem.ensureIndex({arr:1})
      db.elem.ensureIndex({"a.arr":1})
      db.elem.ensureIndex({b:1})
      db.elem.ensureIndex({arr:1, b: 1})
      db.elem.find({b: {$gt: 3}, arr: {$elemMatch:{$gt: 5}}}).explain(true)
      db.elem.find({b: {$gt: 3}, arr: {$elemMatch:{$ne: 5}}}).explain(true)

      Show
          db.elem.insert({arr: [ 1, 2, 3], a: {arr: [9,8,7]}, b:3 }) db.elem.insert({arr: [ 4,5,6], a: {arr: [19,18,17]}, b:5 }) db.elem.ensureIndex({arr:1}) db.elem.ensureIndex({"a.arr":1}) db.elem.ensureIndex({b:1}) db.elem.ensureIndex({arr:1, b: 1}) db.elem.find({b: {$gt: 3}, arr: {$elemMatch:{$gt: 5}}}).explain(true) db.elem.find({b: {$gt: 3}, arr: {$elemMatch:{$ne: 5}}}).explain(true)

      Description

      Part of the query planner's index selection phase is to collect all paths over which the query has predicates (see the mongo::QueryPlannerIXSelect::getFields function). The implementation ignores negation predicates inside an $elemMatch value expression. The consequence is that the planner may fail to generate plans which index negation predicates inside $elemMatch value.

      Original Description

      A query containing an $elemMatch with negation predicates is not considereding all plans.

      The Plan with an index which has an array, which the query includes a $elemMatch with a negation predicate is not considered. A similar query without the negation predicate does include the Plans.

      Note that only the plan for b index is considered (see second query result from the steps)

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: