#26045: Annotate with conditional aggregation includes non-relevant fields in
GROUP
BY clause
----------------------------------------------+----------------------------
Reporter: mark88 | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords: orm, sql,
| annotation
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------------
I'm using Django 1.8.6 and conditional aggregates.
{{{
objects = self.get_queryset().annotate(sent_count=
Sum(
Case(When(messages__date_sent__gte=date_from, then=1)),
output_field=IntegerField()
),
error_count=
Sum(
Case(When(messages__status__iexact='error', then=1)),
output_field=IntegerField()
),
sent_yesterday=
Sum(
Case(When(messages__date_sent__gte=yesterday, then=1)),
output_field=IntegerField()
)
)
}}}
And when viewing SQL query for this annotation, I see every single field
in this model is included in GROUP BY clause, making query very slow.
There's also one field from related model included in GROUP BY. I've run
the query manually, removing all unnecessary fields from the clause and it
runs fine
--
Ticket URL: <https://code.djangoproject.com/ticket/26045>
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/049.9128d278ca7825ade4222805d993bdfc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.