Skip to content

Use IN instead of EXISTS in more places - #31387

Merged
roji merged 3 commits into
dotnet:mainfrom
roji:MoreInExpressions
Aug 3, 2023
Merged

Use IN instead of EXISTS in more places#31387
roji merged 3 commits into
dotnet:mainfrom
roji:MoreInExpressions

Conversation

@roji

@roji roji commented Jul 31, 2023

Copy link
Copy Markdown
Member
  • 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 force-pushed the MoreInExpressions branch from 092475c to 92ae744 Compare August 1, 2023 08:26
@roji
roji force-pushed the MoreInExpressions branch from 92ae744 to 2e2664d Compare August 1, 2023 08:27
@roji
roji merged commit a1c3aba into dotnet:main Aug 3, 2023
@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

2 participants