Skip to content

fix: value set Union and Remove over a NULL operand are NULL in a query (#360) - #443

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/360-value-set-null-operand
Oct 25, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/360-value-set-null-operand

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #360

Problem

A value set Union (array_cat) and Remove (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}, and array_remove('{a}', NULL) is {a}. So for a NULL set (a nullable column, a missing outer-join child, a null parameter) or a NULL element, Where(v == null) selected the row while Select(v) loaded the other operand. IsEmpty and Count on the result answered for the other operand too. The composition sweeps had 24 candidates registered against #360.

Change

  • ValueSetsMethodCallTranslator: Union and Remove become CASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE f(a, b) END, following Clamp'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 extra IS NOT NULL). ValueSetSqlGuard still sees the placeholder and follows the union through the CASE; no change there.
  • test/oracles/candidates.json: the 24 #360 entries are removed (each reported candidate fixed).
  • New ValueSetNullOperandParityTests (integration), built on CompositionRunner.Judge: Union and Remove over a NULL set column, a NULL element column, a captured null and 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, CASE for nullable ones. Registered in oracles.json, with the seed value-set-union-and-remove-declared-strict.patch, and claim E75 holds the new docs/efcore.md bullet. The class is written to cherry-pick onto release/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 has CompositionRunner.
  • Docs: a Good to know bullet in Store a value set in an array column, a ### Breaking line under [11.0.0-preview.1] in the root and EF Core changelogs, and a migration section Check value set Union and Remove over NULL in queries with a workaround ((b.MaybeTags ?? StringSet.Empty).Union(more)) that the parity test runs.

Tests

  • With the fix, on PostgreSQL 16: the full EFCore.PostgreSQL.IntegrationTests suite passes (312), as do the EF translation tests (318) and the conventions tests (417).
  • With only the source change reverted, ValueSetNullOperandParityTests fails for the expected reason, e.g. r.MaybeTags.Union(@{z}) Select, row 1: server {z}, rule (c) NULL and partition … Where(== null) selects it, … Select {z}, on every NULL route for both Union and Remove. DeclaredNullabilityTests, OuterJoinProbeTests, NullableOperandPairProbeTests and RepeatedExecutionProbeTests fail with the disagreements the removed candidates covered. The seed plants the same defect and names those five oracles.

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference labels Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 3296a96 into main Oct 25, 2026
14 of 16 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/360-value-set-null-operand branch October 25, 2026 16:50
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 found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value set Union is declared NULL only for a NULL operand, but array_cat isn't strict: a filter and a projection disagree on a NULL column

1 participant