[SERVER-41383] $merge should resolve 'let' variables only if they're referenced in the update pipeline Created: 30/May/19  Updated: 19/Jan/23

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

Type: Improvement Priority: Major - P3
Reporter: Anton Korshunov Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

Currently, if a $merge stage has the 'let' variables defined, but they're not referenced in the update pipeline, we will still resolve those variables and will pass it down to the update system, even though they're not needed. We also have a default variable `$$new` which is resolved to the entire input document if the user omitted the `let` argument. To maximize performance and reduce the stress on update throughput, we should perform an introspection of the update pipeline when creating a $merge stage and remove all `let' variables which are not used in the update pipeline.

We can also prevent shipping out runtime constants (such as $$NOW and $$CLUSTER_TIME) with every update request if they're also not used in the update pipeline or `let` variables.


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