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

[CQF] Simplify redundant PathObj / impossible PathArr

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

      Take this $elemMatch predicate:

      {a: {$elemMatch: {b: 2, c: 3}}}
      

      It expands to this ABT:

      |   PathGet [a]
      |   PathTraverse [1]
      |   PathComposeM []
      |   |   PathComposeA []
      |   |   |   PathArr []
      |   |   PathObj []
      |   PathComposeM []
      |   |   PathGet [c] PathTraverse [1] PathCompare [Eq] Const [3]
      |   PathGet [b] PathTraverse [1] PathCompare [Eq] Const [2]
      

      The last 3 lines correspond to b: 2, c: 3. This predicate can only be true when applied to an object. So the extra PathObj / PathArr checks are redundant: we can replace them with true / false respectively.

      It's not enough to check for a PathGet however. A predicate like b: {$exists: false} can be true when applied to a non-object, because it uses PathDefault which can "catch" Nothing. Other nodes like this include PathConstant and PathLambda.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: