是否“联合所有”?物化视图占用空间吗?
提交时快速刷新联合所有物化视图(在 Oracle 中)是否复制所有基础数据,或者只是引用它?
如果这个物化视图确实复制了所有数据,那么无论如何都要执行以下操作:
create table3 as ( table1 union all table2 );
这样我就可以在表3上创建索引和物化视图日志,而表3只是对表1和表2的引用。
这样做的原因是我想要将以下内容放入物化视图中:
create materialized view mat1
refresh fast on commit
(
select data, count(*)
from (table1 union all table2)
group by data
);
但是上面的内容不能快速刷新。
但以下事情是有效的:
create materialized view mat1
refresh fast on commit
(
select data from table1
union all
select data from table2
);
create materialized view mat2
refresh fast on commit
(
select data, count(*)
from mat2
group by data
);
但我担心第一个物化视图不必要地复制所有数据。
Does a refresh fast on commit union all materialized view (in Oracle) copy all the underlying data, or does it just have a reference to it?
If this materialized view does copy all the data is there anyway to do the following:
create table3 as ( table1 union all table2 );
So that I can create indexes and materialized view logs on table3, and table 3 is just a reference to table 1 and table 2.
The reason for this is I want put the following in a materialized view:
create materialized view mat1
refresh fast on commit
(
select data, count(*)
from (table1 union all table2)
group by data
);
But the above isn't fast refreshable.
But the following sort of thing works:
create materialized view mat1
refresh fast on commit
(
select data from table1
union all
select data from table2
);
create materialized view mat2
refresh fast on commit
(
select data, count(*)
from mat2
group by data
);
But I'm concerned the first materialized view is unnecessarily replicating all the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
物化视图正是这样做的 - 它通过创建包含查询定义的数据的表来“物化”数据。您可以通过删除物化视图但将内容保留为表来演示这一点:
这将保留一个名为 xxx 的表,该表不再刷新。因此,您的 mat1 视图确实复制了两个表中的所有数据。
想想看 - 如果它只是“引用”联合,那么这将是一个常规视图,不是吗?在这种情况下,鱼和熊掌不可兼得。
编辑:
您无法在 complex 上进行快速刷新物化视图。诸如 COUNT 之类的聚合函数是导致视图变得复杂的因素之一。根据文档,UNION ALL 也是如此,所以我很惊讶你的 mat1 视图可以快速刷新。
A materialized view does exactly that - it "materializes" the data by creating a table containing the data defined by the query. You can demonstrate this by dropping the materialized view but preserving the contents as a table:
Which keeps a table named xxx that is no longer refreshed. So, your mat1 view does indeed duplicate all the data in both tables.
Think about it - if it just "referenced" the union, then it would be a regular view, no? You can't have your cake and eat it too in this case.
EDIT:
You cannot have a fast refresh on a complex materialized view. Aggregate functions such as COUNT are one of the things that cause a view to be complex. According to the docs, so does a UNION ALL, so I'm surprised your mat1 view is fast refreshable.
是的 - 它会复制所有数据,否则将无需任何刷新即可查看...
不确定,但您可以尝试:
Yes - it duplicates all data, otherwise it would be view with no need for any refreshing...
not sure but you could try: