Repository navigation
fix: RangeLowerBoundComparer.Compare runs in memory only in a query, on 10.x (port of #385, #396) - #446
Merged
CaffeinatedCoder merged 2 commits intoOct 25, 2026
Conversation
…385) EF Core translates any Compare(x, y) as the natural order of its operands, whatever the comparer (dotnet/efcore#39402). For a range that is the range order, so RangeLowerBoundComparer ran in SQL comparing whole ranges rather than lower bounds: with p = [2026-03-01,2026-03-10], [2026-03-01,) and [2026-03-01,2026-03-03] compared as 1 and -1 instead of 0, and Where(... Compare(r.Period, p) == 0) selected one row of three. The query interceptor now turns any IComparer<TRange>.Compare over a range or set type into RangeComparerCall.RunInMemory, which no translator knows: a filter or an ordering fails translation, and a final projection runs the comparer on the loaded rows. Once compiled the comparer is a query parameter, so a comparer typed as IComparer<TRange> (as RangeSet.LowerBoundComparer is) can't be told apart from another, and Comparer<T>.Default goes the same way; CompareTo stays the SQL range order. The TranslationSupportProbeTests candidate against #385 is removed, the inventory entry stays client with the new reason, and docs/efcore.md lists the comparer under what runs in memory. A new seed plants the defect, and compareto-null-operand-compared-as-sql-null.patch is refreshed against the new interceptor pipeline. (cherry picked from commit 284d4f8) Ported to release/10.x for #396. The changelog row goes under [10.3.0] ### Changed answers and the migration text under Changed answers in 10.3.0. Known differences in 10.2.0 now says that 10.3.0 fixes both of its entries, keeping its anchor for 10.2.0's changelog, and docs/ranges.md points to What runs where instead. The CompareTo seed is refreshed against this line's interceptor, and the #396 candidate is removed. Found-By: OT Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
Closed
Base automatically changed from
fix/395-value-set-null-operand-10.x
to
release/10.x
October 25, 2026 16:59
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 #396
Port of #385 (PR #444), cherry-picked with
-x. Was stacked on the #395 port (#445), which merged; now based onrelease/10.x.Problem
The same defect as #385, on
release/10.x: EF Core reads anyCompare(x, y)as the natural order (dotnet/efcore#39402), soRangeLowerBoundComparer.CompareandRangeSet.LowerBoundComparerran in SQL in the range order.Where(r => comparer.Compare(r.Period, p) == 0)becameWHERE r."Period" = @pand selected one row of the three memory selects. 10.2.0 named it underdocs/efcore.md#known-differences-in-1020.Change
ValueRangesQueryExpressionInterceptor+RangeComparerCall: the RangeLowerBoundComparer.Compare runs as SQL in the range order: EF Core rewrites any Compare(a, b) to the natural comparison #385 fix as it is onmain. AnyIComparer<TRange>.Compareover a range or set type becomesRangeComparerCall.RunInMemory(…), which EF Core can't translate: a filter or an ordering fails translation, a finalSelectruns the comparer in memory.Comparer<T>.Defaultis included, because a parameter-typed comparer can't be told apart;CompareTostays the SQL range order.test/oracles: theTranslationSupportProbeTestscandidate registered against 10.x: RangeLowerBoundComparer.Compare in a query runs in the range order (port of #385) #396 is removed;translation-support.jsonkeeps the memberclientwith the new reason; claimE31covers the comparer; new seedlower-bound-comparer-runs-as-sql.patch;compareto-null-operand-compared-as-sql-null.patchregenerated against this line's interceptor.docs/ranges.mdpoints to What runs where instead. A### Changed answersrow under[10.3.0]in both changelogs links 10.x: RangeLowerBoundComparer.Compare in a query runs in the range order (port of #385) #396 and Changed answers in 10.3.0, which gets the migration section frommainwith "Before 10.3.0".Tests
LowerBoundComparerQueryTests(integration) comes with it unchanged, as this line's regression test, with the fourClientSideOnlyTranslationTestsrows.EFCore.PostgreSQL.IntegrationTestssuite (304), the EF translation tests (334) and the conventions tests (420) pass.LowerBoundComparerQueryTestsfails withserver 0,1,-1,1and a filter that runs; the fourClientSideOnlyTranslationTestsrows fail;TranslationSupportProbeTestsreportsclassified client, but runs as SQL nowon every range type.dotnet run tools/oracles.cs seedscatches the new seed and the refreshed CompareTo seed on this line.🤖 Generated with Claude Code