简体   繁体   English

SQL Server性能问题

[英]SQL Server performance questions

I have this query in SQL Server 2012: 我在SQL Server 2012中有以下查询:

Select cat, dog, ant, pig, ItemId 
from dbo.Animals 
where cat <> 'sam' 
  and cat in ('bam', 'dam') 
order by pig

I have laid out below what I did and looked at execution plan and the performance time below. 我在下面做了说明,并在下面查看了执行计划和执行时间。

  1. No indexing - Table scan - 20 s 无索引-表扫描-20 s

  2. Clustered Index on ItemId - Clustered Index scan - 20 s ItemId上的聚簇索引-聚簇索引扫描-20 s

  3. Non Clustered index on cat - Clustered Index scan [ Same as 2 ] - 20s Cat上的非聚集索引-聚集索引扫描[与2相同]-20s

  4. Non Clustered index on pig - Clustered Index scan [ Same as 2 ] - 20s 猪的非聚集索引-聚集索引扫描[与2相同]-20s

My questions is why is the performance the same in all scenarios? 我的问题是为什么在所有情况下性能都一样?

Is Caching playing a factor ? 缓存在起作用吗? I don't have permission to play with freeing cache and things like that currently. 我无权使用释放缓存和当前类似的功能。 Can I try anything else from indexing perspective ? 我可以从索引角度尝试其他方法吗?

Your where is redundant, because the conditions on cat only need the in . 您的where是多余的,因为cat上的条件仅需要in

I suspect the index can be used for the where clause but not for the order by . 我怀疑索引可以用于where子句,但不能用于order byorder by Hence, indexes can be used to optimize the search for the rows, but not for the final ordering. 因此,索引可用于优化对行的搜索,但不能用于最终排序。 Presumably there is a large amount of data and that is taking the bulk of the time. 大概有大量数据,这花费了大量时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM