Repository navigation
feat: translate RangeSet.Count as a counted unnest of the multirange (#484) - #491
Merged
Merged
Conversation
…484) RangeSet.Count ran in memory only: PostgreSQL has no multirange cardinality function, and #94's spike found a member translator can't build the subquery (no alias manager). #478 showed the way: the member translator emits a placeholder, and MultirangeCount builds (SELECT count(*)::int FROM unnest(x) AS vcN(r)) after EF Core's alias pass, from the same decorated processor as ValueSetSqlGuard, so it fails closed too. count(*) over unnest(NULL) is 0, so the placeholder sits inside CASE WHEN x IS NULL THEN NULL, which EF Core folds away for a required column. RangeSetCountParityTests measures every range type. A stored multirange counts as memory counts it, the extremes included. One the server computes from an operand at the element type's extreme can hold a range memory reads as empty, (,-2147483648) or (infinity,), the documented domain boundary; those rows are set aside and counted, and docs/efcore.md says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or seed (#484) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 26, 2026
Closed
# Conflicts: # src/CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime/CHANGELOG.md # test/oracles/claims.json
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 #484
Problem
RangeSet.Countran in memory only.bookings.Where(b => b.Blocked.Count > 2)("how fragmented is this availability?") failed translation, and a projection loaded the multirange to count it. #94's spike found why: PostgreSQL has no multirange cardinality function, and a member translator can't build the subquery, because it has no alias manager.Change
ValueRangesMemberTranslator:Counton aRangeSet<TRange, T>emits the placeholdervalueranges_multirange_count_without_sql_guard(x), insideCASE WHEN x IS NULL THEN NULL.count(*)overunnest(NULL)is 0, not NULL (measured on 16 and 18). EF Core folds the test away for a required column.MultirangeCount(new): builds(SELECT count(*)::int FROM unnest(x) AS vcN(r))after EF Core's alias pass, run byValueRangesParameterBasedSqlProcessorFactorynext toValueSetSqlGuard, as Translate value set Intersect, Except, Add and a canonical Union for the non-text families with composed SQL #478 builds its subqueries. ThevcNaliases collide neither with EF Core's nor with the guard'svrN. It fails closed: without the decorator, PostgreSQL rejects the placeholder.(,-2147483648)belowint.MinValue,(infinity,)past the last date. It can also keep apart two date ranges that memory merges across the extreme. That's the existing boundary indocs/architecture.md#domain-width-and-the-boundary, whichIsEmpty()over the same result shares;Countmakes it visible.docs/efcore.mdnow says so in Good to know.ranges.md. Changelogs: root, EF Core, EF Core NodaTime.translation-support.json:RangeSet<TRange, T>.Countis nowserver.postgres-surface.json:unnest(anymultirange)now namesRangeSet.Countand its asserted SQL.ranges.md.RangeSetCountParityTestsis registered, with the new seedrangeset-count-of-a-null-multirange-is-zero.sql-processor-reuses-its-first-output.patchis refreshed for the newProcessbody.Out of scope, as #484 says: the indexer (memory throws past the end, SQL gives NULL), and
Any/All/SelectMany, which stay on #94. The LINQ methodCount()still fails translation loudly; the property is what anIReadOnlyListexposes.Tests
RangeSetCountParityTests(integration, new). For each of the 13 range types: multiranges built from ranges that include the extremes, alone and in pairs and triples that overlap, touch or stand apart. Run throughCompositionRunner.Judge: the column, a NULL column,Union,Except,Intersect,Complement(),Gaps(), two predicates and both orderings. Computed calls skip operands at the extremes, and the test reports how many (int4: 93 of 193).EveryRangeType_HasACountParityTestfails for a range type added without one.RangeSetCountTranslationTests(no database): the subquery in a filter, one alias per subquery, a computed multirange, and theCASEover a nullable column.SqlGuardRegistrationTests.AReplacedProcessorFactory_SendsTheCountPlaceholdercovers failing closed.tools/oracles.cs seeds rangeset-count-of-a-null-multirange-is-zero). The refreshed processor seed is still caught byRepeatedExecutionProbeTests.MSTest.Parallelize.Workers=4locally, see feat: translate Clamp on every range type (#486) #490).This and #490 both add claims after E82 and lines to the same changelog sections, so whichever merges second needs a rebase.
🤖 Generated with Claude Code