[1.9.x] Refs #10060 -- Corrected description of multiple annotations bug.
Backport of 3d2236773ba88e330841b8c72183b0e978e10909 from master
This commit is contained in:
parent
192d1eb5c3
commit
ea63cf8d42
@ -190,9 +190,8 @@ Combining multiple aggregations
|
|||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
Combining multiple aggregations with ``annotate()`` will `yield the wrong
|
Combining multiple aggregations with ``annotate()`` will `yield the wrong
|
||||||
results <https://code.djangoproject.com/ticket/10060>`_, as multiple tables are
|
results <https://code.djangoproject.com/ticket/10060>`_ because joins are used
|
||||||
cross joined. Due to the use of ``LEFT OUTER JOIN``, duplicate records will be
|
instead of subqueries:
|
||||||
generated if some of the joined tables contain more records than the others:
|
|
||||||
|
|
||||||
>>> Book.objects.first().authors.count()
|
>>> Book.objects.first().authors.count()
|
||||||
2
|
2
|
||||||
@ -374,8 +373,8 @@ Both queries return a list of publishers that have at least one book with a
|
|||||||
rating exceeding 3.0, hence publisher C is excluded.
|
rating exceeding 3.0, hence publisher C is excluded.
|
||||||
|
|
||||||
In the first query, the annotation precedes the filter, so the filter has no
|
In the first query, the annotation precedes the filter, so the filter has no
|
||||||
effect on the annotation. ``distinct=True`` is required to avoid a
|
effect on the annotation. ``distinct=True`` is required to avoid a :ref:`query
|
||||||
:ref:`cross-join bug <combining-multiple-aggregations>`.
|
bug <combining-multiple-aggregations>`.
|
||||||
|
|
||||||
The second query counts the number of books that have a rating exceeding 3.0
|
The second query counts the number of books that have a rating exceeding 3.0
|
||||||
for each publisher. The filter precedes the annotation, so the filter
|
for each publisher. The filter precedes the annotation, so the filter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user