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

TSQL:調整動態查詢搜索

TSQL: Tune Dynamic Query Search(TSQL:調整動態查詢搜索)
本文介紹了TSQL:調整動態查詢搜索的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在閱讀調整 TSQL 查詢時,我看到了關于避免(或小心)WHERE 子句中的函數的建議.但是,在某些情況下——比如需要從今天開始的動態日期的搜索——我很好奇查詢是否可以進一步調整?例如,下面的查詢使用當前日期的 DATEADD 函數,它允許用戶隨時獲取過去三十天的正確信息:

In reading on tuning TSQL queries, I've seen advice on avoiding (or being careful) about functions in the WHERE clause. However, in some cases - like searches that require dynamic dates from today's date - I'm curious if a query can be tuned further? For instance, the query below this uses the DATEADD function for the current date, which allows the user at anytime to get the correct information for the past thirty days:

SELECT *
FROM Zoo..Transportation
WHERE ArrivalDate BETWEEN DATEADD(DD,-30,GETDATE()) AND GETDATE()

如果我嘗試消除函數DATEADD,我可以聲明一個變量來提取那個時間,然后使用存儲在變量中的設置值查詢數據,例如:

If I try to eliminate the function, DATEADD, I could declare a variable that will pull that time and then query the data with that set value stored in the variable, such as:

DECLARE @begin DATE
SET @begin = DATEADD(DD,-30,GETDATE())

SELECT *
FROM Zoo..Transportation
WHERE ArrivalDate BETWEEN @begin AND GETDATE()

但是,執行計劃和統計數據顯示的讀取、掃描和批處理成本完全相同.

However, the Execution Plan and Statistics show the exact same number of reads, scans and batch costs.

在這些動態數據實例中(例如,使用今天的日期作為起點),我們如何減少或消除WHERE 子句中函數的使用?

In these instances of dynamic data (for instance, using today's date as a starting point), how do we reduce or eliminate the use of functions in the WHERE clause?

推薦答案

where 子句中的函數意味著做一些愚蠢的事情,例如:

Functions in the where clause mean doing silly things like:

WHERE DATEPART(WEEK, ArrivalDate) = 1

WHERE CONVERT(CHAR(10), ArrivalDate, 101) = '01/01/2012'

例如對 where 子句中的起作用,這在大多數情況下會破壞可調整性(換句話說,使索引查找無用并強制進行索引或表掃描).

E.g. functions against columns in the where clause, which in most case destroy sargability (in other words, render an index seek useless and force an index or table scan).

我知道有一個例外:

WHERE CONVERT(DATE, ArrivalDate) = CONVERT(DATE, GETDATE())

但我不會將其用于任何其他場景.

But I would not rely on this for any other scenario.

這篇關于TSQL:調整動態查詢搜索的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 国产一区二区欧美 | 国产欧美精品一区二区 | 一二区视频 | 亚洲精品一区二区在线观看 | 一区二区免费在线观看 | 毛片一区二区三区 | 伊人网站在线观看 | 久久久久久久国产精品影院 | 亚洲欧美日韩国产综合 | 欧美大片一区 | 日韩av啪啪网站大全免费观看 | 二区中文字幕 | 中文字幕av在线 | 国产精品福利视频 | 国产性网| 国产精品久久久久无码av | 亚洲高清一区二区三区 | 中文字幕一区二区三区乱码在线 | 欧美成ee人免费视频 | 亚洲国产欧美一区 | 国产精品99久 | 7799精品视频天天看 | 国产成人av一区二区三区 | 在线看无码的免费网站 | 精品视频一区二区三区在线观看 | 欧美一区二区三区在线观看视频 | 三级视频国产 | 精品一区国产 | 欧美最猛性xxxxx亚洲精品 | 久久久久国产一区二区三区 | 国产一级视频免费播放 | 在线播放中文字幕 | 中文字幕一区在线 | 久久久久国产 | 亚洲精品大全 | 日韩精品久久久久 | 中文在线视频观看 | 福利久久 | 1区2区3区视频 | 精品国产一区二区三区久久影院 | 99精品网站 |