Skip to content

Use IN instead of EXISTS with ExecuteDelete and entity containment #31386

Description

@roji

When the base query is complex and can't be natively translated to DELETE, we fall back to placing it in a subquery and deleting all rows where the IDs match. For example, we currently generate:

DELETE FROM [o]
FROM [Order Details] AS [o]
WHERE EXISTS (
    SELECT 1
    FROM [Order Details] AS [o0]
    WHERE [o0].[OrderID] < 10300 AND [o0].[OrderID] = [o].[OrderID] AND [o0].[ProductID] = [o].[ProductID])

As we've seen in #30955, doing the same thing with IN can be far more efficient.

Activity

  1. self-assigned this
    on Jul 31, 2023
  2. added 2 commits that reference this issue on Jul 31, 2023
    092475c
    0cbba5c
  3. changed the title [-]Use IN instead of EXISTS with ExecuteUpdate/Delete[/-] [+]Use IN instead of EXISTS with Delete[/+] on Aug 1, 2023
  4. changed the title [-]Use IN instead of EXISTS with Delete[/-] [+]Use IN instead of EXISTS with ExecuteDelete and entity containment[/+] on Aug 1, 2023
  5. added this to the 8.0.0 milestone on Aug 2, 2023
  6. added a commit that references this issue on Aug 3, 2023
    a1c3aba
  7. modified the milestones: 8.0.0, on Aug 19, 2023
  8. modified the milestones: , 8.0.0 on Nov 14, 2023
  9. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions