Repository navigation
fix: Any and Count over an empty captured collection read no rows instead of throwing - #170
Merged
Merged
Conversation
…tead of throwing
Any or Count with a predicate over an empty captured collection of value
sets — or of ranges beside a Contains — threw InvalidOperationException
("Empty collections are not supported as inline query roots") at translation,
where memory answers false and 0. The plugin sends such a collection one
parameter per element, EF Core expands that parameter into VALUES rows in its
parameter-based processing, and its SQL generator refuses a VALUES with none.
EmptyCollectionRewriter runs after the provider's processing, from the
decorated parameter-based processor factory: a SELECT whose table list holds a
VALUES with no rows gets one row of typed NULLs in its place and FALSE on its
WHERE, so it reads no rows — EXISTS is false, count(*) is 0, All is true. The
column types come from the columns referencing the VALUES alias in the same
SELECT, so the row is (VALUES (NULL::int4range)) and every operator on it
types. EF Core has already disabled SQL caching when it read the collection,
so a later execution with elements is generated afresh. Placed before the #76
fix on purpose: switching every range collection to one parameter per range
would otherwise turn an empty range list from a correct answer into this
exception.
With the rewriter call removed, the three new translation tests and the two
new executed tests fail with EF Core's message and CapturedCollectionProbeTests
reports 176 such lines; its #137 candidate is removed.
Closes #137
Found-By: OT
Defect-Class: SQL
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…column A collection of some other type that a context configured for MultipleParameters sends the same way keeps EF Core's own behaviour: the plugin did not put it on this path, so it does not change what it answers. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This was referenced Oct 18, 2026
…captured-collection # Conflicts: # test/oracles/candidates.json
Base automatically changed from
fix/date-extremes-adjacency-divergence
to
main
October 18, 2026 14:21
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 #137
Stacked on #169 (
fix/date-extremes-adjacency-divergence) → #168 → #167: merge those first, then retarget this tomain. It is placed before the #76 fix on purpose: #76 switches every captured range collection to one parameter per range, which would have turned an empty range list from a correct answer into this exception, so the empty case has to read no rows first.Problem
AnyorCountwith a predicate over an empty captured collection threwInvalidOperationException: Empty collections are not supported as inline query rootsat translation, for every value set type wherever the collection was used and for every range type beside aContains. Memory returnsfalseand0. The plugin sends such a collection one parameter per element (ParameterTranslationMode.MultipleParameters), EF Core expands the parameter intoVALUESrows in its parameter-based processing, and its SQL generator refuses to write aVALUESwith no rows.Change
src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/EmptyCollectionRewriter.cs(new): after the provider's parameter-based processing, aSELECTwhose table list holds aVALUESwith no rows gets one row of typedNULLs in its place andFALSEon itsWHERE, so it reads no rows:EXISTSis false,count(*)is 0,Allis true. The column types come from the columns that reference theVALUESalias in the sameSELECT, so the row is(VALUES (NULL::int4range))and every operator on it types; EF Core folds the predicate toWHERE FALSE. Only aVALUESwhose referenced column is a registered range or value set type is rewritten; a collection of another type that a context inMultipleParametersmode sends the same way keeps EF Core's own behaviour. It works on the SQL tree, so it holds for every collection form and every LINQ shape that ends in aVALUESroot, and EF Core has already disabled SQL caching when it read the collection, so a later execution with elements is generated afresh.ValueRangesParameterBasedSqlProcessorFactory: runs the rewriter beforeValueSetSqlGuardon the processor's result.test/oracles/candidates.json: the Any/Count over an empty captured collection of value sets (or of ranges beside Contains) throws 'Empty collections are not supported as inline query roots' #137 row removed.docs/efcore.md(list of sets, Good to know): an empty list matches nothing.CHANGELOG.md,src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md: the 10.0.0 Fixed row.Tests
SetCollectionTranslationTests.Any_OverAnEmptyCapturedList_ReadsNoRowsandCount_OverAnEmptyCapturedList_ReadsNoRows,RangeCollectionTranslationTests.AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows: the SQL,… FROM (VALUES (NULL::text[])) AS w("Value") WHERE FALSE.SetCollectionContainsTests.AnEmptyCollection_AnyAndCountAnswerAsInMemory(alsoAll) andRangeCollectionContainsTests.AnEmptyCollectionBesideContains_AnyAndCountAnswerAsInMemory, executed against PostgreSQL.CapturedCollectionProbeTestspasses with the Any/Count over an empty captured collection of value sets (or of ranges beside Contains) throws 'Empty collections are not supported as inline query roots' #137 candidate gone, so every empty-list row of every discovered type and collection form now agrees with memory.Empty collections are not supported as inline query roots, and the probe reports 176 such lines.🤖 Generated with Claude Code