Repository navigation
feat: translate Clamp on Int32Range, Int64Range and DecimalRange (#406) - #440
Merged
Merged
Conversation
Clamp(value) ran in memory only. On the three types whose bounds read as
memory's it now runs as SQL with memory's answers:
CASE WHEN x IS NULL OR v IS NULL OR isempty(x) THEN NULL
ELSE LEAST(GREATEST(v, lower(x)), <upper>) END
where <upper> is the bound UpperBound() reads: upper(x) - 1 on int4range and
int8range, whose stored upper bound is exclusive, and upper(x) on numrange,
where memory returns an exclusive bound as it is. GREATEST and LEAST skip the
NULL an unbounded side gives, so a NULL range or value is tested first and
answers NULL (rule (c)). Measured on PostgreSQL 16, the extremes included.
Clamp on the other range types stays in memory. ClampParityTests holds every
condition on #408's parity list; translation-support.json classifies the
three closed types server through its except map, and the docs move the row.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
Merged
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 #406
The second addition of 10.3.0 (#408).
mainfirst, then cherry-picked intorelease/10.x.Problem
Clamp(value)ran in memory only, so a query couldn't filter or order by a clamped value. #402 showed the old reason ("aCASEper shape") was overstated:GREATESTandLEASTskip NULL, so an unbounded side needs no branch.Change
ValueRangesMethodCallTranslatortranslatesRangeExtensions.Clamp, matched by itsMethodInfo, onInt32Range,Int64RangeandDecimalRange. On every other range type it declines, so those still run in memory:<upper>is the boundUpperBound()already reads:upper(x) - 1onint4range/int8range, whose stored upper bound is exclusive, andupper(x)onnumrange. There memory returns an exclusive bound as it is.GREATESTandLEASTskip the NULL that an unbounded side gives. They would also skip a NULL range or value, so both are tested first and the answer is NULL (rule (c)). EF Core drops those tests where the column is required or the value can't be NULL.DecimalRange'sNormalizeElementis the identity, so memory sees the value as given.numerickeeps the stored scale (2.500), whichdecimalequality ignores.Measured on PostgreSQL 16 before writing it:
(0,5](stored[1,6)) clamps 0 to 1;[-2147483648,2147483646]clampsint.MaxValueto 2147483646, andint8range's extremes clamp the same way;numrangereturns an exclusive bound;Docs:
docs/efcore.md#what-runs-wheremovesClampon the three types to "Runs as SQL" and adds a "Good to know" bullet (claim E74). The in-memory row for the other types now says only what is known: the same form would apply, but it has been checked against memory on these three only. docs: the in-memory reasons overstate what PostgreSQL lacks, and the Shift/Expand one is stale since #224 #402 gave no measured reason for the temporal or float types, so I didn't invent one.docs/ranges.mdand the EF Core README follow.Inventory and claims:
translation-support.jsonkeepsRangeExtensions.Clamp(*asclient, with anexceptmap making the three closed typesserver. Claim E31 now saysClampstays in memory on the other types.Changelogs:
### Addedunder[11.0.0-preview.1], in the root and EF Core changelogs.Client-only tests:
ClientSideOnlyTranslationTestsandClientSideOnlyProjectionTestsusedSeats.Clampas their in-memory example. They now usePeriod.Clamp(DateRange).Tests
ClampTranslationTests(no database): the SQL for a constant onInt32Range, a nullable value onInt64Range(itsIS NULLtest kept), and a column onDecimalRange.ClampParityTests(integration, registered as an oracle with the seedclamp-reads-the-stored-exclusive-upper-bound.patch) covers Epic: 10.3.0 #408's parity list against memory over the loaded rows:numrangebounds, and the element types' minimum and maximum against the widest storable ranges..Value, and a missing outer-join child on either side.Where(== null),Where(!= null)and a finalSelect. Each predicate (equality with the value, comparisons, a compound one, a coalesce) inWhere,Where(!)andSelect, throughCompositionRunner.Judge, which also checks that the filter and the projection agree.OrderByandOrderByDescending, with NULL where PostgreSQL puts it.DateRange, whoseClampstays in memory, so they don't reach these three.Clamparm removed, the 3 translation tests fail, and every parity call is "Untranslated".isemptyguard fails it with a NULL range clamping to the value ("server 5" where rule (c) answers NULL).TranslationSupportProbeTestspasses with the three typesserverand the restclient.TranslatorDispatchSweepTestspasses.🤖 Generated with Claude Code