Index Seek是Sql Server执行查询语句时利用建立的索引进行查找,索引是B树结构,Sql Server先查找索引树的根节点,一级一级向下查找,在查找到相应叶子节点后,取出叶子节点的数据。对于聚集索引,叶子节点是整个表的数据,能够获取到所有列的数据,而对于非聚集索引,叶子节点存储的是索引列的数据,如果索引有包含列,那么叶子节点中存储有包含列的数据,获取的数据是索引列和包含列,如果还需要其他列的数据,那么必须进行key lookup,根据索引叶子节点包含的“行地址”信息到源表中去获取数据,这部属于Index Seek,而是Key Looup(书签查找)的范畴。Index Seek非常适用于从大数据量的表中返回少量记录的查询。

Index Scan是直接遍历索引树的所有叶子节点,类似于Table Scan。

参考文章

http://www.cnblogs.com/wuxiaoqian726/articles/2015519.html

SQL有一个查询优化分析器 Query Optimizer,其在执行查询之前首先会进行分析,当查询中有可以利用的索引时,其会优先分析使用Index Seek进行查询的效率,在使用Index Seek查询效率并不好的情况下,其会使用Index Scan进行查询。那究竟是在什么情况下会造成Index Seek效率比Index Scan还低呢?

1.在要查询的表中数据不是很多的话,使用Index Seek效率不一定高,因此使用Index seek还要先从索引树开始,然后再利用叶子节点去查找相应的行。在行树比较少的情况下,还没有直接进行Index scan快。

2.在返回的数据量大的情况下,在返回的数据量占总数据量的50%或者超过50%则使用Index Seek效率不一定好,在返回的数据量占10%-15%时,利用Index Seek能获得最佳的性能。

3.在建立索引的列的取值很多是一致的情况下,建立索引不一定能获得很好的效率。其实理由很简单,当建立索引的列取值的变化少的情况下,建立的索引二叉树是矮胖型的,树层次不高,很多行的信息都包含在叶子上,这样的查询显然是不能很好的利用到索引。

参考文章

http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/

SQL SERVER – Index Seek vs. Index Scan – Diffefence and Usage – A Simple Note

In this article we shall examine the two modes of data search and retrieval using indexes- index seeks and index scans, and the differences between the two.

Firstly, let us revisit indexes briefly. An index in a SQL Server database is analogous to the index at the start of a book. That is, its function is to allow you to quickly find the data you are searching for inside the book; in the case of a database, the “book” is a table.

An index scan means that SQL Server reads all rows in a table, and then returns only those rows that satisfy the search criteria. When an index scan is performed, all the rows in the leaf level of the index are scanned. This essentially means that all of the rows of the index are examined instead of the table directly. This is sometimes contrasted to a table scan, in which all the table data is read directly. However, there is usually little difference between an index scan and a table scan.

You may wonder why the Query Optimizer may choose to do an index or table scan. Surely it is much faster to first look up data using an index than to go through all the rows in a table? In fact, for small tables data retrieval via an index or table scan is faster than using the index itself for selection. This is because the added overhead of first reading the index, then reading the pages containing the rows returned by the index, does not offer any performance improvement for a table with only a few rows.

Other reasons to use an index scan would be when an index is not selective enough, and when a query will return a large percentage (greater than 50%) of rows from the table. In such cases the additional overhead of first using the index may result in a small degradation of performance.

An index seek, on the other hand, means that the Query Optimizer relies entirely on the index leaf data to locate rows satisfying the query condition. An index seek will be most beneficial in cases where a small percentage (less than 10 or 15%) of rows will be returned. An index seek will only affect the rows that satisfy a query condition and the pages that contain these qualifying rows; this is highly beneficial, in performance terms, when a table has a very large number of rows.

It is also worth noting that it is usually not worthwhile to create indexes on low-cardinality columns as they would rarely be used by the Query Optimizer. A low-cardinality column is one that contains a very small range of distinct values, for example a ‘Gender’ column would have only two distinct values- Male or Female. An example of a high-cardinality column is of course the primary key column, in which each value is distinct.

In summary, the Query Optimizer generally tries to perform an index seek. If this is not possible or beneficial (for example when the total number of rows is very small) then an index scan is used instead.

