#30158: Subquery Expressions Incorrectly Added to Group by
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: subquery, group_by | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* type: Bug => Cleanup/optimization
Comment:
Jonny, by playing a bit with the code I noticed that it's a bit more
complex than simply returning an empty list in
`Subquery.get_group_by_cols`.
Can you confirm that both queries were returning the appropriate results
but that the one where subqueries were added to the `GROUP BY` was
performing significantly slower?
If that's the case then this is more of an optimization problem where
subqueries can sometimes be removed from the `GROUP BY` and sometimes not
but not in all cases.
e.g.
{{{#!python
Publisher.objects.annotate(
has_long_books=Exists(
Book.objects.filter(
publisher=OuterRef('pk'),
pages__gt=800,
),
),
).values_list('has_long_books').annotate(
total=Count('*'),
)
}}}
When there's an explicit grouping by a subquery (or exists) then it must
be honoured but I believe in other cases it's not.
--
Ticket URL: <https://code.djangoproject.com/ticket/30158#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.c9088e8365e5e5bb3da8b9feaff82a96%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.