Oracle 中的视图和物化视图有什么区别?

发布于 2024-07-05 02:37:33 字数 29 浏览 17 评论 0原文

Oracle 中的视图和物化视图有什么区别?

What is the difference between Views and Materialized Views in Oracle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

不知所踪 2024-07-12 02:37:33

物化视图是由选择查询驱动的数据逻辑视图,但查询的结果将存储在表或磁盘中,查询的定义也将存储在数据库中。

物化视图的性能比普通视图更好,因为物化视图的数据将存储在表中,并且表可以建立索引,因此连接速度更快,并且连接是在物化视图刷新时完成的,因此无需每次触发join 语句与视图的情况一样。

其他区别包括,在视图的情况下,我们总是获取最新数据,但在物化视图的情况下,我们需要刷新视图才能获取最新数据。
对于物化视图,我们需要一个额外的触发器或一些自动方法,以便我们可以保持 MV 刷新,这对于数据库中的视图来说不是必需的。

Materialized views are the logical view of data-driven by the select query but the result of the query will get stored in the table or disk, also the definition of the query will also store in the database.

The performance of Materialized view it is better than normal View because the data of materialized view will be stored in table and table may be indexed so faster for joining also joining is done at the time of materialized views refresh time so no need to every time fire join statement as in case of view.

Other difference includes in case of View we always get latest data but in case of Materialized view we need to refresh the view for getting latest data.
In case of Materialized view we need an extra trigger or some automatic method so that we can keep MV refreshed, this is not required for views in the database.

剪不断理还乱 2024-07-12 02:37:33

添加到 Mike McAllister 相当彻底的答案中......

只有当编译器认为视图查询简单时,物化视图才能设置为通过数据库检测更改自动刷新。 如果它被认为太复杂,它将无法设置本质上是内部触发器来跟踪源表中的更改,从而仅更新 mview 表中更改的行。

当您创建物化视图时,您会发现 Oracle 既创建了 mview,又创建了同名的表,这可能会让事情变得混乱。

Adding to Mike McAllister's pretty-thorough answer...

Materialized views can only be set to refresh automatically through the database detecting changes when the view query is considered simple by the compiler. If it's considered too complex, it won't be able to set up what are essentially internal triggers to track changes in the source tables to only update the changed rows in the mview table.

When you create a materialized view, you'll find that Oracle creates both the mview and as a table with the same name, which can make things confusing.

谜兔 2024-07-12 02:37:33

视图:视图只是一个命名查询。 它不存储任何东西。 当视图有查询时,它会运行视图定义的查询。 实际数据来自表格。

物化视图:物理存储数据并定期更新。 查询MV时,给出MV中的数据。

View: View is just a named query. It doesn't store anything. When there is a query on view, it runs the query of the view definition. Actual data comes from table.

Materialised views: Stores data physically and get updated periodically. While querying MV, it gives data from MV.

捂风挽笑 2024-07-12 02:37:33

视图本质上是由给定查询动态填充的类似逻辑表的结构。 视图查询的结果不会存储在磁盘上的任何位置,并且每次执行查询时都会重新创建视图。 物化视图是存储在数据库中并写入磁盘的实际结构。 它们根据创建时定义的参数进行更新。

Views are essentially logical table-like structures populated on the fly by a given query. The results of a view query are not stored anywhere on disk and the view is recreated every time the query is executed. Materialized views are actual structures stored within the database and written to disk. They are updated based on the parameters defined when they are created.

梦途 2024-07-12 02:37:33

物化视图基于磁盘,并根据查询定义定期更新。

视图只是虚拟的,每次访问时都会运行查询定义。

Materialized views are disk based and are updated periodically based upon the query definition.

Views are virtual only and run the query definition each time they are accessed.

尸血腥色 2024-07-12 02:37:33

视图

它们在查询视图时评估视图定义基础表中的数据。 它是表的逻辑视图,没有数据存储在其他地方。

视图的优点是它始终向您返回最新数据。 视图的缺点是其性能取决于视图所基于的 select 语句的好坏。 如果视图使用的 select 语句连接许多表,或者使用基于非索引列的连接,则视图的性能可能会很差。

