简体   繁体   English

Oracle 视图与 Oracle 中的连接表

[英]Oracle View vs joining tables in Oracle

I understand that a view is a window to an underlying table or set of tables in Oracle.我知道视图是 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 has optimizer transformations that can combine views with the outer query; Oracle 具有优化器转换,可以将视图与外部查询结合起来; 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.谓词推送、简单和复杂的视图合并等。将视图视为构建大型查询的文本宏,而不是返回行的函数。

For example, in the below query Oracle would probably be smart enough to push the predicate on the primary key column into the view.例如,在下面的查询中,Oracle 可能足够聪明,可以将主键列上的谓词推送到视图中。 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.尽管视图本身可能会返回数百万行,但是当整个查询运行时,Oracle 将首先在主键列上应用谓词。

select *
from view_returns_millions_of_rows
where primary_key_value = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM