简体   繁体   中英

If available why does the processor not use a clustered index scan

So I have this structure on a user table:

在此处输入图片说明

But if I run the following code:

select count(*) 
from WH.dbo.tb_DimUserAccount

It seems to go for the Non-Unique Non-Clustered index ix_DimUserAccount_UserType :

在此处输入图片说明

This is the Index Scan:

在此处输入图片说明

Why doesn't it go for a scan of ix_DimUserAccount_Unique ? Should I change my code to somehow use a different index?

Because the non clustered index is probably narrower than the clustered index and it is cheaper to scan than the clustered index (fewer pages to read).

The NCI leaf pages just contain values for the index keys and any included columns. The clustered index leaf pages need to contain values (or pointers to the values) for all columns in the table.

Thus the clustered index will (assuming equal fill factors) generally fit fewer rows per page than an NCI (except for the case where an NCI includes all columns in the table)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM