13

Oracle 10g で次のコードを実行すると:

drop materialized view test4;
drop materialized view test3;
drop table test2;
drop table test1;

create table test1
(
  x1 varchar2(1000),
  constraint test1_pk primary key (x1)
);

create materialized view log on test1 with sequence;

create table test2
(
  x2 varchar2(1000),
  constraint test2_pk primary key (x2)
);

create materialized view log on test2 with sequence;

create materialized view test3
refresh complete on demand 
as
(
  select x1 from test1
  union all
  select null from dual where 0 = 1
);

alter table test3 add constraint test3_pk primary key (x1);

create materialized view log on test3 with sequence;

create materialized view test4
refresh fast on commit
as
(
  select t1.rowid as rid1, t2.rowid as rid2, t1.x1 u1, t2.x2
  from test3 t1, test2 t2
  where t1.x1 = t2.x2
);

マテリアライズド ビューを作成しようとすると、次のエラーが発生しますtest4

SQL Error: ORA-12053: this is not a valid nested materialized view  
12053. 00000 -  "this is not a valid nested materialized view"  
*Cause:    The list of objects in the FROM clause of the definition of this  
           materialized view had some dependencies upon each other.  
*Action:   Refer to the documentation to see which types of nesting are valid.

「FROM 句」内のオブジェクトがどのように相互に依存しているかがわかりません。

これを機能させるにはどうすればよいですか?現在、考えられる唯一の回避策test3は、通常のテーブルに置き換えて、データを手動で削除および更新することです。このアプローチは機能しますが、ちょっとしたハックのように思えます。

別の方法として (そしておそらく望ましいことですが)、2 つのテーブルを持つことができ、それらをマテリアライズド ビューに結合できる例を見てみたいと思います。ここでは、ベース テーブルの 1 つが一括更新されます (マテリアライズド ビューに反映する必要はありません)。 )しかし、他の更新はマテリアライズドビューに反映される必要があります(つまり、「半分」fast refresh on commitと半分のようなものですcomplete refresh on demand)。を使用してみましrefresh forceたが、使用するEXECUTE DBMS_MVIEW.EXPLAIN_MVIEW()と、コミット時にフラッシュが更新されているという証拠が見つかりませんでした。union allsでもこれをやりたいと思います。

4

3 に答える 3

3

次のように、test4 マテリアライズド ビューを高速に更新できます。

SQL> create table test1
  2  ( x1 varchar2(1000)
  3  , constraint test1_pk primary key (x1)
  4  )
  5  /

Table created.

SQL> create materialized view log on test1 with rowid
  2  /

Materialized view log created.

SQL> create table test2
  2  ( x2 varchar2(1000)
  3  , constraint test2_pk primary key (x2)
  4  )
  5  /

Table created.

SQL> create materialized view log on test2 with rowid
  2  /

Materialized view log created.

SQL> create materialized view test4
  2  refresh fast on commit
  3  as
  4    select t1.rowid as rid1
  5         , t2.rowid as rid2
  6         , t1.x1 u1
  7         , t2.x2
  8      from test1 t1
  9         , test2 t2
 10     where t1.x1 = t2.x2
 11  /

Materialized view created.

SQL> insert into test1 values ('hello')
  2  /

1 row created.

SQL> insert into test2 values ('hello')
  2  /

1 row created.

SQL> commit
  2  /

Commit complete.

SQL> select * from test4
  2  /

RID1               RID2
------------------ ------------------
U1
---------------------------------------------
X2
---------------------------------------------
AAATU5AAEAAAssfAAA AAATU8AAEAAAssvAAA
hello
hello


1 row selected.

ネストされた MV が機能するためには、基になる MV を基本的な MV にすることはできないため、このケースは機能しません。これは最初は奇妙に聞こえますが、test3 で行ったようなトリックが必要です。また、結合 MV を機能させるには、基になるテーブルのマテリアライズド ビュー ログを WITH ROWID で作成する必要があります。

高速更新可能なマテリアライズド ビューのエラーについて私が書いた一連のブログ記事を参照してください。ほとんどすべての制限について説明しています。

