title: Count vs len on a Django QuerySet when some results are filtered
body: <p>A more general version of my question has already beek asked: <a href="https://stackoverflow.com/questions/14327036/count-vs-len-on-a-django-queryset">Count vs len on a Django QuerySet</a></p>
  
  <p>My case is a bit different, though. It starts with something like this:</p>
  
  <pre><code>messages = Message.objects.filter(foo=bar)
  </code></pre>
  
  <p>To get <code>error_message_count</code> and <code>other_message_count</code>, which is better?</p>
  
  <pre><code>error_message_count = len(message for message in messages if message.is_error)
  other_message_count = len(messages) - error_message_count
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>error_message_count = messages.filter(is_error = True).count()
  other_message_count = messages.count() - error_message_count
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>error_message_count = messages.filter(is_error = True).count()
  other_message_count = messages.filter(is_error = False).count()
  </code></pre>
  
  <p>I suspect that the first solution boils down to only one query, and the others in two. But perhaps Django and/or the DBMS make one of the second two more efficient?</p>
  
  <p>I'll accept 'profile it' as an answer, but I wonder if any of these solutions are considered best practice.</p>