Index Seek和Index Scan的区别的更多相关文章

  1. index seek与index scan

    原文地址:http://blog.csdn.net/pumaadamsjack/article/details/6597357 低效Index Scan(索引扫描):就全扫描索引(包括根页,中间页和叶 ...

  2. index seek和index scan 提高sql 效率

    index seek和index scan 提高sql 效率解释解释index seek和index scan:索引是一颗B树,index seek是查找从B树的根节点开始,一级一级找到目标行.ind ...

  3. 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...

  4. Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...

  5. Clustered Index Scan 与 Clustered Index Seek

    Clustered Index Scan 与 Clustered Index Seek 在利用 SQL Server 查询分析器的执行计划中,会有许多扫描方式,其中就有 Clustered Index ...

  6. SQL Server中LIKE %search_string% 走索引查找(Index Seek)浅析

      在SQL Server的SQL优化过程中,如果遇到WHERE条件中包含LIKE '%search_string%'是一件非常头痛的事情.这种情况下,一般要修改业务逻辑或改写SQL才能解决SQL执行 ...

  7. JQ first-child与:first的区别以及nth-child(index)与eq(index)的区别

    1.first-child和:first区别 first-child  是指选取每个父元素的第一个子元素 如$("div:first-child")指每个父级里的第一个div孩子 ...

  8. SqlSever中Index Seek的匹配规则(一)

    我们知道在SqlServer中,索引对查询语句的优化起着巨大的作用,一般来说在执行计划中出现了Index Seek的步骤,我们就认为索引命中了.但是Index Seek中有两个部分是值得我们注意的,我 ...

  9. mysql 索引查询 、创建 create index 与 add index 的区别

    1.索引查询 ------TABLE_SCHEMA  库名:TABLE  表名 ------AND UPPER(INDEX_NAME) != 'PRIMARY'  只查询索引,不需要主键 SELECT ...

随机推荐

  1. Swift语法简介(一)

    或许网络上有很多成型的介绍,我只想写下来留给自己.欢迎批评.开撸! 1.第一个程序,Hello,world!古人云,学会了Hello,world!这门语言你就掌握了一半了. print("H ...

  2. 天气预报API(六):中国气象频道、腾讯天气--“新编码”接口的测试

    说明 本文所有测试均以青岛为例. 本文所列接口城市代码(cityid)参数都使用的 "新编码": 全国城市代码列表(新) 本文接口均不是官方接口,仅供测试使用! 腾讯天气 空气质量 ...

  3. (转)【推荐】初级.NET程序员,你必须知道的EF知识和经验

    转自:http://www.cnblogs.com/zhaopei/p/5721789.html [推荐]初级.NET程序员,你必须知道的EF知识和经验   阅读目录   [本文已下咒.先顶后看,会涨 ...

  4. Handler机制来处理子线程去更新UI线程控件

    public class HandlerTestActivity extends Activity { private TextView tv; private static final int UP ...

  5. 【整理】--C++变量概述

    1.变量概述及特殊变量初始化 a.引用 b.常量 c.静态 d.静态常量(整型) e.静态常量(非整型) 初始化:常量和引用,必须通过参数列表进行初始化. 静态成员变量的初始化也颇有点特别,是在类外初 ...

  6. HTML5-表单的创建

    <!-- 文本-->, <!-- 复选框-->,<!-- 单选按钮-->, <!-- 下拉菜单,select:选择,option:选项--> <! ...

  7. [ASE][Daily Scrum]12.15

    这两周事情好多~ 组里面的事情,出国的申请出国………… 不过整体来说我们sprint3并没有安排太多的工作,所以完成情况尚可. 大地图和AI花费了不少时间,

  8. 大数据存储:MongoDB实战指南——常见问题解答

    锁粒度与并发性能怎么样? 数据库的读写并发性能与锁的粒度息息相关,不管是读操作还是写操作开始运行时,都会请求相应的锁资源,如果请求不到,操作就会被阻塞.读操作请求的是读锁,能够与其它读操作共享,但是当 ...

  9. RCP:为指定的导航器添加上下文菜单

    可以参考Eclipse的Help->Help Content下的: Platform Plug-in Developer Guide > Programmer's Guide > P ...

  10. reactor & proactor 笔记

    1. 基本概念 1.1 同步/异步,针对应用程序和内核交互而言. 同步:进程触发IO操作等待或轮询查看IO操作是否完成: 异步:进程触发IO操作后仅需自身的处理,IO操作完成后会得到通知(异步的特点) ...