Basic MV's
Join MV's
Aggregate MV's
Union all MV's
Nested MV's
MV_CAPABILITIES_TABLE
Summary

よろしく、
ロブ。


追加: 2011 年 9 月 29 日

以下は、ネストされた MV の例で、test2 でもユニオン オール トリックを使用しています。

SQL> create table test1
  2  ( x1 varchar2(1000)
  3  , constraint test1_pk primary key (x1)
  4  )
  5  /

Table created.

SQL> create materialized view log on test1 with rowid
  2  /

Materialized view log created.

SQL> create table test2
  2  ( x2 varchar2(1000)
  3  , constraint test2_pk primary key (x2)
  4  )
  5  /

Table created.

SQL> create materialized view log on test2 with rowid
  2  /

Materialized view log created.

SQL> create materialized view test2_mv
  2  refresh fast on commit
  3  as
  4  select rowid rid
  5       , x2
  6       , 'A' umarker
  7    from test2
  8   union all
  9  select rowid
 10       , x2
 11       , 'B'
 12    from test2
 13   where 1=0
 14  /

Materialized view created.

SQL> alter table test2_mv add constraint test2_mv_pk primary key(x2)
  2  /

Table altered.

SQL> create materialized view log on test2_mv with rowid
  2  /

Materialized view log created.

SQL> create materialized view test3
  2  refresh fast on commit
  3  as
  4  select rowid rid
  5       , x1
  6       , 'A' umarker
  7    from test1
  8   union all
  9  select rowid
 10       , x1
 11       , 'B'
 12    from test1
 13   where 0 = 1
 14  /

Materialized view created.

SQL> alter table test3 add constraint test3_pk primary key (x1)
  2  /

Table altered.

SQL> create materialized view log on test3 with rowid
  2  /

Materialized view log created.

SQL> create materialized view test4
  2  refresh fast on commit
  3  as
  4    select t1.rowid as rid1
  5         , t2.rowid as rid2
  6         , t1.x1 u1
  7         , t2.x2
  8      from test3 t1
  9         , test2_mv t2
 10     where t1.x1 = t2.x2
 11  /

Materialized view created.

SQL> insert into test1 values ('hello')
  2  /

1 row created.

SQL> insert into test2 values ('hello')
  2  /

1 row created.

SQL> commit
  2  /

Commit complete.

SQL> select * from test4
  2  /

RID1               RID2
------------------ ------------------
U1
---------------------------------------------------
X2
---------------------------------------------------
AAATXbAAEAAAstdAAA AAATXXAAEAAAstNAAA
hello
hello


1 row selected.

お役に立てれば!

于 2011-09-26T17:24:54.330 に答える
2

オラクルより引用

多層マテリアライズド ビューの使用に関する制限事項

マスター マテリアライズド ビューとマテリアライズド ビューに基づくマテリアライズド ビューの両方が、次の条件を満たす必要があります。

  • 主キーのマテリアライズド ビューであること
  • 9.0.1 以上の互換性レベルのデータベースに存在する

注意: COMPATIBLE 初期化パラメータは、データベースの互換性レベルを制御します。

ただし、解決策を試してみます。戻ってきます。

更新:申し訳ありませんが成功しませんでした。制限が多すぎます:)

于 2011-09-20T06:54:09.927 に答える
0

Oracleのドキュメントによると、あなたは運が悪いかもしれません:

http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/basicmv.htm#i1006734

マテリアライズド ビューでネストされたマテリアライズド ビューを作成できますが、すべての親およびベース マテリアライズド ビューには結合または集計が含まれている必要があります。マテリアライズド ビューの定義クエリに結合または集計が含まれていない場合は、ネストできません。マテリアライズド ビューが定義されている基礎となるすべてのオブジェクト (マテリアライズド ビューまたはテーブル) には、マテリアライズド ビュー ログが必要です。基礎となるすべてのオブジェクトは、テーブルであるかのように扱われます。さらに、マテリアライズド ビューの既存のすべてのオプションを使用できます。

于 2011-09-26T15:14:57.683 に答える