Allow providers to customize aggregate lowering of grouped Any/All
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- backend-api-design, database
Direzione di ricerca
Start in src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs, especially TryTranslateAggregateMethodCall, TryTranslateQuantifierOverGrouping, and the grouping and predicate processing it uses. Read the grouped-quantifier implementation and the linked provider discussion to understand the proposed hook and null/empty-input semantics. Done means providers can customize grouped Any/All translation while the existing default lowering and unsupported-composition fallback remain available.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Scenario
The PostgreSQL provider would like to translate predicated Any/All over a grouping to PostgreSQL's native bool_or/bool_and aggregates, without introducing new EF.Functions APIs:
context.Items
.GroupBy(i => i.CategoryId)
.Select(g => new
{
g.Key,
Any = g.Any(i => i.Flag),
All = g.All(i => i.Flag)
});
For this unfiltered grouping over a nonnullable boolean column, the desired SQL is:
SELECT i."CategoryId", bool_or(i."Flag") AS "Any", bool_and(i."Flag") AS "All"
FROM "Items" AS i
GROUP BY i."CategoryId"
The same customization is useful when the quantifier appears in ORDER BY or HAVING, including over joined grouping sources. Provider discussion: https://github.com/npgsql/efcore.pg/issues/2394.
This is an extensibility request, not a claim that native boolean aggregates necessarily outperform EF's count-based lowering.
Extensibility gap
The grouped-quantifier lowering added in https://github.com/dotnet/efcore/pull/38937 is implemented in RelationalSqlTranslatingExpressionVisitor:
TryTranslateAggregateMethodCalldispatches groupedAny/Alldirectly toTryTranslateQuantifierOverGrouping.TryTranslateQuantifierOverGroupingis private and constructs the count-based implementation itself.- Its aggregate-translator call uses
Queryable.LongCount, not the original quantifier. Consequently, implementingAny/Allcases in a provider'sIAggregateMethodCallTranslatordoes not allow this customization. Overriding ordinaryLongCounttranslation is not a substitute: the provider needs to distinguish quantifiers from actual counts.
The outer TryTranslateAggregateMethodCall is already protected virtual, but overriding it does not let the provider reuse the existing grouping processing: TryTranslateAsEnumerableExpression is private. Reimplementing that parsing would duplicate EF's handling of grouping-element Where, Select, Distinct, ordering, and unsupported compositions.
Predicate handling also matters: RemapLambda is private and includes shared-type entity expansion, so a provider should ideally be able to reuse that processing as well, rather than just copying the parameter replacement.
Current workaround
A provider-local implementation can intercept predicated Any/All and rewrite them to private, expression-only aggregate markers:
g.Any(p) -> PrivateBoolOr(g.Select(p))
g.All(p) -> PrivateBoolAnd(g.Select(p))
Passing these expressions through the base visitor's custom-aggregate path reuses EF's grouping/filter/selector handling and reaches the provider's aggregate translator. The original operator chain is preserved, and unsupported compositions can fall back to the original quantifier translation.
This avoids copying private EF machinery, but requires synthetic methods and an expression-tree detour solely to reach an otherwise inaccessible translation stage.
Requested extensibility
Provide a protected virtual hook for grouped quantifier translation after the grouping source and quantifier predicate have been processed, but before committing to the generic LongCount lowering. The hook should expose the original quantifier, the EnumerableExpression with its existing filter, and the translated predicate, so providers can return native aggregate SQL or delegate to the default implementation.
Making the existing TryTranslateQuantifierOverGrouping protected virtual would be a useful starting point; if it continues to accept an unprocessed LambdaExpression, the predicate-remapping/translation machinery would also need to be reusable. A hook after predicate translation could avoid exposing those additional helpers.
The provider would remain responsible for its native aggregate's null/empty-input semantics, while retaining EF's existing predicate-free Any() behavior and unsupported-composition fallback. For example, filtered Any must return false on empty input, filtered All must return true, and SQL NULL predicate results must not simply be ignored by bool_and.
- Lingua principale
- C#
- Stelle
- 14.8k
- Fork
- 3.4k
- Merge medio
- 3g 18h
- PR unite (30g)
- 159
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dotnet/efcore
-
customer-reported
Difficoltà 4/5 3-5 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 2 giorni
-
Regression in 11.0: replacing an owned instance or re-adding an entity with the same key sets unchanged OnAdd properties to nullForse già presa @seragAhmed l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
dotnet/efcore#39617 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
customer-reported
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di dotnet/efcore
Issue simili
-
bug emitter:client:csharp
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
microsoft/typespec#12572 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
needs-area-label
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-networking
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/aspnetcore#70545 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno