In 将军, the index will be used if the assumed cost of using the index, and then possibly having to perform further bookmark lookups is lower than the cost of just scanning the entire table.
If your query is of the form:
SELECT Name from Table where Name = 'Boris'
And 1 row out of 1000 has the name Boris, it will almost certainly be used. If everyone's name is Boris, it will probably resort to a table scan, since the index is unlikely to be a more efficient strategy to access the data.
The index hint is only available for Microsoft Dynamics database servers.
对于传统的 SQLServer,您在“ Where”子句中定义的过滤器应该说服引擎使用任何相关的索引..。
如果引擎的执行计划能够有效地识别如何读取信息(无论是全表扫描还是索引扫描) ,那么它必须在正确执行语句之前对两者进行比较,作为其内置性能优化器的一部分。
但是,您可以通过使用类似这样的东西来强制优化器进行扫描
Select *
From [yourtable] With (Index(0))
Where ...
或者使用类似于
Select *
From [yourtable] With (Index(1))
Where ...
选择权在你。在对象面板中查看表的索引属性,以了解要使用哪个索引。它应该和你的滤光片相配。
For best results, list the filters which would return the fewest results first.
我不知道我这么说是否正确,但是看起来查询过滤器是连续的; 如果你得到了正确的序列,优化器不应该通过比较所有的组合来为你做这件事,或者至少不应该开始与更昂贵的查询进行比较。