Repeat:
- Do you have a PhoneStatus table
- With clustered index
- And the non-clustered index on the PhoneStatus and PhoneId columns, in that order
- You are posting an update using "... WHERE PhoneId = 126"
- The table has 20 million rows (i.e. large, and then some)
SQL will take your query and try to figure out how to do the work without processing the entire table. For your nonclustered index, the data may look like this:
PhoneStatus PhoneID A 124 A 125 A 126 B 127 C 128 C 129 C 130 etc.
The thing is, SQL will first check the first column before it checks the value of the second column. Since the first column is not specified in the update, SQL cannot βshortenβ the index search tree to the corresponding records, and therefore it is necessary to scan the entire table. (No, SQL is not smart enough to say βah, I just check the second column first,β and yes, they are right to do it this way.)
Since a nonclustered index will not make the query faster, the scan table is used by default β and since there is a clustered index, this means that instead a clustered index scan occurs. (If the clustered index is on PhoneId, then you will have optimal performance for your request, but I assume that is not the case here).
When you use a tooltip, it forces you to use a non-clustered index, and it will be faster than a full table scan if the table contains a lot more columns than the index (which essentially consists of only two), because there would be much less data to sift.
source share