OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.6.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.6.0
    iconOceanBase Database
    SQL - V 4.6.0
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Materialized view logs

    Last Updated:2026-05-07 11:26:25  Updated
    Share
    What is on this page
    Limitations
    Privileges
    Schema definition of a materialized view log
    Operations on existing materialized view logs
    Impact of base table operations on materialized view logs
    DML operations on the base table
    DDL operations on the base table
    Create a materialized view log
    Privilege requirements
    Syntax
    Modify a materialized view log
    Privilege requirements
    Syntax
    Drop a materialized view log
    Considerations
    Privilege requirements
    Syntax
    Example
    References

    folded

    Share

    A materialized view log (mlog) records incremental updates to the base table to support fast refreshes of materialized views. An mlog is a record table that tracks changes in the base table and applies these changes to the corresponding materialized view to enable fast refreshes.

    If the automatic management of materialized view logs feature is enabled, OceanBase Database automatically creates or updates the mlog definition when you create a materialized view with incremental refresh or real-time refresh. For more information about the automatic management of materialized view logs, see Automatic management of materialized view logs.

    Limitations

    • You can create a materialized view log only on a regular table or a materialized view.
    • A regular table can be bound to only one materialized view log.
    • If a transaction is running on the base table when you create a materialized view log, the creation operation will be blocked until the transaction ends.
    • A materialized view log supports LOB columns, but only supports inline storage for LOB data. For more information about LOB types, see LOB types.
    • A materialized view log does not support the following four types of data: JSON, XML, GIS, and UDT.
    • A materialized view log does not support generated columns (including virtual and non-virtual columns).
    • A materialized view log does not support specifying partitions. The partitions of the materialized view log are bound to the partitions of the base table.
    • The maximum length of a materialized view log name is the same as that of a regular table, which cannot exceed 64 characters. Since the name of a materialized view log is prefixed with mlog$_, the name of the base table for creating a materialized view log cannot exceed 58 characters.
    • A materialized view log does not support table-level recovery.
    • A materialized view log will not be moved to the recycle bin when it is deleted.
    • A materialized view log does not support the ALTER operation after it is created.
    • You cannot create an index on a materialized view log.
    • You cannot perform DML operations on a materialized view log. An error will be returned.

    Privileges

    • To create a materialized view log, you must have the SELECT and CREATE TABLE privileges on the base table.
    • To modify a materialized view log, you must have the ALTER privilege on the base table.
    • To drop a materialized view log, you must have the DROP TABLE privilege.
    • You can only grant the SELECT privilege on a materialized view log. Other DML operations are not supported.

    Schema definition of a materialized view log

    A table can have only one materialized view log. The schema name of the materialized view log is mlog$_table, where table is the name of the base table.

    The schema definition of a materialized view log is as follows:

    Column
    Type
    Description
    sequence$$ in64_t An auto-increment column that serves as the primary key of the materialized view log (mlog).

    Note

    The primary key of mlog consists of the primary key of the base table, all partition keys (if any), and the auto-increment column sequence$$, forming a composite primary key.

    primary key Follows the base table If the base table has a primary key, the primary key columns of the base table (which may include multiple columns if it is a composite primary key) are recorded in mlog.
    dmltype$$ char(1) Records the DML type. The value can be I, D, or U, which respectively represent INSERT, DELETE, and UPDATE.
    old_new$$ char(1) Marks the old and new values in an UPDATE statement. An UPDATE statement will write two rows of data to the materialized view log: one row for the old value before the UPDATE operation and one row for the new value after the UPDATE operation. The old value is marked with O and the new value is marked with N.
    column 1 Follows the base table The first regular column of the base table.
    ... N/A N/A
    column N Follows the base table The Nth regular column of the base table.
    ora_rowscn N/A A pseudo column that records a hidden column in the storage layer. It can be read.
    m_row$$ uint64_t This column is recorded in mlog only when the base table does not have a primary key. mlog must contain the primary key columns of the base table. If the base table does not have a primary key, the name of the hidden primary key in mlog is M_ROW$$.

    Operations on existing materialized view logs

    • You can directly query the schema and data of the materialized view log.
    • You can execute the PURGE operation on a materialized view log of a base table by using DBMS_MVIEW.PURGE_LOG(table_name).
    • If the size of a materialized view log exceeds the available disk capacity, an error will be returned. In this case, you must delete the materialized view log and recreate it before you can use it again.

    Impact of base table operations on materialized view logs

    DML operations on the base table

    The definition of a materialized view log is to record DML operations on the base table. Therefore, INSERT, DELETE, and UPDATE operations on the base table will be recorded in the materialized view log. The specific operations are as follows:

    • When you execute an INSERT operation on the base table, each row of data inserted will also be recorded in the materialized view log. The dmltype$$ column of the corresponding record is I, and the old_new$$ column is N.
    • When you execute a DELETE operation on the base table, each row of data deleted will also be recorded in the materialized view log. The dmltype$$ column of the corresponding record is D, and the old_new$$ column is O.
    • When you execute an UPDATE operation on the base table, each row of data modified will generate two records in the materialized view log. The first record is the old value of the row before the UPDATE operation. The dmltype$$ column of the record is U, and the old_new$$ column is O. The second record is the new value of the row after the UPDATE operation. The dmltype$$ column of the record is U, and the old_new$$ column is N.

    DDL operations on the base table

    Before you delete the base table, you must delete the corresponding materialized view log. Otherwise, an error will be returned. This is because a materialized view log is bound to the base table. Therefore, you cannot delete the base table while retaining the materialized view log.

    For more information about the DDL operations supported by the base table, see Online DDL and offline DDL operations.

    Create a materialized view log

    Note

    OceanBase Database does not support specifying partitions for mlogs. The partitions of an mlog are bound to those of the base table.

    Privilege requirements

    You must have the CREATE TABLE and SELECT privileges on the base table to create a materialized view log. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode.

    Syntax

    The SQL statement for creating a materialized view log is as follows:

    CREATE [OR REPLACE] MATERIALIZED VIEW LOG ON [database.] table_name
        [parallel_clause]
        [with_clause]
        [mv_log_purge_clause];
    

    Parameters:

    • OR REPLACE: optional. If you specify this clause, the system creates a new materialized view log with the same name as the existing one and replaces the existing one with the new one. The existing materialized view log is not deleted during the replacement. The read and write operations on the materialized view and base table are not affected.
    • table_name: the name of the base table.
    • parallel_clause: optional. Specifies the parallelism of the materialized view log cleanup.
    • with_clause: optional. Specifies the auxiliary columns in the materialized view log.
    • mv_log_purge_clause: optional. Specifies the time when the system clears the data in the materialized view log.

    For more information about the parameters in the syntax, see CREATE MATERIALIZED VIEW LOG.

    Here is an example:

    1. Create a table named tbl1.

      CREATE TABLE tbl1 (col1 INT, col2 VARCHAR(20), col3 INT, PRIMARY KEY(col1, col3))
          PARTITION BY HASH(col3) PARTITIONS 10;
      
    2. Create a materialized view log on the tbl1 table. Set the parallelism of the materialized view log to 5, record the changes to the col2 column, and record the values before and after the changes. Set the system to clear the expired materialized view log records every 1 day starting from the current date.

      CREATE MATERIALIZED VIEW LOG ON tbl1 
        PARALLEL 5 
        WITH SEQUENCE(col2) INCLUDING NEW VALUES
        PURGE START WITH sysdate() NEXT sysdate() + interval 1 day;
      
    3. Query the information about the materialized view log on the tbl1 table.

      DESC mlog$_tbl1;
      

      The returned result is as follows:

      +------------+-------------+------+------+---------+-------+
      | Field      | Type        | Null | Key  | Default | Extra |
      +------------+-------------+------+------+---------+-------+
      | col1       | int(11)     | NO   | PRI  | NULL    |       |
      | col2       | varchar(20) | YES  |      | NULL    |       |
      | col3       | int(11)     | NO   | PRI  | NULL    |       |
      | SEQUENCE$$ | bigint(20)  | NO   | PRI  | NULL    |       |
      | DMLTYPE$$  | varchar(1)  | YES  |      | NULL    |       |
      | OLD_NEW$$  | varchar(1)  | YES  |      | NULL    |       |
      +------------+-------------+------+------+---------+-------+
      6 rows in set
      

    Modify a materialized view log

    Privilege requirements

    You must have the ALTER privilege on the base table to execute the ALTER MATERIALIZED VIEW LOG statement. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode.

    Syntax

    The SQL statement for modifying a materialized view log is as follows:

    ALTER MATERIALIZED VIEW LOG ON [database.]table_name alter_mlog_action_list;
    
    alter_mview_action_list:
        alter_mlog_action [, alter_mlog_action ...]
    
    alter_mlog_action:
        parallel_clause
        | PURGE [[START WITH expr] [NEXT expr]]
        | LOB_INROW_THRESHOLD [=] integer
    
    parallel_clause:
        NOPARALLEL 
        | PARALLEL integer
    

    Parameters:

    • database.: optional. The name of the database where the materialized view is located. If you do not specify this parameter, the base table is assumed to be in the current database.
    • table_name: the name of the base table.
    • alter_mlog_action_list: the list of operations that can be performed on the materialized view log. You can specify multiple operations, separated by commas (,).

    For more information about the parameters in the syntax, see ALTER MATERIALIZED VIEW LOG.

    Here is an example:

    1. Create a table named test_tbl1.

      CREATE TABLE test_tbl1 (col1 INT PRIMARY KEY, col2 VARCHAR(20), col3 INT, col4 TEXT);
      
    2. Create a materialized view log on the test_tbl1 table.

      CREATE MATERIALIZED VIEW LOG ON test_tbl1 
          WITH SEQUENCE(col2, col3, col4) INCLUDING NEW VALUES;
      
    3. Set the parallelism of the materialized view log on the test_tbl1 table to 5.

      ALTER MATERIALIZED VIEW LOG ON test_tbl1 PARALLEL 5;
      
    4. Set the system to clear the expired materialized view log records every 1 day starting from the current date on the test_tbl1 table.

      ALTER MATERIALIZED VIEW LOG ON test_tbl1
          PURGE START WITH sysdate() NEXT sysdate() + INTERVAL 1 DAY;
      
    5. Set the LOB inline storage length threshold of the materialized view log on the test_tbl1 table.

      ALTER MATERIALIZED VIEW LOG ON test_tbl1 LOB_INROW_THRESHOLD 10000;
      

    Drop a materialized view log

    Considerations

    • If a base table is involved in a running transaction, the drop operation is blocked until the transaction is completed.
    • When you drop a materialized view log, the corresponding materialized view is not moved to the recycle bin.

    Privilege requirements

    You must have the DROP TABLE privilege to drop a materialized view log. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode.

    Syntax

    The SQL statement for dropping a materialized view log is as follows:

    DROP MATERIALIZED VIEW LOG ON [database.] table;
    

    Parameters:

    • database.: optional. The name of the database where the base table of the materialized view log is located. If you do not specify this parameter, the base table is assumed to be in your own database.
    • table: the name of the base table.

    Here is an example:

    Drop the materialized view log on the tbl1 table.

    DROP MATERIALIZED VIEW LOG ON tbl1;
    

    Example

    This example demonstrates how to create a regular table, a materialized view log, and an incrementally refreshed materialized view. It also covers how to drop a materialized view log and an incrementally refreshed materialized view.

    1. Create a table named test_tbl1.

      CREATE TABLE test_tbl1 (col1 INT PRIMARY KEY, col2 INT, col3 INT);
      
    2. Create a materialized view log on the test_tbl1 table, specifying the use of a sequence number (SEQUENCE) to identify changed data. The columns to be recorded include col2 and col3.

      CREATE MATERIALIZED VIEW LOG ON test_tbl1
          WITH SEQUENCE (col2, col3) INCLUDING NEW VALUES;
      
    3. Create a materialized view named mv_test_tbl1, defining it for incremental refresh with an automatic refresh interval of 5 minutes. In the query section, specify grouping by the col2 column from the test_tbl1 table and calculate the number of records in each group (cnt), the number of non-null records in the col3 column (cnt_col3), and the sum of the col3 column (sum_col3) as the results of the materialized view.

      CREATE MATERIALIZED VIEW mv_test_tbl1
        REFRESH FAST ON DEMAND
        START WITH sysdate() NEXT sysdate() + interval 5 minute
        AS SELECT col2, COUNT(*) cnt, COUNT(col3) cnt_col3, SUM(col3) sum_col3 
          FROM test_tbl1 
          GROUP BY col2;
      
    4. View the materialized view log information for the test_tbl1 table.

      SELECT * FROM oceanbase.DBA_MVIEW_LOGS WHERE MASTER = 'test_tbl1';
      

      The returned result is as follows:

      +-----------+-----------+-----------------+-------------+--------+-------------+-----------+----------------+----------+--------------------+--------------------+----------------+-------------+----------------+---------------------+-------------------+-----------------+------------------+-------------+-----------+-----------------+
      | LOG_OWNER | MASTER    | LOG_TABLE       | LOG_TRIGGER | ROWIDS | PRIMARY_KEY | OBJECT_ID | FILTER_COLUMNS | SEQUENCE | INCLUDE_NEW_VALUES | PURGE_ASYNCHRONOUS | PURGE_DEFERRED | PURGE_START | PURGE_INTERVAL | LAST_PURGE_DATE     | LAST_PURGE_STATUS | NUM_ROWS_PURGED | COMMIT_SCN_BASED | STAGING_LOG | PURGE_DOP | LAST_PURGE_TIME |
      +-----------+-----------+-----------------+-------------+--------+-------------+-----------+----------------+----------+--------------------+--------------------+----------------+-------------+----------------+---------------------+-------------------+-----------------+------------------+-------------+-----------+-----------------+
      | test_db   | test_tbl1 | mlog$_test_tbl1 | NULL        | NO     | YES         | NO        | YES            | YES      | YES                | NO                 | NO             | NULL        | NULL           | 2025-09-03 14:13:06 |                 0 |               0 | YES              | NO          |         1 |               0 |
      +-----------+-----------+-----------------+-------------+--------+-------------+-----------+----------------+----------+--------------------+--------------------+----------------+-------------+----------------+---------------------+-------------------+-----------------+------------------+-------------+-----------+-----------------+
      1 row in set
      
    5. Drop the materialized view log on the test_tbl1 table.

      DROP MATERIALIZED VIEW LOG ON test_tbl1;
      
    6. Drop the materialized view mv_test_tbl1.

      DROP MATERIALIZED VIEW mv_test_tbl1;
      

    References

    • DBA_MVIEW_LOGS
    • Overview of Materialized Views
    • Create Materialized Views
    • Refresh Materialized Views
    • Materialized View Query Rewriting
    • Query Materialized Views
    • Drop Materialized Views

    Previous topic

    Overview of materialized views
    Last

    Next topic

    Automatic management of materialized view logs
    Next
    What is on this page
    Limitations
    Privileges
    Schema definition of a materialized view log
    Operations on existing materialized view logs
    Impact of base table operations on materialized view logs
    DML operations on the base table
    DDL operations on the base table
    Create a materialized view log
    Privilege requirements
    Syntax
    Modify a materialized view log
    Privilege requirements
    Syntax
    Drop a materialized view log
    Considerations
    Privilege requirements
    Syntax
    Example
    References