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

$expr with find() does not use an index

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization

      The following query:

       db.foo.find({$expr: {$eq: [ "$a" , 2 ]}}).explain(); 

      Does not use an index even though an apparently suitable predicate with $_internalExprEq }}has appeared in the {{parsedQuery representation :

          parsedQuery: {
            '$and': [
              {
                '$expr': { '$eq': [ '$a', { '$const': 2 } ] }
              },
              { a: { '$_internalExprEq': 2 } }
            ]
          },
       

      From my reading of https://github.com/10gen/mongo/blob/e73bcfb2ba365dced85566219e49e9ff2e4092b8/src/mongo/db/matcher/expression_internal_expr_comparison.h#L50-L70 it appears that it would be safe to use this predicate for indexing, provided that the complete original filter is then applied on top of the results returned by the index.

            Assignee:
            Unassigned Unassigned
            Reporter:
            philip.stoev@mongodb.com Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: