dotnet / dotnet/efcore

Ensure that enumerable expressions are materialized early in funcletization

Open
#37,684 0 comments 0 reactions 0 assignees View on GitHub
area-perf area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Users can embed enumerable expressions inside queries:

```c#
var ids = new[] { 1, 2, 3 }.Where(i => i > 1);
_ = await context.Blogs.Where(b => ids.Contains(b.Id))...
```

This results in an IEnumerable-typed query parameter.

We then have various scenarios where we deal with such parameters. Specifically, in SqlNullabilityProcessor we enumerate IEnumerable parameters, e.g. when inlining constant/parameter lists into SQL when Contains is specified (in SqlNullabilityProcessor).

Ideally, we'd materialize these IEnumerable parameter in the earliest stage of the query pipeline - the funceltizer. Once that's done, the rest of the query pipeline can assume that everything is already materialized, and enumeration is cheap and can be done multiple times if needed (even though these would still likely be typed as IEnumerable).

One problem here is that .NET doesn't have a single (materialized) collection interface/type; collections can implement non-generic `ICollection`, generic `ICollection` and `IReadOnlyCollection`. strings incidentally implement IEnumerable but none of the collection interfaces, even though they're materialized. This makes it difficult to abstract over materialized collections and work with them.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.