-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unneeded columns in the projection of a JOIN subquery #34516
Comments
Are you referring to the fact that the SELECT inside the INNER JOIN has all the columns, as opposed to just t2.Id and t2.IncludeInSalesLevel? SELECT SUM(t0.Quantity)
FROM tOrderDetails AS t0
INNER JOIN
(
SELECT t2.Id, t2.Code, t2.CreatedBy, t2.CreatedDate, t2.IncludeInSalesLevel, t2.IsDeleted, t2.LastModifiedBy, t2.LastModifiedDate, t2.Name
. FROM tProduct AS t2
WHERE Not(t2.IsDeleted)
) AS t1 ON t0.ProductId == t1.Id
WHERE (Not(t0.IsDeleted) && ((t.Id != NULL) && (t.Id == t0.OrderId))) && (t1.IncludeInSalesLevel == CAST(1 AS bit))) AS total If so, that projected column list can indeed be cleaned up, but those columns aren't "loaded" in any real sense - they're not referenced or projected out of the actual query, so there's little chance they affect actual performance in any way. Do you have any indication that these extra columns are a problem? Otherwise, I'll keep this as a SQL cleanup issue. |
Yes that correct, they are not "loaded". I believe cleaning up the query would resolve this issue. |
@zulander1 can you please check this with the latest 9.0 preview (9.0.0-preview.7)? I've done some work in 9.0 to prune unneeded columns, and there's a good chance this is already taken care of... |
@roji you are right, it looks like it is resolved ! Thank you! SELECT TOP(1) (
SELECT COALESCE(SUM([t0].[Quantity]), 0)
FROM [tOrderDetails] AS [t0]
INNER JOIN (
SELECT [t1].[Id], [t1].[IncludeInSalesLevel]
FROM [tProduct] AS [t1]
WHERE [t1].[IsDeleted] = CAST(0 AS bit)
) AS [t2] ON [t0].[ProductId] = [t2].[Id]
WHERE [t0].[IsDeleted] = CAST(0 AS bit) AND [t].[Id] = [t0].[OrderId] AND [t2].[IncludeInSalesLevel] = CAST(1 AS bit)) AS [total]
FROM [tOrder] AS [t]
WHERE [t].[IsDeleted] = CAST(0 AS bit) |
Great, thanks for confirming! |
Duplicate of #31083 |
When running the query, EF is loading all the fields from the Product table,
Generated SQL:
Db context:
using version:
Microsoft.EntityFrameworkCore Version="8.0.8"
Microsoft.EntityFrameworkCore.SqlServer Version="8.0.8"
The text was updated successfully, but these errors were encountered: