简体   繁体   English

SQL Server 2005上的架构信息查询速度非常慢

[英]Really slow schema information queries on SQL Server 2005

I have a database with a rather large number of tables, about 3500, and an application that needs to access a table list. 我有一个包含大量表(约3500个)的数据库,并且有一个需要访问表列表的应用程序。

On a particular server this takes over 2.5 min to return. 在特定服务器上,这需要花费2.5分钟以上的时间才能返回。

EXEC sp_tables @table_type="'TABLE'"

I know there are faster ways to do that but sadly I'm not in a position to modify the application and need to find a way to push it below 30 seconds so the application doesn't throw timeout errors. 我知道有更快的方法可以执行此操作,但是很遗憾,我无法修改应用程序,需要找到一种方法将其推到30秒以下,这样应用程序才不会引发超时错误。

So. 所以。 What, if anything, can I do to improve the performance of this sp within sql server? 我可以做些什么来改善此sp在sql server中的性能?

I have seen these stored procedures run slow if you do not have the GRANT VIEW DEFINITION permission set on your user account. 如果您没有在用户帐户上设置GRANT VIEW DEFINITION权限,我已经看到这些存储过程运行缓慢。 From what I read, this will cause a security check to occur slowing down the query. 据我了解,这将导致进行安全检查,从而减慢查询速度。

Maybe a SQL guru can comment on why, if this does help your problem. 如果这确实可以解决您的问题,也许SQL专家可以评论原因。

Well, sp_tables is system code and can't be changed (could workaround in SQL Server 2000, not SQL Server 2005+) 好吧,sp_tables是系统代码,不能更改(可以在SQL Server 2000中解决,而不是SQL Server 2005+)

Your options are 您的选择是

  1. Change the SQL 更改SQL
  2. Change command timeout 更改命令超时
  3. Bigger server 更大的服务器

You've already said "no" to the obvious solutions... 您已经对明显的解决方案说“不”。

You need to approach this just like any other performance problem. 您需要像处理其他任何性能问题一样来解决此问题。 Why is it slow? 为什么慢呢? Namely, where does it block? 即,它在哪里阻止? Disk IO? 磁盘IO? CPU? 中央处理器? Network? 网络? Lock contention? 锁定竞争? The scientific method is to use a methodology like Waits and Queues , or its newer SQL 2008 equivalent Troubleshooting Performance Problems in SQL Server 2008 . 科学方法是使用“ 等待和队列”之类的方法,或使用SQL Server 2008中更新的SQL 2008等价的“故障排除性能问题” The lazy way is to simply check the wait_type , wait_time and wait_resource columns in sys.dm_exec_requests for the session executing the sp_tables call. 懒惰的方法是简单地检查sys.dm_exec_requestswait_typewait_timewait_resource列,以了解执行sp_tables调用的会话。 Once you find out what is blocking the execution, you can proceed accordingly. 一旦你发现什么阻挡了执行,就可以进行相应处理。

If I'd venture a guess, you'll discover contention as the cause: other sessions are locking table's metadata exclusively and thus block the execution of sp_tables, which has to wait until all operations in front of it finish. 如果我大胆猜测,您会发现争用的原因:其他会话专门锁定表的元数据,从而阻止了sp_tables的执行,而sp_tables必须等待其前面的所有操作完成。

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

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