Repository navigation
fix: value set Union and Remove over a NULL operand are NULL in a query (#360) - #443
Merged
Merged
Conversation
…ry (#360) array_cat and array_remove aren't strict: array_cat(NULL, '{z}') is {z} and array_remove('{a}', NULL) is {a}. Both were declared as propagating nullability, so a filter's `== null` selected the row while a projection loaded the other operand. Each call is now CASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE f(a, b) END, with the function declared as propagating nothing and never NULL (it is reached only with both operands non-NULL). EF Core folds the test away for a required column, a non-null parameter and a constant, so their SQL is the bare call. ValueSetSqlGuard follows the union through the CASE as before. ValueSetNullOperandParityTests holds it on every route to a NULL operand, registered as an oracle with a seed; the 24 candidates the composition sweeps had registered against #360 are removed. Found-By: OT Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
Closed
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 #360
Problem
A value set
Union(array_cat) andRemove(array_remove) were declared to EF Core as NULL exactly when an operand is NULL, but neither PostgreSQL function is strict:array_cat(NULL, '{z}')is{z}, andarray_remove('{a}', NULL)is{a}. So for a NULL set (a nullable column, a missing outer-join child, anullparameter) or a NULL element,Where(v == null)selected the row whileSelect(v)loaded the other operand.IsEmptyandCounton the result answered for the other operand too. The composition sweeps had 24 candidates registered against #360.Change
ValueSetsMethodCallTranslator:UnionandRemovebecomeCASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE f(a, b) END, followingClamp's pattern. The inner function is declared as propagating nothing and never NULL, since it is reached only with both operands non-NULL. EF Core folds the test away for a required column, a non-null parameter and a constant, so their SQL stays the bare call (and a predicate over it gets no extraIS NOT NULL).ValueSetSqlGuardstill sees the placeholder and follows the union through theCASE; no change there.test/oracles/candidates.json: the 24#360entries are removed (each reportedcandidate fixed).ValueSetNullOperandParityTests(integration), built onCompositionRunner.Judge:UnionandRemoveover a NULL set column, a NULL element column, a capturednulland a missing outer-join child on either side, nested, in the filters, the projection and the predicates built on them. A second test holds the SQL: bare call for required operands,CASEfor nullable ones. Registered inoracles.json, with the seedvalue-set-union-and-remove-declared-strict.patch, and claimE75holds the newdocs/efcore.mdbullet. The class is written to cherry-pick ontorelease/10.x(10.x: value set Union and Remove over a NULL operand project a value instead of NULL (port of #360) #395), which lacks the composition sweeps but hasCompositionRunner.### Breakingline under[11.0.0-preview.1]in the root and EF Core changelogs, and a migration section Check value setUnionandRemoveover NULL in queries with a workaround ((b.MaybeTags ?? StringSet.Empty).Union(more)) that the parity test runs.Tests
EFCore.PostgreSQL.IntegrationTestssuite passes (312), as do the EF translation tests (318) and the conventions tests (417).ValueSetNullOperandParityTestsfails for the expected reason, e.g.r.MaybeTags.Union(@{z}) Select, row 1: server {z}, rule (c) NULLandpartition … Where(== null) selects it, … Select {z}, on every NULL route for bothUnionandRemove.DeclaredNullabilityTests,OuterJoinProbeTests,NullableOperandPairProbeTestsandRepeatedExecutionProbeTestsfail with the disagreements the removed candidates covered. The seed plants the same defect and names those five oracles.🤖 Generated with Claude Code