Skip to content

Prune SQL Server OPENJSON's WITH clause#32673

Merged
roji merged 1 commit intodotnet:mainfrom
roji:PruneOpenJson
Dec 30, 2023
Merged

Prune SQL Server OPENJSON's WITH clause#32673
roji merged 1 commit intodotnet:mainfrom
roji:PruneOpenJson

Conversation

@roji
Copy link
Member

@roji roji commented Dec 25, 2023

This extends the new pruner (#32672, review 2nd commit only) to prune the WITH column list on OPENJSON expressions.

Closes #32668

@roji roji requested a review from a team December 25, 2023 19:25
[OwnedCollectionBranch] nvarchar(max) '$.OwnedCollectionBranch' AS JSON,
[OwnedReferenceBranch] nvarchar(max) '$.OwnedReferenceBranch' AS JSON
) AS [o]
FROM OPENJSON([j].[OwnedCollectionRoot], '$') WITH ([OwnedCollectionBranch] nvarchar(max) '$.OwnedCollectionBranch' AS JSON) AS [o]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice example: the 2nd OPENJSON down below gets its WITH clause completely trimmed away, because it's only used for COUNT(*). But its argument referenced [o].[OwnedCollectionBranch], which makes it get preserved here on the 1st OPENJSON, as the only one.

// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using ColumnInfo = Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerOpenJsonExpression.ColumnInfo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😞

Copy link
Member Author

@roji roji Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can inline and qualify with SqlServerOpenJsonExpression.ColumnInfos if you think that's better..

@roji roji force-pushed the PruneOpenJson branch 3 times, most recently from c683714 to 2992a49 Compare December 30, 2023 08:24
@roji roji merged commit 2e7ea62 into dotnet:main Dec 30, 2023
@roji roji deleted the PruneOpenJson branch December 30, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prune OPENJSON columns list

2 participants