Opened 5 years ago

Closed 5 years ago

#30262 closed Cleanup/optimization (duplicate)

Do not create GROUP BY clause expressions for Subqueries

Reported by: Paul Wayper Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: group by
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A Subquery in an annotation on a queryset can contains its own aggregate functions (e.g. COUNT) on the subquery's fields. However, these subqueries do not need to be included as GROUP BY clauses in the original query.

Change History (2)

comment:1 by Paul Wayper, 5 years ago

I've written a patch to do this:

https://github.com/django/django/pull/11092

Let me know what you think!

comment:2 by Simon Charette, 5 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #30099 which is fixed in the upcoming 2.2 release.

The GROUP BY subquery annotation trimming on aggregation optimization is tracked in #30158.

Note: See TracTickets for help on using tickets.
Back to Top