SQL: The myth of COUNT(FooID)
There is a popular ongoing myth about the performace benefit of specifying an ID when using the COUNT function in SQL. For example, Darrel Norton is normally on the ball about stuff, but here he is just wrong.
SELECT COUNT(FooID) FROM Foois not faster than
SELECT COUNT(*) FROM Foo
As the documentation states:
COUNT(*) does not require an expression parameter because, by definition, it does not use information about any particular column. COUNT(*) returns the number of rows in a specified table without eliminating duplicates. It counts each row separately, including rows that contain null values.
Post a Comment