Is COUNT(*) indexed?

前端 未结 1 699
庸人自扰
庸人自扰 2020-12-30 06:53

I want to know just for curiosity that, does Select Count(*) from SomeTableName also traverses all the rows of the database as that of Select * from SomeT

相关标签:
1条回答
  • 2020-12-30 07:33
    SELECT Count(*)
    FROM   SomeTableName 
    

    will always count all rows. Though (unlike SELECT *) it does not have to read all columns and can use the narrowest (non filtered) index available to do so.

    Unlike MySQL (MyISAM engine) it does not retrieve the value from metadata.

    A rowcount value is available in the metadata and can be retrieved from sys.partitions but this is never used for COUNT queries and isn't always accurate.

    0 讨论(0)
提交回复
热议问题