[英]ORACLE: Fast Refresh on Materialized View not working with OUTER JOIN in some conditions
problem is simple.问题很简单。 I create TableParent and TableChild linked by foreign key.
我创建了通过外键链接的 TableParent 和 TableChild。 I create Materialized View Log for both.
我为两者创建物化视图日志。 I create Materialized View with fast refresh as left join from TableParent to TableChild.
我创建了从 TableParent 左连接到 TableChild 时快速刷新的物化视图。
Result is结果是
This is the code这是代码
-- Tables
CREATE TABLE TABLE_PARENT (
ID NUMBER(10, 0),
TEXT NVARCHAR2(50),
CONSTRAINT PK__TABLE1 PRIMARY KEY (ID)
);
CREATE TABLE TABLE_CHILD (
ID NUMBER(10, 0),
TEXT NVARCHAR2(50),
ID_PARENT NUMBER(10, 0),
CONSTRAINT PK__TABLE2 PRIMARY KEY (ID),
CONSTRAINT FK_TABLE_PARENT FOREIGN KEY (ID_PARENT)
REFERENCES TABLE_PARENT (ID)
);
-- Some record before materialized view creation
INSERT INTO TABLE_PARENT(ID, TEXT) VALUES(1, 'parent1');
INSERT INTO TABLE_CHILD(ID, TEXT, ID_PARENT) VALUES(1, 'child1', 1);
INSERT INTO TABLE_CHILD(ID, TEXT, ID_PARENT) VALUES(2, 'child2', 1);
-- Logs
CREATE MATERIALIZED VIEW LOG on TABLE_PARENT WITH PRIMARY KEY, ROWID;
CREATE MATERIALIZED VIEW LOG on TABLE_CHILD WITH PRIMARY KEY, ROWID;
-- Materialized View
CREATE MATERIALIZED VIEW TABLE_MV
REFRESH FAST ON COMMIT
AS
SELECT TABLE_PARENT.ID ID_PARENT,
TABLE_PARENT.TEXT TEXT_PARENT,
TABLE_CHILD.ID ID_CHILD,
TABLE_CHILD.TEXT TEXT_CHILD,
TABLE_PARENT.ROWID PARENT_ROWID,
TABLE_CHILD.ROWID CHILD_ROWID
FROM TABLE_PARENT,
TABLE_CHILD
WHERE TABLE_PARENT.ID = TABLE_CHILD.ID_PARENT (+);
At this point you can verify, first result此时你可以验证,第一个结果
INSERT INTO TABLE_CHILD(ID, TEXT, ID_PARENT) VALUES(3, 'child3', 1);
COMMIT;
SELECT * FROM TABLE_MV;
Then second result然后是第二个结果
UPDATE TABLE_CHILD SET TEXT = 'child33' WHERE ID = 3;
COMMIT;
SELECT * FROM TABLE_MV;
Then third result然后是第三个结果
INSERT INTO TABLE_PARENT(ID, TEXT) VALUES(2, 'parent2');
COMMIT;
SELECT * FROM TABLE_MV;
As you can see, Materialized View is not refreshed in the last case.正如您所看到的,在最后一种情况下,实体化视图并没有被刷新。 I can guess what could be the problem, but i want to see your explanations first.
我能猜到可能是什么问题,但我想先看看你的解释。 I hope i'm doing something wrong and it's not a kind of MView limitation problem.
我希望我做错了什么,这不是一种 MView 限制问题。 I'm working on Oracle 11g Release 11.2.0.1.0.
我正在研究 Oracle 11g 11.2.0.1.0 版。
Thanks much for your help非常感谢你的帮助
According to My Oracle Support - I found Bug 8856349: Fast refresh of OUTER join materialized view does not work根据 My Oracle Support - 我发现错误 8856349:快速刷新外部连接物化视图不起作用
Bug confirmed in 11.2.0.1, fixed in 11.2.0.2 base release.错误在 11.2.0.1 中确认,在 11.2.0.2 基础版本中修复。
The MOS note says that the workaround is to: MOS 说明说解决方法是:
Set the parameter "_mv_refresh_pkfk_relationship_opt"=false.
设置参数“_mv_refresh_pkfk_relationship_opt”=false。
You can change this parameter via the following:您可以通过以下方式更改此参数:
alter system set "_mv_refresh_pkfk_relationship_opt"=false scope=both;
However, as this is a hidden parameter, I would either consult Oracle Support (if you have access) as to any potential side effects of setting this parameter, or thoroughly test materialized view refreshes on a test system first before rolling this out to a production system.但是,由于这是一个隐藏参数,我会咨询 Oracle 支持(如果您有权访问)关于设置此参数的任何潜在副作用,或者先在测试系统上彻底测试物化视图刷新,然后再将其推广到生产环境系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.