|
Comments
|
|
The index you add should be useful and something you are going to use. In this case the index is not useful for anything but COUNT(*) because its selectivity is very high (50%). If you add an index that is not useful and the table volatility is high, you will loose whatever performance you gain on COUNT(*) to slower updates. If the volatility is low then it is not clear why you would be doing lots of count queries. So, while this is a good teaching example, you should stress that adding indexes requires good justification and careful analysis.
|
|
|
Would it also be better to do SELECT COUNT(fieldname) as opposed to SELECT COUNT(*), or does it not make any difference?
|
|
|
very inadequate selection of a bit column for a nonclustered index key.
|
|
|
great video
|
|
|
To MattP:
Yes, it does make a difference. From what I understand, if you SELECT COUNT(fieldname), your count will not include rows where the fieldname value is null.
|
|
|
Understand you want the smallest index possible to satisfy your query, but not sure its a 'best practise' to create a index on a bit column?
|
|
|
I am curious as to how or why the query selects the non-clustered index to perform the query, rather than the clustered index.
Thanks.
|
|
|
I'm sure only the people a MS could say for sure why the optimizer selected that index. Remember the query optimizer is a closely guarded secret.
But if you think about it for a minute it might start to make sense why the optimizer selected this index.
First what does this query need to do? It needs to count all the rows in the table. To do that it would need to use an index that contains an index value for every row. Since the NameStyle column does not allow nulls it will have a value for every row (or every clustered index key) in the leaf level pages. By quickly looking at the index space usage statistics SQL Server can quickly determine it will take less I/O to read the non-clustered index leaf pages verses reading the cluster index leaf pages.
Greg
|
|
|
Thanks!
|
|
|
Very helpful presentation, now I understand why to use non clustered indexes.
|
|
|
keep this kind of cool stuff coming!
|
|
|
Excellent video. Pls consider to do more videos of performance tuning. Thanks!
|
|
|
More in-depth would be very helpful and welcome
|
|
|
This is really great stuff. Thanks for the performance videos as they help understand the underlying structures.
It wasn't clear to my simple and confused mind why picjing the bit column helped - it didn't seem to be a part of the query.
|
|
|
good information
|
|
|
Kool, seems like the bit column index is faster because its less data to scan. Can you confirm this?
|
|
|
Makes sense, a bit column, means its reading less data.
|
|
|
good article
|
|
|
nice
|
|
|
good one
|
|
|
bloody brilliant mate! Was literally taken aback that the nonclustered index read so much less pages. Thanks
|