dotnet / dotnet/efcore

Remove unneeded query root table when it's not needed in the query

Open
#33,946 0 comments 0 reactions 0 assignees View on GitHub
area-bulkupdate area-perf area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

For example, test Replace_ColumnExpression_in_column_setter:

```c#
await ss.Set()
.SelectMany(e => e.OwnedCollections)
.ExecuteUpdateAsync(s => s.SetProperty(o => o.Value, "SomeValue"))
```

... produces the following SQL:

```sql
UPDATE [o0]
SET [o0].[Value] = N'SomeValue'
FROM [Owner] AS [o]
INNER JOIN [OwnedCollection] AS [o0] ON [o].[Id] = [o0].[OwnerId]
```

The SQL is overly-convoluted: it starts with the Owner table (since that's the query root in the LINQ query), although there's no need to reference that table at all in this query (this is because no OwnedCollections can ever exist without them having an Owner).

It's unclear at this point whether this is somehow specific to bulk updates, or a general query issue related to SelectMany(), etc.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.