SQL Server 中的索引查找与索引扫描
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40486539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Index Seek vs Index Scan in SQL Server
提问by Ram
Please explain the difference between Index Scan and Index Seek in MS SQL server with an sample example, since it will be helpful to know, what's the real use of it. Thanks in advance.
请通过示例解释 MS SQL 服务器中索引扫描和索引查找之间的区别,因为它有助于了解它的真正用途。提前致谢。
回答by backtrack
Here is the text showplan (slightly edited for brevity) for this query using a scan:
这是使用扫描的此查询的文本显示计划(为简洁起见略作编辑):
|–Table Scan(OBJECT:([ORDERS]), WHERE:([ORDERKEY]=(2)))
The following figure illustrates the scan:
下图说明了扫描:
Here is the text showplan for the same query using a seek:
这是使用搜索的同一查询的文本显示计划:
|–Index Seek(OBJECT:([ORDERS].[OKEY_IDX]), SEEK:([ORDERKEY]=(2)) ORDERED FORWARD)
have a look on this SQL Server Plans : difference between Index Scan / Index Seek
回答by mansi
In simple words, An index scan or table scan is when SQL Server has to scan the data or index pages to find the appropriate records. A scan is the opposite of a seek, where a seek uses the index to pinpoint the records that are needed to satisfy the query.
简单来说,索引扫描或表扫描是指 SQL Server 必须扫描数据或索引页以找到合适的记录。扫描与查找相反,查找使用索引来精确定位满足查询所需的记录。
your question is similar to the question which is already posted in stackoverflow get it from below link
您的问题类似于已经发布在 stackoverflow 中的问题,请从以下链接获取
you can also get information from below link
您也可以从以下链接获取信息