summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authore0ne <e0ne@e0ne.info>2013-09-08 22:57:36 +0300
committerTim Graham <timograham@gmail.com>2013-09-09 09:49:15 -0400
commit276e053803c847ce645b1859a162a997a4ee3789 (patch)
tree40b6fc0e728a91dd45332bb02cb1d18cd52c3abe
parente4274e3da1160997bc78c09ca8f634e04d7438d2 (diff)
downloaddjango-276e053803c847ce645b1859a162a997a4ee3789.tar.gz
[1.6.x] Fixed #16895 -- Warned about cost of QuerySet ordering
Thanks outofculture at gmail.com for the suggestion. Backport of cbf08c6b0c from master
-rw-r--r--docs/ref/models/options.txt6
-rw-r--r--docs/ref/models/querysets.txt6
-rw-r--r--docs/topics/db/optimization.txt11
3 files changed, 23 insertions, 0 deletions
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt
index 6413050cb7..36b3cded1f 100644
--- a/docs/ref/models/options.txt
+++ b/docs/ref/models/options.txt
@@ -216,6 +216,12 @@ Django quotes column and table names behind the scenes.
ordering = ['-pub_date', 'author']
+.. warning::
+
+ Ordering is not a free operation. Each field you add to the ordering
+ incurs a cost to your database. Each foreign key you add will
+ impliclty include all of its default orderings as well.
+
``permissions``
---------------
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index c5b835f55f..ec89eacfc4 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -336,6 +336,12 @@ You can tell if a query is ordered or not by checking the
:attr:`.QuerySet.ordered` attribute, which will be ``True`` if the
``QuerySet`` has been ordered in any way.
+.. warning::
+
+ Ordering is not a free operation. Each field you add to the ordering
+ incurs a cost to your database. Each foreign key you add will
+ impliclty include all of its default orderings as well.
+
reverse
~~~~~~~
diff --git a/docs/topics/db/optimization.txt b/docs/topics/db/optimization.txt
index c1459ae247..cca2e6381b 100644
--- a/docs/topics/db/optimization.txt
+++ b/docs/topics/db/optimization.txt
@@ -306,6 +306,17 @@ instead of::
entry.blog.id
+Don't order results if you don't care
+-------------------------------------
+
+Ordering is not free; each field to order by is an operation the database must
+perform. If a model has a default ordering (:attr:`Meta.ordering
+<django.db.models.Options.ordering>`) and you don't need it, remove
+it on a ``QuerySet`` by calling
+:meth:`~django.db.models.query.QuerySet.order_by()` with no parameters.
+
+Adding an index to your database may help to improve ordering performance.
+
Insert in bulk
==============