問題描述
我知道視圖是 Oracle 中底層表或表集的窗口.例如,如果我有一個通過連接多個表創建的視圖,當我從視圖中選擇數據時,視圖會執行實際的連接操作嗎?視圖的性能是否比連接多個表來獲取數據更好?在性能方面是否相同?
I understand that a view is a window to an underlying table or set of tables in Oracle. For instance if I have a view that is created by joining multiple tables , will the view perform the actual join operations when I select data from the view? Does a view perform better than joining multiple tables to fetch data or is it the same with respect to performance?
推薦答案
單個查詢和使用視圖的邏輯等效查詢之間通常沒有性能差異.
There is usually no performance difference between a single query and a logically equivalent query that uses views.
Oracle 具有優化器轉換,可以將視圖與外部查詢結合起來;謂詞推送、簡單和復雜的視圖合并等.將視圖視為構建大型查詢的文本宏,而不是返回行的函數.
Oracle has optimizer transformations that can combine views with the outer query; predicate pushing, simple and complex view merging, etc. Think of views more like a text macro that builds a large query, instead of a function that returns rows.
例如,在下面的查詢中,Oracle 可能足夠聰明,可以將主鍵列上的謂詞推送到視圖中.盡管視圖本身可能會返回數百萬行,但是當整個查詢運行時,Oracle 將首先在主鍵列上應用謂詞.
For example, in the below query Oracle would probably be smart enough to push the predicate on the primary key column into the view. Although the view by itself might return millions of rows, when the entire query is run Oracle will apply the predicate on the primary key column first.
select *
from view_returns_millions_of_rows
where primary_key_value = 1;
這篇關于Oracle 視圖與 Oracle 中的連接表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!