0

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?
jps
  • 20,041
  • 15
  • 75
  • 79
Chanikya
  • 476
  • 1
  • 8
  • 22

1 Answers1

1

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360