Repository navigation
fix: follow a text set operation through a scalar subquery in the guard's rewrite (#505) - #508
Merged
Merged
Conversation
…rd's rewrite (#505) The guard's walker treats a scalar subquery that projects a text Union, Add, Intersect or Except as derived, and so lets ==, != and Count over it through, trusting the expander to write them as mutual containment and count(DISTINCT). The expander's IsDerived had no arm for a scalar subquery, so the raw = and cardinality reached the server and compared the unsorted array_cat: {a,c} ∪ {a,b} == {a,b,c} dropped the row, and (… ?? subquery).Count counted {a,c,a,b} as 4. 10.3.0 refused the query. IsDerived now judges a scalar subquery by its one projection, as the walker does. UnionCanonicalityTests runs ==, != and Count over COALESCE through a correlated scalar subquery, and Add, Intersect and Except the same way, against memory over the loaded rows; with the arm removed both new tests fail on the answer. Found-By: RV Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #505
Problem
ValueSetSqlGuarddecides in two places whether a value may be an unsorted text set, and the two disagreed on a scalar subquery.Union,Add,IntersectorExceptas derived. So it lets==,!=andCountover it through, because the expander writes those as mutual containment andcount(DISTINCT …)(Translate text value set Intersect, Except, Add, Count and equality where the result needs no order (StringSet, StringSet<T>) #485).IsDerivedhad no arm for a scalar subquery, so the raw=,<>andcardinalityreached the server and compared the unsortedarray_cat.On
{a,c},….Select(o => o.Tags.Union({a,b})).FirstOrDefault() == {a,b,c}dropped the row.(r.OptionalTags ?? subquery).Countcounted{a,c,a,b}as 4. 10.3.0 threw for the same query, so on 10.x this is a regression in the unreleased 10.4.0. It shipped in no release.Change
CanonicalExpander.IsDerivedjudges a scalar subquery by its one projection, as the walker does (ValueSetSqlGuard.cs).guard-rewrite-misses-a-scalar-subquery, caught byUnionCanonicalityTests.No changelog row: the wrong answer shipped in no release. On
main, #485's text forms are in 11.0.0-preview.1's Added, which this makes true.Tests
UnionCanonicalityTests(integration) gains two tests, each comparing the server's answer with LINQ over the loaded rows:EqualityOnAUnionFromAScalarSubquery_AnswersAsMemoryDoes:==,!=and==behind aCOALESCE, through a correlated scalar subquery, andAdd,IntersectandExceptthe same way.CountOverAUnionFromAScalarSubquery_CountsTheDistinctElements_AsMemoryDoes:Countbehind aCOALESCE.dotnet run tools/oracles.cs seeds guard-rewritereports the seed caught (2 of 17 tests fail).🤖 Generated with Claude Code