Skip to content

Conversation

@rstam
Copy link
Contributor

@rstam rstam commented Mar 28, 2025

No description provided.

@rstam rstam added the improvement Optimizations or refactoring (no new features or fixes). label Mar 28, 2025
@rstam rstam requested review from adelinowona and sanych-sun March 28, 2025 18:22
@rstam rstam requested a review from a team as a code owner March 28, 2025 18:22
Copy link
Contributor

@adelinowona adelinowona left a 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.

@rstam
Copy link
Contributor Author

rstam commented Mar 31, 2025

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.

@rstam rstam requested a review from adelinowona April 1, 2025 15:18
Copy link
Contributor

@adelinowona adelinowona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@sanych-sun sanych-sun left a 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.

{
internal static class AstExpressionExtensions
{
public static bool IsConstant(this AstExpression expression, BsonValue value)
Copy link
Member

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)

Assert(query,
1,
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'} } }",
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'}, __agg1 : { $first : '$B' } } }",
Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No harm in checking how easy it would be right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's easy.

Copy link
Contributor Author

@rstam rstam Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I am finding a way to do this that is simpler than I thought.

I had originally thought we had to solver a tougher problem, which was: to look for redundancy between the various __aggx fields.

But in this particular case we can just generate a better accumulator expression in VisitFilterField.

Assert(query,
1,
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'} } }",
"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT' }, __agg1 : { $first : '$B' } } }",
Copy link
Contributor Author

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.

"{ $group: { _id: '$A', __agg0: { $first: '$$ROOT'}, __agg1 : { $first : '$B' } } }",
"{ $match: { '__agg0.B' : 'Balloon' } }",
"{ $project: { Key: '$_id', FirstB: '$__agg0.B', _id: 0 } }");
"{ $project: { Key: '$_id', FirstB: '$__agg1', _id: 0 } }");
Copy link
Contributor Author

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.

@rstam
Copy link
Contributor Author

rstam commented Apr 24, 2025

I've rebased on main now that CSHARP-5563 has been merged to main.

See the comments for a question about whether some further work is called for.

Copy link
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rstam rstam requested a review from sanych-sun April 29, 2025 00:18
Copy link
Contributor

@adelinowona adelinowona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rstam rstam merged commit 7824d76 into mongodb:main Apr 30, 2025
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Optimizations or refactoring (no new features or fixes).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants