Skip to content
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

Fix Contains within SQL Server aggregate functions #32478

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

roji
Copy link
Member

@roji roji commented Dec 1, 2023

This:

  • Adds tracking in SQL Server for when we're inside an aggregate method (Count, Max...). The flag was introduced on SqlServerQueryCompilationContext.
    • This maybe isn't the ideal place, because the flag is only temporary translation state, and does not apply to all of compilation.
    • But it's currently the only place shared across SqlServerQueryableMethodTranslatingExpressionVisitor and SqlServerSqlTranslatingExpressionVisitor. We can think about a better way to preserve state data across the different visitors during the translation process.
  • Then, if the flag is on and we see the new OPENJSON-based subquery translation for Contains, we convert it to the old IN+constants translations, as if the SQL Server compatibility level were too low.

One note: we could instead refrain from producing the OPENJSON translation altogether (return null from TranslatePrimitiveCollection), and let the general relational fallback produce the old IN+constants translation. But this would block simplifications that pattern-match on top of the OPENJSON translation (currently we only have TranslateElementOrDefault which does that for SQL Server).

Fixes #32374

@roji roji requested a review from maumar December 1, 2023 12:49
@roji roji force-pushed the SqlServerAggregateStuff branch from 0eefa4b to 9def3db Compare December 1, 2023 13:12
@roji roji force-pushed the SqlServerAggregateStuff branch from 9def3db to facca73 Compare December 2, 2023 09:09
@roji roji merged commit cfcdf56 into dotnet:main Dec 4, 2023
7 checks passed
@roji roji deleted the SqlServerAggregateStuff branch December 4, 2023 21:43
roji added a commit to roji/efcore that referenced this pull request Dec 7, 2023
roji added a commit to roji/efcore that referenced this pull request Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants