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

Optimize $size + ExpressionFieldPath

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Query Execution

      Currently when evaluating something like {$size: '$a.b'} on a document like {a: [{b:1},{b:2}, ...]} we will first evaluate the ExpressionFieldPath which will produce an array of the values of b, then we ask for the size of that array. This is wasteful, and is even more wasteful if you consider '$a.b.c.d' where each level is an array of object since only the size of the a array matters in that case. (I'm not arguing that these semantics are good, but that is what we do today). Instead we should have an ExpressionSizeOfFieldPath that just returns the size of the top-level array that ExpressionFieldPath would create, but without making any new arrays.

      I have a profile where over 20% of the time is spent in the unnecessary ExpressionFieldPath for the simple '$a.b' case. I assume it would be even worse for '$a.b.c.d.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: