-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5529: Optimize grouping.First().X to not retrieve the entire $$ROOT #1653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but you should update the LINQ2 tests as well since the optimization changes the output. Evergreen is failing because of that.
I was wondering if that would be the case. Updating now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + minor change suggested.
@@ -19,6 +19,9 @@ namespace MongoDB.Driver.Linq.Linq3Implementation.Ast.Expressions | |||
{ | |||
internal static class AstExpressionExtensions | |||
{ | |||
public static bool IsConstant(this AstExpression expression, BsonValue value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename it to IsConstantEqualsTo
or make it return the constant's value instead:
public static bool IsConstant(this AstExpression expression, out BsonValue value)
@@ -484,9 +484,9 @@ public void GroupBy_where_select_anonymous_type_with_duplicate_accumulators_meth | |||
|
|||
Assert(query, | |||
1, | |||
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'} } }", | |||
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'}, __agg1 : { $first : '$B' } } }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could argue that __agg1
is redundant because we've already fetched the entire first $$ROOT
so we could compute { $first : "$B" }
by calling __agg0.B
client-side.
Not sure how easy this would be. Do you think it is worth working on?
@@ -511,9 +511,9 @@ where g.First().B == "Balloon" | |||
|
|||
Assert(query, | |||
1, | |||
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'} } }", | |||
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT' }, __agg1 : { $first : '$B' } } }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about __agg1
.
"{ $match: { '__agg0.B' : 'Balloon' } }", | ||
"{ $project: { Key: '$_id', FirstB: '$__agg0.B', _id: 0 } }"); | ||
"{ $project: { Key: '$_id', FirstB: '$__agg1', _id: 0 } }"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about __agg1
.
I've rebased on See the comments for a question about whether some further work is called for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.