sql – 索引扫描/搜索中选择性的作用

前端之家收集整理的这篇文章主要介绍了sql – 索引扫描/搜索中选择性的作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在阅读许多sql书籍和文章,其中选择性是创建索引的重要因素.如果一列具有低选择性,则索引搜索会带来更多伤害.但这些文章都没有解释原因.任何人都可以解释为什么会这样,或提供相关文章链接

解决方法

来自Robert Sheldon撰写的SimpleTalk文章14 SQL Server Indexing Questions You Were Too Shy To Ask

The ratio of unique values within a key column is referred to as index
selectivity. The more unique the values,the higher the selectivity,
which means that a unique index has the highest possible selectivity.
The query engine loves highly selective key columns,especially if
those columns are referenced in the WHERE clause of your frequently
run queries. The higher the selectivity,the faster the query engine
can reduce the size of the result set. The flipside,of course,is
that a column with relatively few unique values is seldom a good
candidate to be indexed.

另请查看这些文章

>由Pinal Dave检查this post
> this othersql Serverpedia上
> This forum postsqlServerCentral上也可以帮到你.
> This article也在sqlServerCentral上

sqlServerCentral文章

In general,a nonclustered index should be selective. That is,the
values in the column should be fairly unique and queries that filter
on it should return small portions of the table.

The reason for this is that key/RID lookups are expensive operations
and if a nonclustered index is to be used to evaluate a query it needs
to be covering or sufficiently selective that the costs of the lookups
aren’t deemed to be too high.

If sql considers the index (or the subset of the index keys that the
query would be seeking on) insufficiently selective then it is very
likely that the index will be ignored and the query executed as a
clustered index (table) scan.

It is important to note that this does not just apply to the leading column. There are scenarios where a very unselective column can be used as the leading column,with the other columns in the index making it selective enough to be used.

原文链接:https://www.f2er.com/mssql/78900.html

猜你在找的MsSQL相关文章