Skip to content

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

@roji

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.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions