|
When a $let variable simplifies to a constant, references to that variable should simplify to a constant too. For example, in
{$match: {$expr:
|
{$let: {
|
vars: {upperBound: {$add: [2, 3]}},
|
in: {$lt: ["$field", {$add: ["$$upperBound", 10]}]}
|
}}
|
}}
|
This should simplify down to
{$match: {$expr:
|
{$lt: ["$field", 15]}
|
}}
|
which thanks to SERVER-39943 can be indexed.
Possibly this is actually 2 separate optimizations:
1. replace each occurrence of "$$upperBound" with 5
2. remove the $let expression since $$upperBound is unused
If some of the vars are constant and some are not, we can apply rule 1 but not rule 2.
|