#26434: Inconsistent results of QuerySet.count() when ordering is not a subset
of
explicit grouping.
-------------------------------------+-------------------------------------
Reporter: kamandol | Owner: Michal
| Mládek
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: postgresql queryset | Triage Stage: Ready for
count annotate aggreagate | checkin
order_by |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
> we would need to translate string aliases (order_by and extra_order_by)
to Col expressions but this may be expensive here (or at least non-
trivial).
It's not only a matter of being expensive and non trivial it simply cannot
be done in the way the ORM currently resolves `order_by` members at the
last minute. Trying to eagerly resolve `order_by`, instead of lazily at
compilation time, could break tons of queries as it would change the
`JOIN` reuse logic and produce `JOIN` left overs when `order_by` is called
to explicitly clear (the ORM doesn't have a way to elide `JOIN`s when they
are added see ticket:35865#comment:6).
It might be worth reverting and working on a solution more localized to
`get_aggregation` as it's terminal (it's the method called by `aggregate`
and thus `count`) so we know the query cannot be altered further from
there and thus we could eagerly resolve `order_by` from there.
--
Ticket URL: <https://code.djangoproject.com/ticket/26434#comment:30>
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 view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019a2b31c4d6-16018d44-928a-49ce-b94c-2b0e63904871-000000%40eu-central-1.amazonses.com.