同一查询的不同执行时间 where 子句中的不同值

different execution time for same query where different values in where clause

亲爱的, 我 运行 相同的查询,它需要不同的执行时间如下: 查询是:

select * from table1 where userID = 2

它扫描包含用户 ID 作为其键之一的非集群索引 idx1,因此我在 5 秒内得到结果。 但是当我再次使用 userID = 5 运行 时 它扫描不包含 userID 作为其键之一的非集群索引 idx2,并在 2 小时后得到结果,我认为它可能读取整个 table 以找到 userID = 5

这个问题的原因是什么?? 也许 userID = 5 的值不在 idx1 叶子中?? 我认为 NC 索引中的叶级别存储一系列值和查询 运行 以及 userID =4 和 userID = 6 所以 userID = 5 应该在叶级别,

请指教

尝试使用索引提示

热修复

select * from table1 with(index(idx1) where userID = 5

参考:http://blog.sqlauthority.com/2009/02/08/sql-server-introduction-to-force-index-query-hints-index-hint-part2/

长期解决方案

您可能需要更新 table 的统计信息或重建索引。 您可以点击此链接:Script for rebuilding and reindexing the fragmented index?

首先更新该表索引的统计信息。 如果它不起作用并且您正在使用 ASE15 或 +,您应该更新列 userID 的统计信息。 ASE15 优化器比 ASE12 对统计信息更敏感。