Repository navigation
feat: translate value set Union, Add, Intersect and Except canonically for every family but text (#478) - #480
Merged
Conversation
…y for the non-text families (#478) For every family PostgreSQL sorts as memory does, the translator emits a placeholder per operation inside the NULL-over-NULL CASE, and the SQL guard builds it after EF Core's alias pass: ARRAY((SELECT DISTINCT ON (x) x FROM unnest(...) WITH ORDINALITY ... WHERE x IS NOT NULL ORDER BY x, ordinality)), or the multiset form under @>, <@, &&, IsEmpty, a null test and the outermost projection. Text keeps array_cat and the refusals (#479). Co-Authored-By: Claude Opus 5.5 <[email protected]>
#478) CanonicalSetOperationParityTests runs Union, Add, Intersect and Except over every pair of subsets of three probes for every family but text, stored canonical, out of order and twice, and with a NULL element, under ==, Count, ExecuteUpdate, the projection, containment and IsEmpty; and the copy of a value kept, for decimals by scale and floats by the sign of zero. The seed canonical-set-keeps-any-copy (a plain DISTINCT) is caught by it. CanonicalSetCompositionTests runs the compositions text still refuses, and the NULL-operand parity covers the new operations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ut text (#478) The EF guide, the value sets guide, getting started and the four package READMEs say where the operations now run, that equal values keep the first copy, what a NULL element another tool stored does, and that a wrapper's CompareTo must order as its underlying type does. AGENTS.md narrows the array_cat rule to text and adds the rule for canonical form; claims E17-E20, E35 and E75 follow, E78-E82 are new; the translation inventory and three changelogs record the change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…et rewrites (#478) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 26, 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 #478
Problem
Value set
Intersect,ExceptandAddran in memory only, and a server-sideUnionwasarray_cat, which the SQL guard allowed only under@>/<@/&&, a null test or the final projection. So equality,Count,GroupBy,Distinct,OrderBy, set operations,INandExecuteUpdateover any of them threw, for every family. The reason was text:ORDER BYsorts it by the database collation, not ordinally. For the other families PostgreSQL sorts as memory does, so canonical form can be built in plain SQL.Change
ValueSetsMethodCallTranslator): for every family with the newISetTypeDefinition.CanonicalizesInSql(all butStringSetandStringSet<T>),Union,Add,IntersectandExceptemit a placeholder function inside the existing NULL-over-NULLCASE. Text keepsarray_catand the refusals.ValueSetSqlGuard.CanonicalExpander): builds each placeholder after EF Core's alias pass, which a translator can't reach and which parses every alias as one letter and a number:ARRAY((SELECT DISTINCT ON (vrN.x) vrN.x FROM unnest(…) WITH ORDINALITY AS vrN(x) WHERE vrN.x IS NOT NULL [AND filter] ORDER BY vrN.x, vrN.ordinality)).ORDER BY x, ordinalitykeeps the first copy of each value, asValueSetCoredoes (1.0/1.00,-0/0). NULL elements another tool stored are dropped.Intersect/Exceptfilter by containment (b @> ARRAY[x]), because Npgsql'sANYnode needs an enumerable CLR type. Where order and duplicates can't change the answer (@>,<@,&&,cardinality(…) = 0, a null test, an outermost projection that neither groups nor deduplicates, and a placeholder's own operands) it writes the multiset form instead:array_cat, or the filter without sorting. The walker treats a placeholder as canonical. Without the guard the placeholders reach PostgreSQL as unknown functions, so it still fails closed.SelectExpression's immutable constructor,PgUnnestExpression,PgNewArrayExpression) have the same API on both.efcore.md(value sets,Union, rows written by other tools, what runs where),value-sets.md(a wrapper'sCompareTomust order as its underlying type does; Vogen and StronglyTypedId do),getting-started.md, the four package READMEs,architecture.md,testing.md, and AGENTS.md (thearray_catrule narrowed to text, a rule for canonical form added).translation-support.jsonreclassifiesIntersect/Except/Addas server except on text.CanonicalSetOperationParityTestsregistered with the seedcanonical-set-keeps-any-copy. The seedsql-processor-reuses-its-first-outputregenerated against the changed line.11.0.0-preview.1. The 10.x port (cherry-pick intorelease/10.x, 10.4.0) follows this merge.Tests
CanonicalSetTranslationTestsasserts the whole SQL for each form, every set column of the model (canonical for all but text, refused for text), aliases per subquery, and canonical form kept underGroupByandDistinct.NodaCanonicalSetTranslationTestscovers the five NodaTime sets and their arities.SqlGuardRegistrationTestsasserts the four placeholders reach the SQL when the processor factory is replaced. The text refusals moved toStringSet(Intersect_OnText,Except_OnText,Add_OnText,TextWrapperSets_Union_Count_FailsTranslation).CanonicalSetOperationParityTestsruns every pair of subsets of three probes for every discovered family but text, stored canonical, out of order and twice, and with a NULL element, under==,Count,ExecuteUpdate, the projection, containment andIsEmpty, against memory over the pairs as stored. Each question asserts its SQL reached the server and every row answered. It also checks the copy kept (thirty decimals a side by scale, and the sign of zero for floats) and thatAddbinds a Coptic date as the set stores it.CanonicalSetCompositionTestsruns the compositions text still refuses overInt32Set.ValueSetNullOperandParityTestscovers the four operations over a NULL operand.DISTINCT(droppingORDER BY x, ordinality) failsTheFirstCopyOfEachValue_IsKept_AsInMemory(DecimalSetandDecimalSet<Money>keep1.00where memory keeps1.0). BindingAdd's element through the provider's mapping instead of the set's failsAdd_StoresTheElementAsTheSetWould_AsInMemory.maindoes too there (2 failures), and the new tests run two families at a time and empty their pools.🤖 Generated with Claude Code