任何数据库的主要组成部分是其表格,在为了使数据可访问性定制化的情况下,有视图的概念。换句话说,通过表格的视图,我们可以限制任何用户只能访问他应该访问的数据。现在基于视图的特点和特性,我们可以区分视图和物化视图。
In this article, we will discuss the important differences between Views and Materialized Views in SQL. But before, let’s have look into the basics of views and materialized view individually for better understanding of the differences between them.
Views are the logical and virtual copy of a table that is created by executing a ‘select query’ statement. The views are not stored anywhere on the disk. Thus, every time, a query has to be executed when certain data is required. But, the query expression is stored on the disk.
视图没有与之相关的存储/更新成本。视图是根据特定的架构设计的,这意味着有一个SQL标准来定义视图。视图在数据需要被不经常访问,但数据经常更新时使用。
Materialized views are the views whose contents are computed and stored. Materialized views are also a logical virtual table, but in this case the result of the query is stored in the table or the disk. The performance of the materialized views is better than normal views. This is because the data is stored on the disk.
有时,物化视图也被称为“索引视图”,因为查询后创建的表被索引,可以更快、更高效地访问。当数据需要频繁访问且表中的数据不经常更新时,会使用物化视图。
The following table highlights the important differences between Views and Materialized Views −
Key | Views | Materialized Views |
---|---|---|
Definition | 从技术上讲,表的视图是通过“select查询”创建的表的逻辑虚拟副本,但结果不会存储在磁盘上。 Whenever we need the data, we need to fire the query. So, the user always gets the updated or latest data from the original tables. |
Materialized views(物化视图)也是数据的逻辑虚拟副本,由“select查询”驱动,但查询结果将存储在表格或磁盘中。 |
Storage | In Views the resulting tuples of the query expression is not get storing on the disk only the query expression is stored on the disk. | 在物化视图的情况下,查询表达式和查询结果的元组都存储在磁盘上。 |
查询执行 | 查询表达式存储在磁盘上,而不是其结果,因此每次用户尝试从中提取数据时,查询表达式都会被执行,以便用户每次都能获得最新的更新值。 | The result of the query gets stored on the disk and hence the query expression does not get executed every time when user try to fetch the data so that user will not get the latest updated value if it get changed in database. |
成本效益 | 由于Views没有与之相关的存储成本,因此它们也没有与之相关的更新成本。 | Materialized Views有与之相关的存储成本,因此也有与之相关的更新成本。 |
Design | Views in SQL are designed with a fixed architecture approach due to which there is an SQL standard of defining a view. | Materialized Views in SQL are designed with a generic architecture approach, so there is no SQL standard for defining it, and its functionality is provided by some databases systems as an extension. |
使用情况 | Views are generally used when data is to be accessed infrequently and data in table get updated on frequent basis. | 当数据需要频繁访问且表中的数据不经常更新时,使用Materialized Views。 |
在SQL中,视图(Views)和物化视图(Materialized Views)是非常不同的。当数据很少被访问,而表中的数据经常更新时,使用视图。相反,当数据需要频繁访问,而表中的数据不经常更新时,使用物化视图。
以上就是SQL 中视图和物化视图的区别的详细内容,更多请关注php中文网其它相关文章!
已抢64995个
抢已抢27616个
抢已抢14982个
抢已抢7451个
抢已抢9404个
抢已抢19017个
抢