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

take slice or element of array before materializing it

    • Query Optimization

      When a large array has format

      a: [{b: 1}, {b: 2}, ...]
      

      and aggregation does something like

      {$slice: ["$a.b", 1, 2]}
      

      then as array "a" gets larger, materializing it into "$a.b" becomes more expensive - and just taking $slice (or $arrayElemAt) and then extracting "a.b" can be significantly faster.

      Discovered when working with very large arrays (over 10,000) and doing $slice and two $arrayElemAt operations in the same stage and having it perform 100x worse than explicitly taking slice first and then extracting b out of smaller result.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: