Index Seek和Index Scan

本文解析了SQL Server中Table Scan与Index Scan的区别,介绍了Query Optimizer如何选择最有效的查询方式,并提供了性能优化建议。

When   I   create   a   graphical   query   execution   plan   of   a   query   using   Query   Analyzer,   I   notice   that   there   are   two   types   of   scans:   Table   Scans   and   Index   Scans.   How   are   these   different?    
   
   
   
  Answer  
   
  When   the   Query   Optimizer   is   asked   to   optimize   a   query   and   create   an   execution   plan   for   it,   it   tries   its   best   to   use   an   Index   Seek.   An   Index   Seek   means   that   the   Query   Optimizer   was   able   to   find   a   useful   index   in   order   to   locate   the   appropriate   records.   As   you   probably   know,   indexes   make   data   retrieval   in   SQL   Server   very   fast.    
   
  But   when   the   Query   Optimizer   is   not   able   to   perform   an   Index   Seek,   either   because   there   is   no   indexes   or   no   useful   indexes   available,   then   SQL   Server   has   to   scan   all   the   records,   looking   for   all   the   records   that   meet   the   requirements   of   the   query.    
   
  There   are   two   types   of   scans   the   SQL   Server   can   perform.   When   a   Table   Scan   is   performed,   all   the   records   in   a   table   are   examined,   one   by   one.   For   large   tables,   this   can   take   a   long   time.   But   for   very   small   tables,   a   table   scan   can   actually   be   faster   than   an   Index   Seek.   So   if   you   see   that   SQL   Server   has   performed   a   Table   Scan,   take   a   note   of   how   many   rows   are   in   the   table.   If   there   aren't   many,   then   in   this   case,   a   Table   Scan   is   a   good   thing.    
   
  When   an   Index   Scan   is   performed,   all   the   rows   in   the   leaf   level   of   the   index   are   scanned.   What   does   this   mean?   Essentially,   this   means   that   all   of   the   rows   of   the   table   or   the   index   are   examined   instead   of   the   table   directly.   Sometimes,   the   Query   Optimizer   determines   that   an   Index   Scan   is   more   efficient   than   a   Table   Scan,   so   one   is   performed,   although   the   performance   difference   between   them   is   generally   not   much.    
   
  You   might   ask   that   if   there   is   an   index   available,   why   can't   an   Index   Seek   be   performed?   In   some   cases,   such   as   if   a   huge   quantity   of   rows   need   to   be   returned,   it   is   faster   to   do   an   Index   Scan   than   an   Index   Seek.   Or   it   may   be   because   the   index   is   not   selective   enough.   In   any   case,   the   Query   Optimizer   doesn't   think   the   available   index   is   useful,   other   than   for   performing   an   Index   Scan.    
   
  So   what   does   all   this   mean   from   an   analysis   standpoint?   Generally   speaking,   an   Index   Scan   or   an   Index   Seek   is   almost   the   same   thing,   from   a   performance   perspective.   If   you   see   any   one   of   these   in   a   query   execution   plan,   the   first   thing   you   need   to   do   is   to   see   if   there   are   few   rows   in   the   table.   If   so,   then   a   scan   is   OK.   Or,   if   many   rows   are   being   returned,   then   a   scan   is   often   faster   than   an   Index   Seek,   and   the   Query   Optimizer   made   the   correct   choice   of   selecting   a   scan.   The   only   way   to   speed   up   this   particular   situation   would   be   to   find   a   way   to   rewrite   the   query   in   order   to   return   fewer   rows,   assuming   this   is   possible.    
   
  If   the   above   two   reasons   don't   apply,   then   your   next   step   would   be   to   try   to   identify   useable   indexes   to   help   speed   the   performance   of   the   query,   assuming   that   the   current   performance   of   the   query   is   unacceptable,   so   that   an   Index   Seek   is   performed   instead   of   an   Index   or   Table   Scan.  

【SCI一区复现】基于配电网韧性提升的应急移动电源预配置动态调度(下)—MPS动态调度(Matlab代码实现)内容概要:本文档围绕“基于配电网韧性提升的应急移动电源预配置动态调度”主题,重点介绍MPS(Mobile Power Sources)动态调度的Matlab代码实现,是SCI一区论文复现的技术资料。内容涵盖在灾害或故障等极端场景下,如何通过优化算法对应急移动电源进行科学调度,以提升配电网在突发事件中的恢复能力与供电可靠性。文档强调采用先进的智能优化算法进行建模求解,并结合IEEE标准测试系统(如IEEE33节点)进行仿真验证,具有较强的学术前沿性工程应用价值。; 适合人群:具备电力系统基础知识Matlab编程能力,从事电力系统优化、配电网韧性、应急电源调度等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于复现高水平期刊(SCI一区、IEEE顶刊)中关于配电网韧性与移动电源调度的研究成果;②支撑科研项目中的模型构建与算法开发,提升配电网在故障后的快速恢复能力;③为电力系统应急调度策略提供仿真工具与技术参考。; 阅读建议:建议结合前篇“MPS预配置”内容系统学习,重点关注动态调度模型的数学建模、目标函数设计与Matlab代码实现细节,建议配合YALMIP等优化工具包进行仿真实验,并参考文中提供的网盘资源获取完整代码与数据。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值