1. 程式人生 > >使用查詢調控器防止查詢長時間運行

使用查詢調控器防止查詢長時間運行

ima erro 遠程 eat 已取消 運行 es2017 urn 配置

在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則可以驗證。

使用查詢調控器防止查詢長時間運行