久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

T-SQL 從視圖中選擇變量要慢得多

T-SQL Select from view much slower with variable(T-SQL 從視圖中選擇變量要慢得多)
本文介紹了T-SQL 從視圖中選擇變量要慢得多的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 where 子句中指定值時,我有一個運行速度很快(<1s)的視圖:

I have a view that runs fast (< 1s) when specifying a value in the where clause:

SELECT *
FROM vwPayments
WHERE AccountId = 8155

...但是當該值是變量時運行緩慢(~3s):

...but runs slow (~3s) when that value is a variable:

DECLARE @AccountId BIGINT = 8155

SELECT *
FROM vwPayments
WHERE AccountId = @AccountId

為什么第二個查詢的執行計劃不同?為什么它運行得這么慢?

Why is the execution plan different for the second query? Why is it running so much slower?

推薦答案

簡而言之,查詢優化器用來選擇最佳計劃的統計分析會在值為已知值時選擇查找,并且它可以利用統計信息和掃描值未知.它在第二個選擇中選擇掃描,因為在知道 where 子句的值之前編譯計劃.

In short the statistical analysis the query optimizer uses to pick the best plan picks a seek when the value is a known value and it can leverage statistics and a scan when the value is not known. It picks a scan in the second choice because the plan is compiled before the value of the where clause is known.

雖然我很少建議在這種特定情況下使用查詢分析器,但您可以使用 forceseek 提示或其他查詢提示來覆蓋引擎.但是請注意,在引擎的幫助下找到獲得最佳計劃的方法是更好的解決方案.

While I rarely recommend bossing the query analyzer around in this specific case you can use a forceseek hint or other query hints to override the engine. Be aware however, that finding a way to get an optimal plan with the engine's help is a MUCH better solution.

我快速搜索了谷歌并找到了一篇體面的文章更深入地介紹了影響查詢計劃的局部變量的概念.

I did a quick Google and found a decent article that goes into the concept of local variables affecting query plans more deeply.

這篇關于T-SQL 從視圖中選擇變量要慢得多的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日本一区二区三区四区 | 亚洲伦理自拍 | 亚洲一区 | 欧美午夜一区二区三区免费大片 | 国产高清在线 | 91成人午夜性a一级毛片 | 亚洲a一区二区 | 久久国产电影 | 亚洲国产黄 | 日韩精品一区二区三区四区 | 亚洲三级在线观看 | 欧美成人精品二区三区99精品 | 成人久久一区 | 免费视频一区二区三区在线观看 | 精品国产乱码久久久久久闺蜜 | 波多野结衣一二三区 | 久久久亚洲| 国产精品小视频在线观看 | 四虎影院新网址 | 国产亚洲精品美女久久久久久久久久 | 国产精品揄拍一区二区 | 国产精品久久久久久久久久 | 色小姐综合网 | 国产免费自拍 | 成人高清网站 | 午夜视频在线观看一区二区 | 男女在线网站 | 日韩av在线一区二区 | 精品国产乱码久久久久久蜜柚 | 黄a网站| 亚洲网站免费看 | 久久久久综合 | 久久午夜精品 | 久久久久久久一区二区 | 亚洲激情av| 日本超碰 | 精品少妇一区二区三区日产乱码 | 亚洲网站在线观看 | 成人不卡 | 超碰成人免费 | 亚洲天堂免费 |