Why does Django's count()
result in a SQL query like
SELECT COUNT(*)
and is there a way to just count on a single column?
For instance, having a model with the following rows:
- id
- first_name
- last_name
Instead of having the count run on *
which is similar to SELECT COUNT(id, first_name, last_name)
I would like to only run
SELECT COUNT(id)
Or best to do SELECT COUNT(1)
. I want to do this because I once heard that this would be faster for huge tables.
NOTE: If it's faster or not is not the question, it's how to do the query with Django. So please don't mark it as duplicated with Count(*) vs Count(1) - SQL Server