Often it is said to use count(id)
as it reduces the amount of data being processed. As an index exists on it, it is considered faster and more efficient.
This assumption is incorrect. In reality, the database uses the smallest secondary non-null index.
count(*)
basically means nothing more than Count anything as fast as you can
. It leaves the decision of optimization to the database.
count(id)
is actually ignored. The database's optimizer ignores the id
.
Why does it exist then? count()
is an aggregation function. As per SQL standard, an aggregation function must have a parameter, even when it's not always necessary.
Reference links: