summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-12-10 05:19:27 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-12-10 05:19:27 +0000
commita1cbeb9afbbf0f16e1ffa1891575fbc2c3edae74 (patch)
treec5741e275b870b9d5decd0f5ab716497b9305a2c /tests
parent7030ab9a72ea590b359c22644e45edaf05dd8b5c (diff)
If an SQL query doesn't specify any ordering, avoid the implicit sort
that happens with MySQL when a "GROUP BY" clause is included. This is a backend-specific operation, so any other databases requiring similar encouragement can have a function added to their own backend code. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9637 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/queries/models.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 868200f60c..d8737df197 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -6,6 +6,7 @@ import datetime
import pickle
import sys
+from django.conf import settings
from django.db import models
from django.db.models.query import Q, ITER_CHUNK_SIZE
@@ -1053,3 +1054,20 @@ FieldError: Infinite loop caused by ordering.
[]
"""
+
+if settings.DATABASE_ENGINE == "mysql":
+ __test__["API_TESTS"] += """
+When grouping without specifying ordering, we add an explicit "ORDER BY NULL"
+portion in MySQL to prevent unnecessary sorting.
+
+>>> query = Tag.objects.values_list('parent_id', flat=True).order_by().query
+>>> query.group_by = ['parent_id']
+>>> sql = query.as_sql()[0]
+>>> fragment = "ORDER BY "
+>>> pos = sql.find(fragment)
+>>> sql.find(fragment, pos + 1) == -1
+True
+>>> sql.find("NULL", pos + len(fragment)) == pos + len(fragment)
+True
+
+"""