Repository navigation
fix: keep EF Core's _ord column an integer in the empty-root rewrite (#319) - #389
Merged
Merged
Conversation
…319) EF Core types the _ord ordering column of its empty query root like the elements, so TypeTheNulls cast it to the range type with them (NULL::int4range AS _ord). It is an integer when the list has elements, so a shape comparing it with one would fail on the server for the empty list only. Write it as 0, as OneRowOfNulls does on release/10.x. Found-By: RV Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 24, 2026
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 #319
Problem
EmptyCollectionRewritercasts everyNULLconstant of EF Core's empty query root that has a registered range or value set CLR type. EF Core types its_ordordering column the same way as the elements, so_ordwas cast to the range type too:When the list has elements,
_ordis an integer (VALUES (0, @p1), …). No answer changed: no row exists, andORDER BYover a rangeNULLis valid. But a shape comparing_ordwith an integer would fail on the server, and only for the empty list.Change
EmptyCollectionRewriter: the_ordprojection becomes0. That's an integer, as it is when the list has elements, and asOneRowOfNullswrites it onrelease/10.x. Only the element column is still cast. The class remarks say so.### Fixedrow in the root changelog and the EF Core package's changelog, under11.0.0-preview.1.Tests
RangeCollectionTranslationTests.FirstOrDefault_OverAnEmptyCapturedList_KeepsTheOrderingColumnAnIntegerpins the whole statement forempty.Where(w => w.Overlaps(b.Seats)).FirstOrDefault(). Before the fix it fails withactual: … SELECT NULL::int4range AS _ord …; with the fix it passes.RangeCollectionContainsTests,SetCollectionContainsTestsandCapturedCollectionProbeTests(28 tests).The 10.x port is #325, for 10.2.0 (#358).
🤖 Generated with Claude Code