[ACCEPTED]-Is "SELECT COUNT(column)" faster/slower than "SELECT COUNT(*)"?-count
I tried a few SELECT COUNT(*) FROM MyTable
vs. SELECT COUNT(SomeColumn) FROM MyTable
with various sizes of 17 tables, and where the SomeColumn
once is a clustering 16 key column, once it's in a non-clustered 15 index, and once it's in no index at all.
In 14 all cases, with all sizes of tables (from 13 300'000 rows to 170 million rows), I never 12 see any difference in terms of either speed nor execution 11 plan - in all cases, the COUNT
is handled by 10 doing a clustered index scan --> i.e. scanning 9 the whole table, basically. If there is 8 a non-clustered index involved, then the 7 scan is on that index - even when doing 6 a SELECT COUNT(*)
!
There doesn't seem to be any difference 5 in terms of speed or approach how those 4 things are counted - to count them all, SQL 3 Server just needs to scan the whole table 2 - period.
Tests were done on SQL Server 1 2008 R2 Developer Edition
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.