Query: unnecessary APPLY generated where JOIN is enough is some cases
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Example:
Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer
```sql
SELECT [l].[Id], [t].[Id], [t0].[Name], [t0].[Id], [t].[c]
FROM [LevelOne] AS [l]
OUTER APPLY (
SELECT TOP(1) 1 AS [c], [l0].[Id]
FROM [LevelTwo] AS [l0]
WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL
) AS [t]
OUTER APPLY (
SELECT [l1].[Name], [l1].[Id]
FROM [LevelOne] AS [l1]
WHERE EXISTS (
SELECT 1
FROM [LevelTwo] AS [l2]
WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t].[Id])
) AS [t0]
ORDER BY [l].[Id], [t].[Id]
```
very minor issue, but we should at some point investigate and clean up this
Contributor guide
Assessment
This issue has not been assessed yet.