[release/8.x] Produce uncorrelated IN for Contains with nullable item (#32575) #32764
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 #32574, backports #32575
Description
As a result of the primitive collections changes in 8.0, when Contains is used with a nullable item over a parameterized list, a correlated EXISTS subquery is generated in the SQL. This changes the SQL to contain an uncorrelated IN subquery instead.
Customer impact
The correlated subquery can be the cause of very serious perf regressions; for example, one user reported that a query that previously completed in milliseconds now times out.
How found
Customer reported on 8.
Regression
Yes, considerable perf regression from 7.
Testing
The new SQL is asserted in tests.
Risk
Medium, the change has been quirked.