I\'ve heard several times that you shouldn\'t perform COUNT(*)
or SELECT *
for performance reasons, but wasn\'t able to dig up some further informa
COUNT(*)
is different from COUNT(column1)
!
COUNT(*)
returns the number of records, and does NOT use more resources, while COUNT(column1)
counts the number of records where column1 is non null.
For SELECT
, it is different. SELECT *
will of course request more data.
It's absolutely true that "*" is "all columns". And you're right in the point of if you've a table with an incredible number of columns (say 100+), these kind of queries can be bad in terms of efficiency.
I believe that the best solution is creating database views previously filtering the amount of records evolved in the count operation, so, the performance impact isn't a big problem, because views can be cached.
In the other hand, it seems that "*" operator should be avoided when returning records, and it's brutally better to select the fields you really need to use in some business.