Hi Ram,

On 01/18/2013 06:25 AM, Ram Rachum wrote:
> Can someone who's familiar with Django internals please confirm or deny
> the following answer to my question?
> 
> http://stackoverflow.com/a/14369747/76701

That answer is correct. A common situation for evaluating a queryset in
a boolean context is that you're about to use the results if there are
any, in which case it's more efficient to fetch all the data right away
rather than doing a COUNT query and then a second query to fetch all the
data.

The only time "exists()" is more efficient is when _all_ you want is to
know whether there are any matching rows; you're not going to do
anything with the rows themselves.

When the existence-check is just a path on the way to the "real" use of
the queryset, you can be quick and implicit; when the existence check is
all that you care about, you say so explicitly by using "exists()".

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to