ORDER BY in aggregate subqueries is not necessary and might cause problems on some SQL servers
Some SQL servers, like MS SQL 2005
does not allow ORDER BY
in subqueries without a TOP
modifier. (It might apply to other database servers as well.) It is also suboptimal to use ORDER BY
in the subquery of an aggregate SELECT
, since it does not affect the result.
It might be better to just clear ordering in the subquery in this case. I suggest adding the following line in the BaseQuery.get_aggregation
method before the query.add_subquery(obj)
call:
obj.clear_ordering(True)
Patch against the db\models\sql\query.py
file of the 1.1 release version has been attached.
Attachments
(1)
- query.py.patch
(502 bytes
) - added by egenix_viktor 15 years ago.
- Patch against db/models/sql/query.py (Django 1.1, release version)
Download all attachments as:
.zip
Change History
(12)
milestone: |
→ 1.2
|
Triage Stage: |
Unreviewed → Accepted
|
Summary: |
ORDER BY in aggregate subqueries is not necessary and might causes on some SQL servers → ORDER BY in aggregate subqueries is not necessary and might cause problems on some SQL servers
|
Component: |
Database layer (models, ORM) → ORM aggregation
|
milestone: |
1.2 → 1.3
|
Needs tests: |
set
|
Owner: |
nobody removed
|
Severity: |
→ Normal
|
Type: |
→ Bug
|
Component: |
ORM aggregation → Database layer (models, ORM)
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Resolution: |
fixed
|
Status: |
closed → new
|
Owner: |
set to Anssi Kääriäinen <akaariai@…>
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Patch against db/models/sql/query.py (Django 1.1, release version)