Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improved documentation of when QuerySet.exists() and .count() are a g…

…enuine optimization.

Also fixed a typo.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@11960 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a5af81f93fdf79a99d59a7cabd14ce58266d1d10 1 parent 5160212
Luke Plant authored December 22, 2009

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  docs/ref/models/querysets.txt
10  docs/ref/models/querysets.txt
@@ -1037,7 +1037,8 @@ Example::
1037 1037
 
1038 1038
 ``count()`` performs a ``SELECT COUNT(*)`` behind the scenes, so you should
1039 1039
 always use ``count()`` rather than loading all of the record into Python
1040  
-objects and calling ``len()`` on the result.
  1040
+objects and calling ``len()`` on the result (unless you need to load the
  1041
+objects into memory anyway, in which case ``len()`` will be faster).
1041 1042
 
1042 1043
 Depending on which database you're using (e.g. PostgreSQL vs. MySQL),
1043 1044
 ``count()`` may return a long integer instead of a normal Python integer. This
@@ -1140,8 +1141,11 @@ Aggregation <topics-db-aggregation>`.
1140 1141
 Returns ``True`` if the :class:`QuerySet` contains any results, and ``False``
1141 1142
 if not. This tries to perform the query in the simplest and fastest way
1142 1143
 possible, but it *does* execute nearly the same query. This means that calling
1143  
-:meth:`QuerySet.exists()` is faster that ``bool(some_query_set)``, but not by
1144  
-a large degree.
  1144
+:meth:`QuerySet.exists()` is faster than ``bool(some_query_set)``, but not by
  1145
+a large degree.  If ``some_query_set`` has not yet been evaluated, but you know
  1146
+that it will be at some point, then using ``some_query_set.exists()`` will do
  1147
+more overall work (an additional query) than simply using
  1148
+``bool(some_query_set)``.
1145 1149
 
1146 1150
 Field lookups
1147 1151
 -------------

0 notes on commit a5af81f

Please sign in to comment.
Something went wrong with that request. Please try again.