[release/8.0] Fix OPENJSON postprocessing with split query (#32978) #33027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #32976, backports #32978
Description
The SqlServerJsonPostprocessor introduced in EF 8 did not properly visit the shaper expression (in addition to the query expression), missing necessary rewriting of split queries which are stored there.
Customer impact
Split queries are an important, commonly-used EF mechanism to avoid severe performance issues (e.g. the so-called "cartesian explosion") when querying out related collections.
JSON postprocessing is a query processing step which is necessary when user queries include a JSON collection that requires ordering (or represents a collection of the SQL Server hierarchyid type). This includes any query which composes an order-sensitive operator on top of a JSON column or parameter, e.g.:
The intersection of these two things - split queries and JSON queries with order sensitivity - currently produce incorrect SQL and fail, and this is what's fixed in this PR. This intersection is likely to be not uncommon.
How found
Customer reported on 8.
Regression
No, as far as we're aware the affected scenarios weren't possible in 8.0.
Testing
Tests added.
Risk
Very low, safe one-line fix; quirk added.