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

Resolve ambiguity of positional projections with multiple implicit array traversal predicates in certain cases

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Querying
    • None
    • Query Optimization

    Description

      In general, if there are multiple query predicates that require implicit array traversal, the behavior of the positional projection operator is undefined. For instance, should the following projection return the zeroth or first array element?

      db.collection.drop();
      db.collection.insert({a:[{b:1},{c:1}]});
      db.collection.find({"a.b":1,"a.c":1},{"a.$":1}); // Return "a.0" element, or "a.1" element?
      

      SERVER-14662 tracks work to make such queries return an error to the user.

      However, there are cases in which this ambiguity can be resolved. Consider the following projection:

      db.collection.drop();
      db.collection.insert({a:[{b:1},{c:1}],d:[{e:1},{f:1}]});
      db.collection.find({"a.b":1,"d.f":1}, {"a.$":1});
      

      In this case, we can resolve the ambiguity because "a.$" matches the prefix of path "a.b" but does not match a prefix of path "d.f".

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            rassi J Rassi
            Votes:
            3 Vote for this issue
            Watchers:
            16 Start watching this issue

            Dates

              Created:
              Updated: