gpt4 book ai didi

sql - 添加约束时物化 View "invalidates"

转载 作者:行者123 更新时间:2023-12-02 04:26:17 26 4
gpt4 key购买 nike

我在 Oracle 10.2.0.50 数据库中有一个如下所示的物化 View :

CREATE MATERIALIZED VIEW mv_cis
NOCACHE
NOLOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH FORCE
ON DEMAND
WITH PRIMARY KEY AS
SELECT component_id, ctn, visible_tag, facility,
SYSTEM, elev, parent, room_number,
remarks, safety_class, seismic, quality_level
FROM v_cis;

非常简单的东西。创建此物化 View 后,它是有效的并填充了我期望的数据。然后我向其表添加一个约束,如下所示:

ALTER TABLE mv_cis
MODIFY ctn CONSTRAINT chk_cis_ctn_null NOT NULL ENABLE VALIDATE;

这按预期工作,表获得了新的约束,世界上一切都很好。

但是,我随后查看了物化 View (使用 Toad for Oracle 12),它显示无效。寻找user_mviews表显示COMPILE_STATE其中是NEED_COMPILESTALENESSUNDEFINED 。所以我运行:

ALTER MATERIALIZED VIEW mv_cis COMPILE;

没有变化。奇怪的是,刷新 View 仍然有效,但它显示无效,这让我抓狂,并且使我的测试计划失败,即使一切看起来都井然有序。那么,我错过了什么?

最佳答案

我要说的是错误,您应该检查 Metalink 和/或提交 SR。

这是 11.2 场景。当然,这很简单。如果您愿意,我可以使用您的实际 DDL 进行尝试。

SQL> create table base(id integer primary key, name varchar2(100) not null,
2 description varchar2(400));

Table created.

SQL> desc base
Name Null? Type
----------------------------------------- -------- ----------------------------

ID NOT NULL NUMBER(38)
NAME NOT NULL VARCHAR2(100)
DESCRIPTION VARCHAR2(400)

SQL> create materialized view mv_base build immediate refresh force on demand
2 with primary key as
3 select id, name, description from base
4 ;

Materialized view created.

SQL> desc mv_base
Name Null? Type
----------------------------------------- -------- ----------------------------

ID NOT NULL NUMBER(38)
NAME NOT NULL VARCHAR2(100)
DESCRIPTION VARCHAR2(400)

SQL> alter table mv_base modify description constraint chk_not_null not null
2 enable validate;

Table altered.

SQL> desc mv_base
Name Null? Type
----------------------------------------- -------- ----------------------------

ID NOT NULL NUMBER(38)
NAME NOT NULL VARCHAR2(100)
DESCRIPTION NOT NULL VARCHAR2(400)

现在检查是否需要编译。

SQL> select mview_name, compile_state, staleness from user_mviews;

MVIEW_NAME COMPILE_STATE STALENESS
------------------------------ ------------------- -------------------
MV_BASE NEEDS_COMPILE NEEDS_COMPILE

SQL> alter materialized view mv_base compile;

Materialized view altered.

SQL> select mview_name, compile_state, staleness from user_mviews;

MVIEW_NAME COMPILE_STATE STALENESS
------------------------------ ------------------- -------------------
MV_BASE VALID FRESH

关于sql - 添加约束时物化 View "invalidates",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26537006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com