无法使用连接和分组创建实体化视图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使用连接和分组创建实体化视图相关的知识,希望对你有一定的参考价值。
我正在尝试使用左外连接和group by创建一个物化视图。
我收到这个错误:
错误报告 - ORA-12015:无法从复杂查询创建快速刷新物化视图12015. 00000 - “无法从复杂查询创建快速刷新物化视图”
原因:复杂查询不支持ROWID和主键约束。
操作:使用REFRESH FORCE或REFRESH COMPLETE选项重新发出该命令,或创建一个简单的物化视图。
代码:
CREATE MATERIALIZED VIEW CSPRD.MV_LLATTRDATA_MAX_VERSIONS
PARALLEL 16
USING INDEX
REFRESH
NEXT trunc(SYSDATE, 'hh') + 1/24
FAST
WITH ROWID
USING DEFAULT LOCAL ROLLBACK SEGMENT
ENABLE QUERY REWRITE
AS
SELECT /*+ PARALLEL(16) */
AD.ID,
AD.DEFID,
AD.ATTRID,
MAX(AD.VERNUM) MAX_VERNUM,
MAX(AD.DEFVERN) MAX_DEFVERN,
AD.ROWID,
DT.ROWID
FROM csprd.mv_llattrdata_shrunk_v1 AD, MV_DTREECORE_SHRUNK_V2 DT
WHERE AD.ID = DT.DATAID(+)
GROUP BY AD.ID, AD.DEFID, AD.ATTRID;
答案
并行的东西表明这些是大表。所以我建议你使用并行的“预建表”来实例化它们,然后切换到串行以进行快速刷新 - 因为在快速刷新期间重载并行似乎是反直觉的。
确保您的mview日志包含正确类型的信息 - 然后应该可以进行外部联接。
SQL> create table t as select * from dba_objects where object_id is not null;
SQL> alter table t add constraint t_pk primary key ( object_id ) ;
SQL> create table t1 as select * from dba_objects where object_id is not null;
SQL> alter table t1 add constraint t1_pk primary key ( object_id ) ;
SQL> create materialized view log on t with (object_type), sequence, rowid including new values;
SQL> create materialized view log on t1 with (object_type), sequence, rowid including new values;
SQL>
SQL> --
SQL> -- single table
SQL> --
SQL> create materialized view mv
2 REFRESH FAST
3 as
4 SELECT
5 object_type,
6 max(object_id) oid
7 FROM t
8 GROUP BY object_type;
Materialized view created.
SQL>
SQL> --
SQL> -- simple join
SQL> --
SQL> drop materialized view mv;
Materialized view dropped.
SQL> create materialized view mv
2 REFRESH FAST
3 as
4 SELECT
5 t.object_type,
6 max(t.object_id) oid
7 FROM t, t1
8 where t1.object_id = t.object_id
9 GROUP BY t.object_type;
Materialized view created.
SQL>
SQL> --
SQL> -- outer join
SQL> --
SQL> drop materialized view mv;
Materialized view dropped.
SQL> create materialized view mv
2 REFRESH FAST
3 as
4 SELECT
5 t.object_type,
6 t1.object_type o2type,
7 max(t.object_id) oid
8 FROM t, t1
9 where t.object_id = t1.object_id(+)
10 GROUP BY t.object_type, t1.object_type;
Materialized view created.
SQL>
您可以使用DBMS_MVIEW.EXPLAIN_MVIEW来提前评估mview的各种功能。
以上是关于无法使用连接和分组创建实体化视图的主要内容,如果未能解决你的问题,请参考以下文章