#26045: Annotate with conditional aggregation includes non-relevant fields in 
GROUP
BY clause
-------------------------------------+-------------------------------------
     Reporter:  mark88               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  orm, sql,            |             Triage Stage:
  annotation                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by jarshwah):

 MySQL and Postgres will optimise by grouping by all primary keys of each
 joined table, but this optimisation may not exist for queries that include
 "complex" annotations. If you don't need all of the fields from `self`,
 then prepending a `values()` clause before the annotate is how you
 restrict the group by.

 `self.get_queryset().values('pk').annotate(...)` should do what you want,
 again, if you don't need the other fields from the self model.

--
Ticket URL: <https://code.djangoproject.com/ticket/26045#comment:2>
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/064.df84d7b416d24759c2b0cde6790a6093%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to