Query: further improve translation of queries with Distinct or Groupby in correlated subquery, when entity identifiers are not easy to obtain
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the correlated query example named Correlated_collection_with_distinct_not_projecting_identifier_column_also_projecting_complex_expressions and compare it with the current handling of Distinct and GroupBy projections. The change is complete when complex projections such as g.OwnerFullName.Length can be used to preserve row uniqueness in the correlated subquery without requiring entity identifiers.
Written by the indexing model from the issue text.
Description
Improvement on https://github.com/dotnet/efcore/issues/22049. Currently, when we don't have access to "natural" identifiers, (so we can't inject orderby to properly bucket the results in case of correlated subquery - this can happen for GroupBy and Distinct) we try to use what we have - entire projection in case of distinct and grouping key in case of GroupBy. Those still guarantee the uniqueness of the row, so it's ok to use them. However, current limitation is that we only do this if the entire projection is made of columns - we don't do it for anything more complex, say x.Name.Length. It should be perfectly fine to use more complex projection as it still guarantees the uniqueness of the row. The reason why we have the limitation is that we didn't have an easy way to get the proper comparer for this complex expression (in case of columns we use the comparer from type mapping).
Example of the query that could work: Correlated_collection_with_distinct_not_projecting_identifier_column_also_projecting_complex_expressions
ss.Set<Gear>()
.Select(
g => new
{
Key = g.Nickname,
Subquery = g.Weapons
.Select(w => new { w.Name, w.IsAutomatic, w.OwnerFullName.Length })
.Distinct().ToList()
}
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100