Repository navigation
feat: translate Contains over a captured collection of ranges - #77
Merged
Merged
Conversation
wanted.Contains(r.Tags) over a captured list, array or IEnumerable of value sets went out as one array parameter (r."Tags" = ANY (@wanted)). A value set is already an array, so that parameter is an array of arrays, which PostgreSQL does not have, and Npgsql threw InvalidCastException writing T[][] for every family. The query interceptor now switches such a parameter to EF Core's MultipleParameters mode: one parameter per set, so Contains runs as IN (@p1, @p2, ...) and Any/Count read from VALUES. Equality of canonical arrays is set equality, so the rows match the in-memory answer. Only a collection whose effective mode is Parameter is changed; Constant and EF.Constant keep their literals. EF.Parameter(wanted), which asks for the impossible single parameter, throws in translation and says to remove it. A server-side Union stays refused under IN by ValueSetSqlGuard. Closes #46 Found-By: RV Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
wanted.Contains(r.Seats) over a captured list, array or IEnumerable of ranges went out as one parameter, r."Seats" = ANY (@wanted). Npgsql received an untyped NpgsqlRange<T>[] and inferred it as a multirange, so PostgreSQL failed with 42809 (op ANY/ALL (array) requires array on right side), and the custom timerange threw InvalidCastException. The interceptor's collection expander from #46 now covers ranges too: a captured range collection that a Contains reads is sent one parameter per range, IN (@p1, @p2, ...), each typed by the range's own mapping. EF.Parameter(wanted) as the source of Contains throws in translation and says to remove it. RangeSet collections already bound as one multirange array and are left alone. Any/Count over a range collection with no Contains ran before, through unnest of the multirange-typed parameter, which merges overlapping ranges and drops empty ones. Switching those would change an answer, so they are left as they are and filed as #76 for 10.0.0. Closes #71 Found-By: CA Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 17, 2026
CaffeinatedCoder
added a commit
that referenced
this pull request
Oct 17, 2026
CapturedCollectionProbeTests (integration) adds the captured collection to the EF Core operand-position axis. It reads every discovered range and value set type through: - a captured array, List, HashSet and IEnumerable - six lists that tell a list from the multirange it would collapse into (empty, overlapping, adjacent, with an empty value, duplicate, every shape) - Contains, Any and Count, alone and beside a Contains that reads the same collection The oracle is the same projection compiled and run over the rows as loaded. The lists hold loaded values, so the store's microsecond truncation does not count as a disagreement. Two families, registered as candidates: - #76, measured wider: a range collection that no Contains reads also fails loudly. Any(==) is rewritten to = ANY and fails with 42809, and timerange cannot be written at all. - #137 (new): Any/Count with a predicate over an empty collection throws "Empty collections are not supported as inline query roots". It affects every value set type, and ranges beside Contains. The sweep is registered in oracles.json and named in the heldBy of E36 and E37. It is seeded with set-collection-sent-as-one-parameter (the #46 defect), which tools/oracles.cs reports CAUGHT. Reverting #77 fails it too (42809 on every Contains). axes.md gains the value. It runs in about 5 seconds. Closes #136 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #71
Stacked on #75. This branch is cut from #75's branch (
fix/list-contains-value-set) because it extends the query interceptor code #75 adds. Until #75 merges, this PR also shows #75's commit (d076560). Only69bdcaais new here.Problem
wanted.Contains(r.Seats)over a captured collection of ranges failed for every range family. The full matrix is in the issue comment.TimeRangefailed withInvalidCastExceptioninstead. Npgsql receives the collection as an untypedNpgsqlRange<T>[]and infers it as a multirange. Measured directly:pg_typeof($1)isint4multirange, andint4range[]onceDataTypeNameis set.timerangehas no inferred type at all. A constant list,EF.Constantand an inlinenew[] { … }already worked, and so did a collection ofRangeSetvalues.Change
IN (@p1, @p2, …). Each parameter is typed by the range's own mapping, so the customtimerangeworks as well. This is the SQL the constant and inline forms already produce.int4range[]? That would need two Npgsql-internal types (NpgsqlArrayTypeMapping,INpgsqlTypeMapping), and it still couldn't nametimerange.EF.Parameter(wanted).Contains(…)over ranges now throws in translation and says to remove it.Containsin the query reads it. The revert proof showed thatAny/Countalone over a captured range list ran before, throughunnestof the multirange-typed parameter. That path merges overlapping ranges and drops empty ones, so it is silently wrong (measured:Count(Overlaps)1 where memory says 2,Any(IsEmpty)false where memory says true). Switching it would change an existing answer, so under the release rule it is filed as Any/Count over a captured list of ranges silently merge overlapping ranges and drop empty ones #76 (silent, 10.0.0), and the fix there is to drop this limit. The docs give theEF.Constantworkaround, and a live test checks it.E37andE38are intest/oracles/claims.json. The### Addedlines are in the root and EF Core changelogs. No candidate was keyed to list.Contains(rangeColumn) fails with 42809 'op ANY/ALL (array) requires array on right side' #71.Tests
RangeCollectionTranslationTests(no database) checks the wholeWHEREclause for:timerange;NOT IN;Anybeside aContains(VALUES) andAnyalone (unchangedunnest);EF.Parameterrefusal, andEF.ParameterwithAnyalone (unchanged);EF.Constant, and aRangeSetcollection (unchanged= ANY).RangeCollectionContainsTests(live PostgreSQL) covers all 11 range families: six BCL ranges,TimeRangeand four NodaTime ranges. Each runs as an array, aListand anIEnumerable, with its negation, against the in-memory answer. Equal ranges are built differently:[1,6)against[1,5], another decimal scale, another offset. It also runs the issue's query, an empty list,Contains+Countover overlapping ranges, theEF.Constantworkaround, theEF.Parameterrefusal and the unchangedRangeSetcollection.42809and theEF.Parametertest catchingPostgresException.Contains-only limit failsAnyAlone_OverACapturedList_IsUnchangedandAnyAlone_OverEFParameter_IsUnchanged, so the 9.1.0 scope is guarded.dotnet teston the whole solution, integration included: green.🤖 Generated with Claude Code