Skip to content

fix: follow a text set operation through a scalar subquery in the guard's rewrite (#510, port of #505) - #514

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/510-scalar-subquery-text-set-10.x
Oct 26, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/510-scalar-subquery-text-set-10.x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #510

Port of #508 (#505) to release/10.x: both commits cherry-picked with -x, applied without conflicts.

Problem

….Select(o => o.Tags.Union(x)).FirstOrDefault() == target compared the unsorted array_cat, because the guard's expander didn't follow a scalar subquery that its walker had let through. 10.3.0 threw for that query, so this is a regression in the unreleased 10.4.0. #497's 10.4.0 changelog row already promises == and Count over a text Union, and this makes it true.

Change

The IsDerived arm, two UnionCanonicalityTests, and the seed guard-rewrite-misses-a-scalar-subquery.

No ### Changed answers row and no silent label: no release shipped the wrong answer.

Tests

  • On the EF Core 10.0.0 floor: UnionCanonicalityTests 17/17. With the seed applied, both new tests fail (15/17).
  • On the newest-patch leg (-p:EfFloat=10.0.13 -p:NpgsqlEfFloat=10.0.3): UnionCanonicalityTests 17/17.
  • Full suite on the floor, PostgreSQL 16: green.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits October 26, 2026 18:13
…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>
(cherry picked from commit 4bd2b7b)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a0209a8)
@CaffeinatedCoder CaffeinatedCoder added this to the 10.4.0 milestone Oct 26, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario labels Oct 26, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 900934e into release/10.x Oct 26, 2026
10 of 11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/510-scalar-subquery-text-set-10.x branch October 26, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/value-sets Value set families and wrapper arities bug Something isn't working package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant