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.3.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive 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.3.0
    iconOceanBase Database
    SQL - V 4.3.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

    Creation and update strategies for materialized views

    Last Updated:2026-04-15 08:30:01  Updated
    Share
    What is on this page
    Create a materialized view
    Full update
    Incremental update
    Example

    folded

    Share

    Create a materialized view

    Materialized views are an important tool for database optimization. They store query results in physical storage to speed up data retrieval. When you create a materialized view, a schema corresponding to the query that defines the view is first generated. The schema is then used to build an SQL statement for creating a table that stores data of the materialized view. After the table is created, the query that defines the view is executed, and the result set is inserted into the table.

    Materialized views support two update strategies: full update and incremental update.

    Full update

    A full update clears all existing data in a materialized view and inserts the latest query result set into the view.

    In this process, a combination operation of TRUNCATE TABLE and INSERT INTO SELECT is performed. OceanBase Database uses the DDL framework to implement full updates.

    Incremental update

    An incremental update calculates the difference between a materialized view and its base tables based on data that has changed since the last update and applies the difference to the materialized view. This strategy is more efficient.

    Incremental data changes, including old and new values of all modified rows, are recorded in materialized view logs.

    materilazied-architechture

    As shown in the preceding figure, when DML operations such as INSERT and UPDATE are performed on base tables, the database activity streams (DAS) mechanism ensures that base tables and materialized view logs are simultaneously updated. Background maintenance tasks regularly apply the incremental changes in materialized view logs to the materialized view. When data in materialized view logs is refreshed to the materialized view, the deletion module will clear the data from the logs. In this case, a query operation will access both the materialized view and data in materialized view logs that has not been refreshed, combine the data, and return the latest result set.

    Example

    The table and view definitions, as well as the update sequence are as follows:

    CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT);
    CREATE MATERIALIZED VIEW m1 AS SELECT COUNT(c1) FROM t1;
    
    -- Update sequence
    INSERT INTO t1 VALUES(3,4);
    INSERT INTO t1 VALUES(5,6);
    INSERT INTO t1 VALUES(8,3);
    UPDATE t1 SET c1 = 7 WHERE c1 = 8;
    

    The corresponding mlog table is mlog$_t1. The value N of the old field indicates a new value, and the value Y indicates an old value. You can obtain the incremental update value in the m1 view by using the following query:

    (SELECT COUNT(c1) FROM mlog WHERE old = 'N') - (SELECT COUNT(c1) FROM mlog WHERE old = 'Y')
    

    Previous topic

    Materialized view logs
    Last

    Next topic

    Dictionary views
    Next
    What is on this page
    Create a materialized view
    Full update
    Incremental update
    Example