是否“联合所有”?物化视图占用空间吗?

发布于 2024-12-09 19:58:46 字数 737 浏览 0 评论 0原文

提交时快速刷新联合所有物化视图(在 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 技术交流群。

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

发布评论

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

评论(2

彩扇题诗 2024-12-16 19:58:46

物化视图正是这样做的 - 它通过创建包含查询定义的数据的表来“物化”数据。您可以通过删除物化视图但将内容保留为表来演示这一点:

DROP MATERIALIZED VIEW xxx PRESERVE TABLE;

这将保留一个名为 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:

DROP MATERIALIZED VIEW xxx PRESERVE 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.

岛歌少女 2024-12-16 19:58:46

是的 - 它会复制所有数据,否则将无需任何刷新即可查看...

不确定,但您可以尝试:

create materialized view mat1
refresh fast on commit
(
  select data, sum (c) from
  (
  select 1 x, data, count(*) c from table1 group by 1, data
  union
  select 2, data, count(*) from table1 group by 2, data
  ) group by data
);

Yes - it duplicates all data, otherwise it would be view with no need for any refreshing...

not sure but you could try:

create materialized view mat1
refresh fast on commit
(
  select data, sum (c) from
  (
  select 1 x, data, count(*) c from table1 group by 1, data
  union
  select 2, data, count(*) from table1 group by 2, data
  ) group by data
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文