物化檢視日誌與增量重新整理

renjixinchina發表於2014-06-13

一、    物化檢視日誌結構

Oracle 的物化檢視的快速重新整理要求必須建立物化檢視日誌,透過物化檢視日誌可以實現增量重新整理功能。

物化檢視日誌的名稱為MLOG$_面跟基表的名稱,如果表名的長度超過20位,則只取前20位,當截短後出現名稱重複時,Oracle會自動在物化檢視日誌名稱後面加上數字作為序號。

      物化檢視日誌在建立時有多種選項:可以指定為ROWIDPRIMARY KEYOBJECT ID幾種型別,同時還可以指定SEQUENCE或明確指定列名。上面這些情況產生的物化檢視日誌的結構都不相同。

 WITH 選項                

任何物化檢視都會包括的4列:
SNAPTIME$$:用於表示重新整理時間。
DMLTYPE$$:用於表示DML操作型別,I表示INSERTD表示DELETEU表示UPDATE
OLD_NEW$$:用於表示這個值是新值還是舊值。NEW)表示新值,OLD)表示舊值,U表示UPDATE操作。
CHANGE_VECTOR$$:表示修改向量,用來表示被修改的是哪個或哪幾個欄位。
如果WITH後面跟了ROWID,則物化檢視日誌中會包含:M_ROW$$:用來儲存發生變化的記錄的ROWID
如果WITH後面跟了PRIMARY KEY,則物化檢視日誌中會包含主鍵列。
如果WITH後面跟了OBJECT ID,則物化檢視日誌中會包含:SYS_NC_OID$:用來記錄每個變化物件的物件ID
如果WITH後面跟了SEQUENCE,則物化檢視日子中會包含:SEQUENCE$$:給每個操作一個SEQUENCE號,從而保證重新整理時按照順序進行重新整理。
如果WITH後面跟了一個或多個COLUMN名稱,則物化檢視日誌中會包含這些列。使用with column將自動新增主鍵,不能再新增primary key選項否則報如下錯誤:

SQL> create materialized view log on emp with(ename),primary key ;

 

create materialized view log on emp with(ename),primary key

 

ORA-00922: 選項缺失或無效

 

SQL> create materialized view log on emp with(ename) ;

 

Materialized view log created

OBJECT ID 僅針對object table

NEW VALUES選項

設定 including new values物化檢視日誌將舊值和新值,update將產生兩條記錄

二、    透過dbms_mview.explain_mview反向退出物化檢視日誌需要以上哪些選項

dbms_mview.explain_mview能幫助確認哪些是對物化檢視是可行的哪些是不可行的,比如像物化檢視是否可以增量重新整理。增量重新整理還需要什麼條件,比如物化檢視日誌需要新增哪些選項。

dbms_mview.explain_mview支援查詢語句,物化檢視檢視建立語句和物化檢視,對於複雜的查詢語句,可以先以BUILD DEFERRED方式建立,再使用dbms_mview.explain_mview進行分析

SQL> @$ORACLE_HOME/rdbms/admin/utlxmv.sql

 

Table created.

SQL> desc mv_capabilities_table

Name            Type           Nullable Default Comments

--------------- -------------- -------- ------- --------

STATEMENT_ID    VARCHAR2(30)   Y                        

MVOWNER         VARCHAR2(30)   Y                        

MVNAME          VARCHAR2(30)   Y                        

CAPABILITY_NAME VARCHAR2(30)   Y                        

POSSIBLE        CHAR(1)        Y                        

RELATED_TEXT    VARCHAR2(2000) Y                        

RELATED_NUM     NUMBER         Y                        

MSGNO           INTEGER        Y                        

MSGTXT          VARCHAR2(2000) Y                        

SEQ             NUMBER         Y  

SQL> exec dbms_mview.explain_mview('MV_EMP');

 

PL/SQL procedure successfully completed

 

SQL> commit;

 

Commit complete

 

SQL> select * from mv_capabilities_table;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SQL> select * from MV_CAPABILITIES_TABLE ;

 

STATEMENT_ID                   MVOWNER                        MVNAME                         CAPABILITY_NAME                POSSIBLE RELATED_TEXT                                                                     RELATED_NUM                                   MSGNO MSGTXT                                                                                  SEQ

------------------------------ ------------------------------ ------------------------------ ------------------------------ -------- -------------------------------------------------------------------------------- ----------- --------------------------------------- -------------------------------------------------------------------------------- ----------

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            PCT                            Y                                                                                                                                                                                                                                       1

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_COMPLETE               Y                                                                                                                                                                                                                                    1002

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST                   N                                                                                                                                                                                                                                    2003

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REWRITE                        N                                                                                                                                                                                                                                    3004

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            PCT_TABLE                      Y        TCHOSPDAYDETAILH                                                                         434                                                                                                                                4005

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_INSERT      N        EOSADMIN.TCHOSPDAYDETAILH                                                                                                       2081 mv log does not have all necessary columns                                             5006

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_INSERT      N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                                5007

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N        FSCALESELFEE                                                                             393                                    2143 SUM(expr) without COUNT(expr)                                                          6008

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N        FOVERPRICESELFEE                                                                         343                                    2143 SUM(expr) without COUNT(expr)                                                          6009

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N        SELFPAYMONEY                                                                             227                                    2143 SUM(expr) without COUNT(expr)                                                          6010

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N        TOTALMONEY                                                                               193                                    2143 SUM(expr) without COUNT(expr)                                                          6011

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N        SUMAMOUNT                                                                                162                                    2143 SUM(expr) without COUNT(expr)                                                          6012

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N                                                                                                                                        2146 see the reason why REFRESH_FAST_AFTER_INSERT is disabled                               6013

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ONETAB_DML  N                                                                                                                                        2143 SUM(expr) without COUNT(expr)                                                          6014

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ANY_DML     N        EOSADMIN.TCHOSPDAYDETAILH                                                                                                       2165 mv log does not have sequence #                                                        7015

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_AFTER_ANY_DML     N                                                                                                                                        2161 see the reason why REFRESH_FAST_AFTER_ONETAB_DML is disabled                           7016

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REFRESH_FAST_PCT               N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                                8017

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REWRITE_FULL_TEXT_MATCH        N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                                9018

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REWRITE_PARTIAL_TEXT_MATCH     N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                               10019

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REWRITE_GENERAL                N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                               11020

 

STATEMENT_ID                   MVOWNER                        MVNAME                         CAPABILITY_NAME                POSSIBLE RELATED_TEXT                                                                     RELATED_NUM                                   MSGNO MSGTXT                                                                                  SEQ

------------------------------ ------------------------------ ------------------------------ ------------------------------ -------- -------------------------------------------------------------------------------- ----------- --------------------------------------- -------------------------------------------------------------------------------- ----------

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            REWRITE_PCT                    N                                                                                                                                        2164 the materialized view is BUILD DEFERRED                                               12021

                               EOSADMIN                       MV_TCHOSPDAYDETAILH            PCT_TABLE_REWRITE              Y        TCHOSPDAYDETAILH                                                                         434                                                                                                                               13022

 

22 rows selected

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-1182449/,如需轉載,請註明出處,否則將追究法律責任。

相關文章