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

SQL Server 是否在復雜視圖中傳播 WHERE 條件?

Does SQL Server propagate WHERE conditions in complex views?(SQL Server 是否在復雜視圖中傳播 WHERE 條件?)
本文介紹了SQL Server 是否在復雜視圖中傳播 WHERE 條件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我已經用一個完整的例子來跟蹤這個問題,以防我從這個問題中不清楚我的意思.

I've followed this question with a full example in case it isn't clear what I mean from the question.

我制作了一個視圖,它連接了大約五個表中的數據.這些表有大量數據,查詢運行緩慢.我的問題是,如果我這樣做:

I've made a view which joins data from about five tables. The tables have vast amounts of data and the queries are slow to run. My question is that if I do:

SELECT * FROM myView WHERE PersonID = 1000 

SQL Server 是否知道我的意思"并自動將該條件傳播到視圖中的底層連接?這樣它就不會為所有人運行,而是在正確的階段最小化結果集.或者它會運行所有內容然后在完整結果集上執行 WHERE ID = 1000 ?

does SQL Server 'know what I mean' and automatically propagate that condition to the underlying joins in the view? So that it doesn't run for everybody, but minimizes the result set at the right stages. Or will it run for everything then do the WHERE ID = 1000 on the full result set?

示例

為了簡化(...希望如此)我的意思,這里有一個偽 TSQL 場景示例:

To simplify (...hopefully) what I mean, here's an example pseudo-TSQL scenario:

TABLE People (
    ID,
    Surname,
    DOB
)
TABLE Activities (
    ID,
    TypeID,
    LocationID,
    Date
)
TABLE PersonActivityInvolvements (
    ID, 
    PersonID, 
    ActivityID
)
TABLE ActivityTypes (
    ID,
    Name
)
TABLE Locations (
    ID,
    Street,
    City
)

所以我想要一個視圖,顯示所有 People、他們參與的任何 ActivityActivityType地點 它發生了.盡管此設置并不十分復雜,但您可以看到,如果每個實體有數萬個,則執行可能需要很長時間.

So I want a view which shows me all People, any Activities they were involved in, the ActivityType, and the Location it took place. Although this setup is not drastically complicated, you can see that it might take a very long time to execute if there are say tens of thousands of each entity.

視圖可能是這樣的:

SELECT 
    *
FROM 
    People LEFT OUTER JOIN PersonActivityInvolvement PA
    ON People.ID = PA.ID
        INNER JOIN Activity 
        ON PA.ID = Activity.ID
            INNER JOIN ActivityTypes AT
            ON A.TypeID = AT.ID
                INNER JOIN Locations 
                ON A.LocationID = Locations.ID

如果要這樣做

SELECT * FROM myView WHERE DOB >= dateAdd(YEAR, -18, getDate())

視圖中的查詢是為所有人運行還是 SQL Server 知道它應該將其應用于 People.DOB 字段?

would the query inside the view run for everyone or would SQL Server know that it should apply it to the People.DOB field?

推薦答案

引擎會做任何它認為最快的事情.如果您將該字段編入索引,并且您的 JOIN 鍵都編入索引,則它可能會也可能不會先運行該過濾器.

The engine will do whatever it thinks is fastest. If you have that field indexed, and your JOIN keys are all indexed, it may or may not run that filter first.

如果 WHERE 子句的開銷更高(即未編入索引),它實際上可能會在 LAST 上運行過濾器 - 這樣開銷大的操作就會在最小的結果集上運行.

It may actually run the filter LAST if the WHERE clause is more expensive (i.e. unindexed) - that way the expensive operation is running on the smallest result set.

唯一確定的方法是運行查詢并檢查執行計劃(實際未估計).

Ther only way to know for sure is to run the query and check the execution plan (ACTUAL not estimated).

這篇關于SQL Server 是否在復雜視圖中傳播 WHERE 條件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉換為其整數表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 久久久黑人| 95国产精品| 亚洲成人在线免费 | 久久精品国产免费看久久精品 | 亚洲一区二区免费视频 | 精品久久久久久亚洲精品 | 天天插天天操 | av在线免费观看不卡 | 精品福利在线 | 亚洲有码转帖 | 午夜精品一区二区三区在线视频 | 亚洲手机在线 | 欧美精品一区三区 | 黄色av网站在线观看 | 福利av在线| 亚洲一区在线播放 | www.亚洲区| 免费成人在线网站 | 伦理片97 | 91欧美精品成人综合在线观看 | 欧美日韩久| 午夜寂寞福利视频 | 欧美成人免费在线视频 | 成人在线日韩 | 91精品久久 | 欧美一区不卡 | 国户精品久久久久久久久久久不卡 | 色综合99 | 色综合99| 91av小视频| 国产一级视频在线观看 | 中文字幕第一页在线 | 免费中文字幕日韩欧美 | 国产精品国产成人国产三级 | 中文字幕欧美一区二区 | 久久久久久国产 | 亚洲精品久久久 | 在线三级电影 | 国产激情视频网站 | 国产精品毛片一区二区在线看 | 最近中文字幕第一页 |