简体   繁体   English

SQL Server简单的WHERE子句极其慢

[英]SQL Server simple WHERE clause extremely slow

My SQL Server query is something like 我的SQL Server查询类似于

Select * 
from mytable 
where mycolum = X

The table only has about 8000 records, and this query used to run extremely fast. 该表只有大约8000条记录,该查询过去运行得非常快。

Now all of a sudden it's running super slow. 现在突然之间,它的运行速度非常慢。 Any thoughts? 有什么想法吗? Here's what I've tried 这是我尝试过的

  • Updating the statistics for that table 更新该表的统计信息
  • Shrinking the database 缩小数据库
  • Updating stats for the entire database via sp_updatestats 通过sp_updatestats更新整个数据库的统计信息
  • Restarting the db server 重新启动数据库服务器

None of these are working. 这些都不起作用。

Any ideas or things I could try? 有什么想法或我可以尝试的事情吗?

You should create an index for the column. 您应该为该列创建索引。 If you are using a production DB that needs to remain active during the building of the index then you want to use ONLINE = ON in my sample below. 如果您使用的生产数据库需要在建立索引期间保持活动状态,那么您想在下面的示例中使用ONLINE = ON。

CREATE INDEX mytable_indx1 ON dbo.mytable (mycolum) WITH (ONLINE = ON);

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

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