Hello
I did a small benchmark with 8 $let
made the query 4x slower.
Seems that every nested $let
, we add makes the query 50% slower, for example i tested
also with 2 nested $let
and query took double time, which is very big difference.
[0 ... 1000] array
map 1 function, that adds 7 times the number 1
[7 8 .... 1007]
The first time i used
(+ .. (+ (+ n 1) 1))
7x
The second time i used
n1=n+ 1, n2=n1+1, n3=n2+1
7x in a nested $let
{
"$let": {"vars": {"n1": {"$add": ["$$n",1]}},
"in": { "$let": {"vars": {"n2": {"$add": [ "$$n1",1]}} ... 7x
Times were
728msec $let
180msec $add
Query became 4x slower.
I tried exactly the same in a programming language and i got zero difference, nested let didn’t cost anything.
Why $let
in MQL costs so much, and is there a way to ask for it to be fixed?
Using variables with $let
is very important, escpecially in data processing.
Thank you