Skip to content

Query: Fix bug in BindPropertyToOuterParameter - #7619

Closed
tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:queries-by-source
Closed

tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:queries-by-source

Conversation

@tuespetre

Copy link
Copy Markdown
Contributor

This PR makes the following changes:

  • Makes QueriesBySource a private API to RelationalQueryModelVisitor
  • Makes Queries an IEnumerable<SelectExpression> instead of ICollection<SelectExpression>
  • Renames AddQuery to MapQuery to better align with what the method is doing

This is, again, a set of changes I am splitting out from #7543. The idea is that as the query model is being visited, each query source gets mapped to a SelectExpression so that during binding (either within SqlTranslatingExpressionVisitor or MemberAccessBindingExpressionVisitor or etc.) there will be optimal opportunity to find or add the appropriate projection expressions.

As you can see this change already has benefits outside of the context of #7543 in that it has optimized some types of N+1 queries that would otherwise pull much more data on each of the +1 queries.

@dnfclas

dnfclas commented Feb 15, 2017

Copy link
Copy Markdown

Hi @tuespetre, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@smitpatel

Copy link
Copy Markdown
Contributor

Poaching this @maumar

@smitpatel

Copy link
Copy Markdown
Contributor

The changed test SQL is an improvement here, those tests should be using parameter injection but instead they are not because of bug here
https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore.Relational/Query/RelationalQueryModelVisitor.cs#L1633

Instead of trying to find SelectExpression by asking QueriesBySource, it should use TryGetQuery method which utilizes HandlesQuerySource method on SelectExpression.

Ideally, a querymodelvisitor (qmv) should store only SelectExpression(s), which are required to be run to generate results of query model being visited. There can be more than one SelectExpression stored it they are being stitched together. That is the reason when we lift the join clause into main select expression we remove the entry for join clause in QueriesBySource. If a query source is being lifted then there should be no need to store it in QueriesBySource, instead SelectExpression.HandlesQuerySource method should tell if particular qs is part of SelectExpression.

This change brought test SQL changes because of existing bug. Instead the underlying bug should be fixed. Leaving that aside, this does not add any value rather increases the metadata size.

@smitpatel smitpatel changed the title Refactor QueriesBySource Query: Fix bug in BindPropertyToOuterParameter Feb 22, 2017

@smitpatel smitpatel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct approach would be to fix bug in BindPropertyToOuterParameter

@tuespetre

Copy link
Copy Markdown
Contributor Author

instead SelectExpression.HandlesQuerySource method should tell if particular qs is part of SelectExpression

WOW! 😱 Big 'duh' moment for me, now I am seeing all of the places where a query source is not being mapped to an added join expression or subquery select expression, and how I was using these changes to compensate for that.

@tuespetre

Copy link
Copy Markdown
Contributor Author

🆙📅

@smitpatel

Copy link
Copy Markdown
Contributor

Merged via 2a8a3b5
Thank you for contribution.

@smitpatel smitpatel closed this Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants