Skip to content

fix: RangeLowerBoundComparer.Compare runs in memory only in a query, on 10.x (port of #385, #396) - #446

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/396-lower-bound-comparer-10.x
Oct 25, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/396-lower-bound-comparer-10.x

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #396

Port of #385 (PR #444), cherry-picked with -x. Was stacked on the #395 port (#445), which merged; now based on release/10.x.

Problem

The same defect as #385, on release/10.x: EF Core reads any Compare(x, y) as the natural order (dotnet/efcore#39402), so RangeLowerBoundComparer.Compare and RangeSet.LowerBoundComparer ran in SQL in the range order. Where(r => comparer.Compare(r.Period, p) == 0) became WHERE r."Period" = @p and selected one row of the three memory selects. 10.2.0 named it under docs/efcore.md#known-differences-in-1020.

Change

Tests

  • LowerBoundComparerQueryTests (integration) comes with it unchanged, as this line's regression test, with the four ClientSideOnlyTranslationTests rows.
  • On .NET 10 (SDK 10.0.402), PostgreSQL 16, on top of the 10.x: value set Union and Remove over a NULL operand project a value instead of NULL (port of #360) #395 port: the full EFCore.PostgreSQL.IntegrationTests suite (304), the EF translation tests (334) and the conventions tests (420) pass.
  • With the seed applied (the rewriter removed from the pipeline): LowerBoundComparerQueryTests fails with server 0,1,-1,1 and a filter that runs; the four ClientSideOnlyTranslationTests rows fail; TranslationSupportProbeTests reports classified client, but runs as SQL now on every range type. dotnet run tools/oracles.cs seeds catches the new seed and the refreshed CompareTo seed on this line.

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.3.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 area/ranges Range unions, variants and the shape engines package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 25, 2026
Base automatically changed from fix/395-value-set-null-operand-10.x to release/10.x October 25, 2026 16:59
@CaffeinatedCoder CaffeinatedCoder removed the stacked Base is another open PR; merge in order, CI does not run until it targets main label Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit a8ad482 into release/10.x Oct 25, 2026
10 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/396-lower-bound-comparer-10.x branch October 25, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines bug Something isn't working 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.

1 participant