Suppose I have a huge table with 500,000 rows in MySQL.
Which is faster,
- getting the number of rows in a table or
- getting all the data with 8 columns?
Suppose I have a huge table with 500,000 rows in MySQL.
Which is faster,
If you are calling MySQL from your ASP.net code, then the most efficient way by far to get a count of all records in a table is to do SELECT COUNT(*)
, or something equivalent to this. The reason is that returning all records takes a potentially huge amount of bandwidth. If all you want is a count of all records, then you don't really care about the data in those records.
Besides bandwidth/network overhead, there is the cost of counting the records themselves. Databases were designed with such aggregate operations in mind, application languages less so.