使用查询调控器防止查询长时间运行

在SQL Server服务器属性--连接中,有一个名为“使用查询调控器防止查询长时间运行”的选项:

官网解释如下:

query governor cost limit option:

Use the query governor cost limit option to specify an upper limit on the time period in which a query can run. Queries that have estimated run times greater than this limit, return an error and are not executed. Query cost refers to the estimated elapsed time, in seconds, required to complete a query on a specific hardware configuration.If you specify a nonzero, nonnegative value, the query governor disallows execution of any query that has an estimated cost exceeding that value. Specifying 0 (the default) for this option turns off the query governor, and all queries are allowed to run without any time limitation.If you use sp_configure to change the value of query governor cost limit, the changed value is server wide. To change the value on a per-connection basis, use the SET QUERY_GOVERNOR_COST_LIMIT statement.The query governor cost limit option is an advanced option. If you are using the sp_configure system stored procedure to change the setting, you can change query governor cost limit only when show advanced options is set to 1. The setting takes effect immediately (without a server restart).
 
说明此设置是一个cost阈值,无单位。如果某个query的subtreecost大于设置值,则不会执行,而是直接报如下错误:

消息 8649,级别 17,状态 1,服务器 LEOSWONDERWORLD,第 1 行
查询已取消,因为此查询的估计开销(59)超出了配置的阈值 5。请与系统管理员联系。

 

需要特别注意的一点是,这个设置貌似对sqlserver management studio(ssms.exe)工具无效,无论是在DB Server本地还是远程连接,使用ssms进行的查询都不会受此参数影响。

但是通过链接服务器查询或者osql、sqlcmd则可以验证。

转载于:https://www.cnblogs.com/leohahah/p/7761483.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值