Skip to content
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

Use IN instead of EXISTS in more places #31387

Merged
merged 3 commits into from
Aug 3, 2023
Merged

Conversation

roji
Copy link
Member

@roji roji commented Jul 31, 2023

  • First, this optimizes to use IN syntax instead of EXISTS for entity equality/containment e.g. (context.Blogs.Where(b => ctx.BlogsDetails.Contains(b.Details))) - when the entity has a non-composite key (composite keys are still translate via EXISTS). This improves on #30955, which already switched most queries from IN to EXISTS where possible, but not for entity equality/containment.
  • It then leverages this and switches to using Contains in ExecuteDelete. This form comes into use for complex querying which cannot be directly translated to DELETE; we then add a WHERE clause that checks whether the row's PK is in a subquery containing the complex conditions.
  • Note that ExecuteUpdate generated an inner join instead of IN/EXISTS. This is because unlike with delete, update supports arbitrary projections (e.g. into anonymous types), and that's tricky to get working with IN/EXISTS. The inner join approach should be just as efficient - if a tad uglier - so I'm leaving as-is for now.

Closes #31386

@roji roji requested a review from a team July 31, 2023 23:46
@roji roji merged commit a1c3aba into dotnet:main Aug 3, 2023
7 checks passed
@roji roji deleted the MoreInExpressions branch August 3, 2023 06:00
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.

Use IN instead of EXISTS with ExecuteDelete and entity containment
2 participants