[SERVER-28312] take slice or element of array before materializing it Created: 14/Mar/17  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: optimization, performance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

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.


Generated at Thu Feb 08 04:17:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.