SqlProfiler 扫描启动是否错误?
如果在 SqlProfiler 中您可以看到执行查询时扫描已启动,这是否意味着全表扫描或者只是查找?如果两者都可以,你怎么知道是两者中的哪一个呢?
If in SqlProfiler you can see that to execute a query a Scan is Started, does this mean a full table scan or can it just be a lookup? If it can be both, how can you tell which one of the two it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自文档:
所以可能是其中之一。
IndexID
字段将告诉您它是否是索引以及是哪个索引。这并不是说它真的很重要。聚集索引扫描基本上是表扫描。非聚集索引扫描更好,但也只是一点点。如果您看到任何完整扫描,则意味着 (a) 您正在使用不可控制谓词或对未索引的字段使用谓词,或者 (b) 谓词字段已建立索引,但输出列未被索引覆盖。索引,并且优化器决定执行完整扫描比书签/RID 查找更便宜。
从性能角度来看,索引扫描通常并不比表扫描好多少,因此如果可能的话,您应该尝试消除导致索引扫描的任何因素。
From the documentation:
So it could be either one. The
IndexID
field will tell you if it is an index, and which one.Not that it really matters very much. A clustered index scan basically is a table scan. A nonclustered index scan is better, but only a little. If you see any full scan, it means either (a) you're using non-sargable predicates or predicates on fields that aren't indexed, or (b) the predicate fields are indexed but the output columns aren't covered by the index, and the optimizer has decided that it is cheaper to perform a full scan than a bookmark/RID lookup.
Index scans aren't often much better than table scans, performance-wise, so you should try to eliminate whatever is leading to it, if possible.