物化视图

它们类似于常规视图,因为它们是数据的逻辑视图(基于 select 语句),但是,底层查询结果集已保存到表中。 这样做的好处是,当您查询物化视图时,您正在查询一个表,该表也可能已建立索引。

此外,由于所有联接均已在物化视图刷新时解析,因此您只需支付一次联接费用(或与刷新物化视图一样频繁),而不是每次从物化视图中进行选择时支付联接费用。 此外,启用查询重写后,Oracle 可以优化从物化视图源中选择的查询,从而改为从物化视图中读取。 在将物化视图创建为聚合表形式或频繁执行查询的副本的情况下,这可以大大加快最终用户应用程序的响应时间。 缺点是,从物化视图返回的数据仅是上次刷新物化视图时的最新数据


物化视图可以设置为按照设定的计划手动刷新,或者基于数据库检测到基础表之一的数据更改。 物化视图可以通过与物化视图日志相结合来进行增量更新,物化视图日志充当基础表上的变更数据捕获源

物化视图最常用于数据仓库/商业智能应用程序,其中查询包含数千万行的大型事实表会导致查询响应时间延长,从而导致应用程序无法使用。


物化视图还有助于保证时刻的一致性,类似于快照隔离

Views

They evaluate the data in the tables underlying the view definition at the time the view is queried. It is a logical view of your tables, with no data stored anywhere else.

The upside of a view is that it will always return the latest data to you. The downside of a view is that its performance depends on how good a select statement the view is based on. If the select statement used by the view joins many tables, or uses joins based on non-indexed columns, the view could perform poorly.

Materialized views

They are similar to regular views, in that they are a logical view of your data (based on a select statement), however, the underlying query result set has been saved to a table. The upside of this is that when you query a materialized view, you are querying a table, which may also be indexed.

In addition, because all the joins have been resolved at materialized view refresh time, you pay the price of the join once (or as often as you refresh your materialized view), rather than each time you select from the materialized view. In addition, with query rewrite enabled, Oracle can optimize a query that selects from the source of your materialized view in such a way that it instead reads from your materialized view. In situations where you create materialized views as forms of aggregate tables, or as copies of frequently executed queries, this can greatly speed up the response time of your end user application. The downside though is that the data you get back from the materialized view is only as up to date as the last time the materialized view has been refreshed.


Materialized views can be set to refresh manually, on a set schedule, or based on the database detecting a change in data from one of the underlying tables. Materialized views can be incrementally updated by combining them with materialized view logs, which act as change data capture sources on the underlying tables.

Materialized views are most often used in data warehousing / business intelligence applications where querying large fact tables with thousands of millions of rows would result in query response times that resulted in an unusable application.


Materialized views also help to guarantee a consistent moment in time, similar to snapshot isolation.

霊感 2024-07-12 02:37:33

视图使用查询从基础表中提取数据。

物化视图是磁盘上包含查询结果集的表。

当使用应用了索引的标准视图不可行或不合适时,物化视图主要用于提高应用程序性能。 物化视图可以通过触发器或使用 ON COMMIT REFRESH 选项定期更新。 这确实需要一些额外的权限,但并不复杂。 ON COMMIT REFRESH 至少从 Oracle 10 起就已经存在。

A view uses a query to pull data from the underlying tables.

A materialized view is a table on disk that contains the result set of a query.

Materialized views are primarily used to increase application performance when it isn't feasible or desirable to use a standard view with indexes applied to it. Materialized views can be updated on a regular basis either through triggers or by using the ON COMMIT REFRESH option. This does require a few extra permissions, but it's nothing complex. ON COMMIT REFRESH has been in place since at least Oracle 10.

把时间冻结 2024-07-12 02:37:33

物化视图 - 磁盘上包含查询结果集的表

非物化视图 - 从基础表中提取数据的查询

Materialised view - a table on a disk that contains the result set of a query

Non-materiased view - a query that pulls data from the underlying table

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文