OceanBase logo

OceanBase

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

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

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

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.0.0Enterprise Edition

  • Overview
    • Overview
    • System architecture
    • Compatibility with MySQL
    • Compatibility with Oracle
      • Overview
      • SQL data types
      • Built-in functions
      • System views
    • Limits
  • Get Started
    • Quick start with OceanBase Database
    • Hands on for OceanBase SQL
      • Usage notes
      • Basic SQL operations (MySQL mode)
      • Basic SQL operations (Oracle mode)
    • Build applications (MySQL Mode)
      • Connect Python applications to OceanBase Database
      • Connect Java applications to OceanBase Database
      • Connect C applications to OceanBase Database
    • Build applications(Oracle Mode)
      • Connect Python applications to OceanBase Database
      • Connect Java applications to OceanBase Database
      • Connect C applications to OceanBase Database
    • Experience OceanBase advanced features
      • Experience scalable OLTP
        • Run the TPC-C benchmark in OceanBase Database
        • Experience the hot row update capability of OceanBase Database
      • Experience operational OLAP
      • Experience parallel import and data compression
      • Experience the multitenancy feature
  • Develop
    • Develop (MySQL Mode)
      • Connect to Oceanbase Database with client
        • Overview
        • Connect to an OceanBase Database tenant by using a MySQL client
        • Connect to an OceanBase Database tenant by using OBClient
        • Connect to OceanBase Database by using ODC
        • Java application
          • OceanBase Connector/J
          • Java APIs
          • Connect Java applications to OceanBase Database
        • C application
          • OceanBase Connector/C
          • C API functions
          • Connect C applications to OceanBase Database
        • Python applications
        • SpringBoot connection example
        • SpringBatch connection example
        • Example of Database connection pool configuration
          • Overview of database connection pool configuration
          • Example of configuring a Tomcat connection pool
          • Example of configuring a C3P0 connection pool
          • Example of configuring a Proxool connection pool
          • Example of configuring a HiKariCP connection pool
          • Example of configuring a DBCP connection pool
          • CommonPool configuration example
          • Example of configuring a JDBC connection pool
        • SpringJDBC connection example
        • SpringJPA connection example
        • Hibernate connection example
        • MyBatis connection example
      • Create and manage database objects
        • About DDL statements
        • View the currently connected database
        • Change the password of a user
        • Data type
          • General data types
          • Unsupported data types
        • Create and manage tables
          • About tables
          • Create a table
          • About auto-increment columns
          • About types of column constraints
          • About table structure modification
          • About table clearing
          • About table dropping
          • Flash back a dropped table
          • About table privileges
        • Create and manage partition tables
          • About partitioned tables
          • Create a partitioned table
          • Manage a partitioned table
          • Create a subpartitioned table
          • Manage a subpartitioned table
          • Partition routing
          • Indexes on partitioned tables
          • Suggestions on using partitioned tables
        • Create and manage indexes
          • About indexes
          • Create an index
          • Drop an index
        • Create and manage views
          • About views
          • Create a view
          • Modify a view
          • Delete a view
        • Create and manage sequences
          • About sequences
          • Create a sequence
          • Modify a sequence
          • Delete a sequence
        • Create and manage triggers
          • About triggers
          • Create a trigger
          • Delete a trigger
      • Query
        • About queries
        • Single-table queries
        • Conditional queries
        • ORDER BY queries
        • GROUP BY queries
        • Use the LIMIT clause in queries
        • Query data from multiple tables
          • About multi-table join queries
          • INNER JOIN queries
          • OUTER JOIN queries
          • Subqueries
        • Use operators and functions in a query
          • Use arithmetic operators in queries
          • Use numerical functions in queries
          • Use string connectors in queries
          • Use string functions in queries
          • Use datetime functions in queries
          • Use type conversion functions in queries
          • Use aggregate functions in queries
          • Use NULL-related functions in queries
          • Use the CASE conditional operator in queries
          • Use the SELECT FOR UPDATE statement to lock query results
        • Execution plan
          • View an execution plan
          • Understand an execution plan
        • Use SQL hints in queries
        • Variables of query timeout
      • DML statements and transactions
        • DML statement
          • About DML statements
          • About the INSERT statement
          • UPDATE statements
          • About the DELETE statement
          • About the REPLACE INTO statement
        • Transactions
          • About transaction control statements
          • Start a transaction
          • Transaction savepoints
          • Commit a transaction
          • Roll back a transaction
          • About transaction timeout
      • Common errors and solutions
        • About error codes
        • Database connection error
        • About timeout
          • Idle session timeout
          • Transaction timeout errors
        • About user
          • Locked user
          • Incorrect user password
        • About table
          • Table already exists
          • Table does not exist
          • Invalid use of NULL value
        • About constraint
          • Unique key conflict
          • Foreign key conflict
        • About SQL commands
          • Data truncation
    • Develop (Oracle Mode)
      • Connect to Oceanbase Database with client
        • Overview
        • Connect to an OceanBase tenant by using an Oracle client
        • Connect to an OceanBase Database tenant by using OBClient
        • Connect to OceanBase Database by using ODC
      • Application development
        • Java application
          • OceanBase Connector/J
          • Java APIs
          • Connect Java applications to OceanBase Database
        • Python application
          • OceanBase Connector/J in Python
          • Python APIs
          • Connect Python applications to OceanBase Database
        • 300.c-application-1
          • OceanBase Connector/C
          • OBCI APIs
          • Connect C applications to OceanBase Database
      • Create and manage database objects
        • About DDL statements
        • View the currently connected database
        • Change the password of a user
        • Data type
          • General data types
          • Unsupported data types
        • Create and manage tables
          • About tables
          • Create a table
          • Define an auto-increment column by using the SEQUENCE keyword
          • About types of column constraints
          • About table structure modification
          • About table clearing
          • About table dropping
          • Flash back a dropped table
          • About table privileges
        • Create and manage partition tables
          • About partitioned tables
          • Create a partitioned table
          • Manage a partitioned table
          • Create a subpartitioned table
          • Manage a subpartitioned table
          • Partition routing
          • Indexes on partitioned tables
          • Suggestions on using partitioned tables
        • Create and manage indexes
          • Drop an index
          • About indexes
          • Create an index
        • Create and manage views
          • About views
          • Create a view
          • Modify a view
          • Drop a view
        • Create and manage sequences
          • About sequences
          • Create a sequence
          • Modify a sequence
          • Delete a sequence
        • Create and manage synonyms
          • About synonyms
          • Create a synonym
          • Delete a synonym
        • Create and manage triggers
          • About triggers
          • Create a trigger
          • Modify a trigger
          • Delete a trigger
          • Enable or disable a trigger
      • Query
        • About queries
        • Single-table queries
        • Conditional queries
        • ORDER BY queries
        • GROUP BY queries
        • Use Row_Limiting_Clause in queries
        • Query data from multiple tables
          • About multi-table join queries
          • INNER JOIN queries
          • OUTER JOIN queries
          • Subqueries
        • Use operators and functions in a query
          • Use arithmetic operators in queries
          • Use numerical functions in queries
          • Use string concatenation operators in queries
          • Use string functions in queries
          • Use datetime functions in queries
          • Use type conversion functions in queries
          • Use aggregate functions in queries
          • Use NULL-related functions in queries
          • Use CASE functions in queries
          • Use the SELECT FOR UPDATE statement to lock query results
        • Execution plan
          • View execution plans of queries
          • Understand an execution plan
        • Use SQL hints in queries
        • About query timeout variables
      • DML statements and transactions
        • DML statement
          • About DML statements
          • About the INSERT statement
          • UPDATE statements
          • About the MERGE statement
          • About the DELETE statement
        • Transactions
          • About transaction control statements
          • Start a transaction
          • Transaction savepoints
          • Commit a transaction
          • Roll back a transaction
          • About transaction timeout
      • Common errors and solutions
        • Overview
        • Database connection error
        • About timeout
          • Idle session timeout
          • Transaction timeout errors
        • About user
          • Locked user
          • Incorrect user password
        • About object
          • Object already exists
          • Object does not exist
        • About constraint
          • Unique key conflict
          • Foreign key conflict
        • About sql
          • Data type inconsistency
  • Deploy
    • Overview
    • Deployment procedure
    • Preparations before deployment
      • Prepare servers
      • Configure servers
      • Prepare installation packages
    • HA solution for OceanBase clusters
    • Deploy through the CLI
      • Configure the deployment environment
        • Install oat-cli
        • Use oat-cli to configure the deployment environment
        • Configure the clock source
        • Upload installation packages
        • Configure host information
        • Check the environment before deployment
      • Deploy OCP
        • Deployment description
        • Generate a configuration file
        • Start deployment
        • Check after deployment
      • Deploy the OceanBase cluster
        • Deploy a single-replica OceanBase cluster
        • Deploy a three-replica OceanBase cluster
      • Deploy OBProxy
        • Deploy OBProxy through the CLI
      • Create an OceanBase tenant
        • View resources available for a business tenant
        • Create a tenant
        • Verify after deployment
      • Deploy OMS
        • Deployment description
        • Modify the configuration file
        • Start deployment
        • Check after deployment
      • Deploy ODC
        • Deployment description
        • Modify the configuration file
        • Start deployment
        • Check after deployment
  • Migrate
    • Overview
    • Migrate data by using SQL scripts
    • Migrate data by using MySQLDump
    • Migrate data by using DataX
    • Migrate data by using OUTFILE statements

Download PDF

Overview System architecture Compatibility with MySQL Overview SQL data types Built-in functions System views Limits Quick start with OceanBase Database Usage notes Basic SQL operations (MySQL mode) Basic SQL operations (Oracle mode) Connect Python applications to OceanBase Database Connect Java applications to OceanBase Database Connect C applications to OceanBase Database Connect Python applications to OceanBase Database Connect Java applications to OceanBase Database Connect C applications to OceanBase Database Experience operational OLAP Experience parallel import and data compression Experience the multitenancy feature Overview Deployment procedure Prepare servers Configure servers Prepare installation packages HA solution for OceanBase clustersOverview Migrate data by using SQL scripts Migrate data by using MySQLDumpMigrate data by using DataX Migrate data by using OUTFILE statements
OceanBase logo

The Unified Distributed Database for the AI Era.

Follow Us
Products
OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
Resources
DocsBlogLive DemosTraining & Certification
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.0.0
iconOceanBase Database
SQL - V 4.0.0Enterprise Edition
SQL
KV
  • 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

Manage a subpartitioned table

Last Updated:2023-07-24 09:52:12  Updated
share
What is on this page
Add a partition
Syntax
Examples
Add a subpartition
Syntax
Parameters
Examples
Drop a partition
Syntax
Examples
Drop a subpartition
Syntax
Examples
Truncate a partition
Syntax
Examples
Truncate a subpartition
Syntax
Examples

folded

share

After you create a subpartitioned table, you can add, drop, or truncate partitions and subpartitions in the subpartitioned table.

Add a partition

Syntax

You can add a partition to a template-based or non-template-based subpartitioned table.

  • Add a partition to a template-based subpartitioned table.

    ALTER TABLE table_name ADD PARTITION partition_options;
    
    partition_option:
      range_partition_option | list_partition_option
    
    range_partition_option:
      partition_name VALUES LESS THAN partition_expr
    
    list_partition_option:
      partition_name VALUES partition_expr
    

    Note

    For a template-based subpartitioned table, you only need to specify the partition definition when you add a partition. The subpartition definition is automatically filled based on the template.

  • Add a partition to a non-template-based subpartitioned table

    ALTER TABLE table_name ADD PARTITION partition_options(subpartition_option);
    
    partition_option:
      range_partition_option | list_partition_option
    
    range_partition_option:
      partition_name VALUES LESS THAN partition_expr
    
    list_partition_option:
      partition_name VALUES partition_expr
    
    tg_subpartition_option:
      {SUBPARTITION subpartition_name VALUES LESS THAN range_partition_expr, ...}
     |{SUBPARTITION subpartition_name VALUES list_partition_expr, ....}
     |{SUBPARTITION subpartition_name, ....}
    

    Note

    For a non-template-based subpartitioned table, you must specify both partition and subpartition definitions when you add a partition.

Examples

  • Add the partition p2 to the template-based RANGE-RANGE-subpartitioned table t2_m_rr.

    obclient> ALTER TABLE t2_m_rr ADD PARTITION p2 VALUES LESS THAN(300);
    Query OK, 0 rows affected
    

    View the p2 partition added to the t2_m_rr subpartitioned table.

    obclient> SHOW CREATE TABLE t2_m_rr\G
    *************************** 1. row ***************************
           TABLE: T2_M_RR
    CREATE TABLE: CREATE TABLE "T2_M_RR" (
      "COL1" NUMBER(38),
      "COL2" NUMBER(38)
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2) subpartition template (
    subpartition MP0 values less than (2020),
    subpartition MP1 values less than (2021),
    subpartition MP2 values less than (2022))
    (partition P0 values less than (100),
    partition P1 values less than (200),
    partition P2 values less than (300))
    1 row in set
    

    Insert data into the p2 partition of the t2_m_rr table.

    obclient>INSERT INTO t2_m_rr VALUES (288,288);
    Query OK, 1 row affected
    

    View the p2 partition of the t2_m_rr subpartitioned table.

    obclient> SELECT * FROM t2_m_rr partition(p2);
    +------+------+
    | COL1 | COL2 |
    +------+------+
    |  288 |  288 |
    +------+------+
    1 row in set
    
  • Add the partition p2 to the non-template-based RANGE-RANGE-subpartitioned table t2_f_rr.

    obclient> ALTER TABLE t2_f_rr ADD PARTITION p2 VALUES LESS THAN(300)
           (SUBPARTITION sp5 VALUES LESS THAN(2020),
            SUBPARTITION sp6 VALUES LESS THAN(2021),
            SUBPARTITION sp7 VALUES LESS THAN(2022)
            );
    Query OK, 0 rows affected
    

    View the p2 partition added to the t2_f_rr subpartitioned table.

    obclient> SHOW CREATE TABLE t2_f_rr\G
    *************************** 1. row ***************************
           TABLE: T2_F_RR
    CREATE TABLE: CREATE TABLE "T2_F_RR" (
      "COL1" NUMBER,
      "COL2" NUMBER
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2)
    (partition P0 values less than (100) (
    subpartition SP0 values less than (2020),
    subpartition SP1 values less than (2021)),
    partition P1 values less than (200) (
    subpartition SP2 values less than (2020),
    subpartition SP3 values less than (2021),
    subpartition SP4 values less than (2022)),
    partition P2 values less than (300) (
    subpartition SP5 values less than (2020),
    subpartition SP6 values less than (2021),
    subpartition SP7 values less than (2022)))
    1 row in set
    

    Insert data into the p2 partition of the t2_f_rr table.

    obclient> INSERT INTO t2_f_rr VALUES (288,288);
    Query OK, 1 row affected
    

    View the p2 partition of the t2_f_rr subpartitioned table.

    obclient> SELECT * FROM t2_f_rr partition(p2);
    +------+------+
    | COL1 | COL2 |
    +------+------+
    |  288 |  288 |
    +------+------+
    1 row in set
    

Add a subpartition

Syntax

ALTER TABLE table_name MODIFY PARTITION partition_name
  ADD SUBPARTITION subpartition_option;

subpartition_option:
  {SUBPARTITION subpartition_name VALUES LESS THAN range_partition_expr, ...}
 |{SUBPARTITION subpartition_name VALUES list_partition_expr, ...}

Parameters

Parameter Description
table_name The table name.
partition_name The name of the partition to which the subpartition to be added belongs.
subpartition_name The subpartition name.

Examples

Add the subpartitions sp8 and sp9 to the partition p1 of the non-template-based RANGE-RANGE-subpartitioned table t2_f_rr.

obclient> ALTER TABLE t2_f_rr MODIFY PARTITION p1 ADD
       SUBPARTITION sp8 VALUES LESS THAN(2023),
       SUBPARTITION sp9 VALUES LESS THAN(2024);
Query OK, 0 rows affected

View the sp8 and sp9 subpartitions added to the t2_f_rr subpartitioned table.

obclient> SHOW CREATE TABLE t2_f_rr\G
*************************** 1. row ***************************
       TABLE: T2_F_RR
CREATE TABLE: CREATE TABLE "T2_F_RR" (
  "COL1" NUMBER,
  "COL2" NUMBER
) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
 partition by range(col1) subpartition by range(col2)
(partition P0 values less than (100) (
subpartition SP0 values less than (2020),
subpartition SP1 values less than (2021)),
partition P1 values less than (200) (
subpartition SP2 values less than (2020),
subpartition SP3 values less than (2021),
subpartition SP4 values less than (2022),
subpartition SP8 values less than (2023),
subpartition SP9 values less than (2024)),
partition P2 values less than (300) (
subpartition SP5 values less than (2020),
subpartition SP6 values less than (2021),
subpartition SP7 values less than (2022)))
1 row in set

Insert data into the sp8 and sp9 subpartitions of the t2_f_rr table.

obclient> INSERT INTO t2_f_rr VALUES (188,2023),(188,2022);
Query OK, 2 rows affected
Records: 2  Duplicates: 0  Warnings: 0

View the sp8 and sp9 subpartitions of the created t2_f_rr subpartitioned table.

obclient> SELECT * FROM t2_f_rr partition(sp8,sp9);
+------+------+
| COL1 | COL2 |
+------+------+
|  188 | 2022 |
|  188 | 2023 |
+------+------+
2 rows in set

Drop a partition

Syntax

ALTER TABLE table_name DROP PARTITION partition_name_list [ UPDATE GLOBAL INDEXES ];

partition_name_list:
  partition_name[, partition_name ...]

Note

  • Before you drop a partition from a subpartitioned table, ensure that no active transaction or query exists in this partition. Otherwise, SQL statement errors or exceptions may occur. In the sys tenant, you can query the context status of unfinished transactions through the __all_virtual_trans_stat table.
  • If you drop a partition, its definition, data, and subpartitions are also dropped.
  • When you drop a partition from a subpartitioned table with global indexes in Oracle mode, you need to add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update the global indexes. If the UPDATE GLOBAL INDEXES keyword is not added, the global indexes of this subpartitioned table become unavailable after the partition is dropped.

Examples

  1. View the information about the t2_f_rr subpartitioned table.

    obclient>SHOW CREATE TABLE t2_f_rr\G
    *************************** 1. row ***************************
           TABLE: T2_F_RR
    CREATE TABLE: CREATE TABLE "T2_F_RR" (
      "COL1" NUMBER,
      "COL2" NUMBER
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2)
    (partition P0 values less than (100) (
    subpartition SP0 values less than (2020),
    subpartition SP1 values less than (2021)),
    partition P1 values less than (200) (
    subpartition SP2 values less than (2020),
    subpartition SP3 values less than (2021),
    subpartition SP4 values less than (2022),
    subpartition SP8 values less than (2023),
    subpartition SP9 values less than (2024)),
    partition P2 values less than (300) (
    subpartition SP5 values less than (2020),
    subpartition SP6 values less than (2021),
    subpartition SP7 values less than (2022)))
    1 row in set
    
  2. Drop the partition p0 from the subpartitioned table t2_f_rr.

    obclient> ALTER TABLE t2_f_rr DROP PARTITION p0;
    Query OK, 0 rows affected
    
  3. View the results.

    obclient> SHOW CREATE TABLE t2_f_rr\G
    *************************** 1. row ***************************
           TABLE: T2_F_RR
    CREATE TABLE: CREATE TABLE "T2_F_RR" (
      "COL1" NUMBER,
      "COL2" NUMBER
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2)
    (partition P1 values less than (200) (
    subpartition SP2 values less than (2020),
    subpartition SP3 values less than (2021),
    subpartition SP4 values less than (2022),
    subpartition SP8 values less than (2023),
    subpartition SP9 values less than (2024)),
    partition P2 values less than (300) (
    subpartition SP5 values less than (2020),
    subpartition SP6 values less than (2021),
    subpartition SP7 values less than (2022)))
    1 row in set
    

Drop a subpartition

Syntax

ALTER TABLE table_name DROP SUBPARTITION subpartition_name_list [ UPDATE GLOBAL INDEXES ];

subpartition_name_list:
  subpartition_name[, subpartition_name ...]

Note

  • Before you drop a subpartition from a subpartitioned table, ensure that no active transaction or query exists in this subpartition. Otherwise, SQL statement errors or exceptions may occur. In the sys tenant, you can query the context status of unfinished transactions through the __all_virtual_trans_stat table.
  • If you drop a subpartition, its definition and data are also dropped.
  • When you drop a subpartition from a subpartitioned table with global indexes in Oracle mode, you need to add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update the global indexes. If the UPDATE GLOBAL INDEXES keyword is not added, the global indexes of this subpartitioned table become unavailable after the subpartition is dropped.

Examples

Drop the subpartitions sp8 and sp9 from the partition p1 of the subpartitioned table t2_f_rr, and update the global indexes.

  1. View the t2_f_rr table.

    obclient> SHOW CREATE TABLE t2_f_rr\G
    *************************** 1. row ***************************
           TABLE: T2_F_RR
    CREATE TABLE: CREATE TABLE "T2_F_RR" (
      "COL1" NUMBER,
      "COL2" NUMBER
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2)
    (partition P1 values less than (200) (
    subpartition SP2 values less than (2020),
    subpartition SP3 values less than (2021),
    subpartition SP4 values less than (2022),
    subpartition SP8 values less than (2023),
    subpartition SP9 values less than (2024)),
    partition P2 values less than (300) (
    subpartition SP5 values less than (2020),
    subpartition SP6 values less than (2021),
    subpartition SP7 values less than (2022)))
    1 row in set
    
  2. Drop the subpartitions sp8 and sp9 from the partition p1 of the subpartitioned table t2_f_rr, and update the global indexes.

    obclient> ALTER TABLE t2_f_rr DROP SUBPARTITION sp8,sp9 UPDATE GLOBAL INDEXES;
    Query OK, 0 rows affected
    
  3. View the results.

    obclient> SHOW CREATE TABLE t2_f_rr\G
    *************************** 1. row ***************************
           TABLE: T2_F_RR
    CREATE TABLE: CREATE TABLE "T2_F_RR" (
      "COL1" NUMBER,
      "COL2" NUMBER
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
     partition by range(col1) subpartition by range(col2)
    (partition P1 values less than (200) (
    subpartition SP2 values less than (2020),
    subpartition SP3 values less than (2021),
    subpartition SP4 values less than (2022)),
    partition P2 values less than (300) (
    subpartition SP5 values less than (2020),
    subpartition SP6 values less than (2021),
    subpartition SP7 values less than (2022)))
    1 row in set
    

Truncate a partition

Syntax

ALTER TABLE table_name TRUNCATE PARTITION partition_name_list[ UPDATE GLOBAL INDEXES ];

partition_name_list:
  partition_name[, partition_name ...]

Note

  • OceanBase Database allows you to truncate one or more partitions in a subpartitioned table of the RANGE or LIST partitioning method to clear all data in the subpartitions corresponding to one or more partitions. Supported subpartitioning methods of RANGE or LIST are RANGE-RANGE, RANGE-LIST, LIST-RANGE, and LIST-LIST.
  • Before you truncate a partition from a subpartitioned table, ensure that no active transaction or query exists in this partition. Otherwise, SQL statement errors or exceptions may occur. In the sys tenant, you can query the context status of unfinished transactions through the __all_virtual_trans_stat table.
  • When you truncate a partition from a subpartitioned table with global indexes in Oracle mode, you need to add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update the global indexes. If the UPDATE GLOBAL INDEXES keyword is not added, the global indexes of this subpartitioned table become unavailable after the partition is truncated.

Examples

  1. View the p0 and p1 partitions of the t2_f_rl table.

    obclient> SELECT * FROM t2_f_rl partition(p0,p1);
    +------+------+
    | COL1 | COL2 |
    +------+------+
    |   99 | 01   |
    |   99 | 02   |
    |  199 | 01   |
    |  199 | 02   |
    +------+------+
    4 rows in set
    
  2. Truncate the partitions p0 and p1 of the RANGE-LIST-subpartitioned table t2_f_rl.

    obclient> ALTER TABLE t2_f_rl TRUNCATE PARTITION p0,p1;
    Query OK, 0 rows affected
    
  3. View the p0 and p1 partitions of the t2_f_rl table.

    obclient> SELECT * FROM t2_f_rl partition(p0,p1);
    Empty set
    

Truncate a subpartition

Syntax

ALTER TABLE table_name TRUNCATE SUBPARTITION subpartition_name_list[ UPDATE GLOBAL INDEXES ];

subpartition_name_list:
  subpartition_name[, subpartition_name ...]

Note

  • Before you truncate a subpartition from a subpartitioned table, ensure that no active transaction or query exists in this subpartition. Otherwise, SQL statement errors or exceptions may occur. In the sys tenant, you can query the context status of unfinished transactions through the __all_virtual_trans_stat table.
  • OceanBase Database allows you to truncate one or more subpartitions in a subpartitioned table of the RANGE or LIST partitioning method to clear all data in one or more subpartitions. Supported subpartitioning methods of RANGE or LIST are RANGE-RANGE, RANGE-LIST, LIST-RANGE, and LIST-LIST.
  • When you truncate a subpartition from a subpartitioned table with global indexes in Oracle mode, you need to add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update the global indexes. If the UPDATE GLOBAL INDEXES keyword is not added, the global indexes of this subpartitioned table become unavailable after the subpartition is truncated.

Examples

Truncate the subpartitions sp3 and sp4 from the partition p1 of the subpartitioned table t2_f_lr, and then update the global indexes.

  1. View the sp3 and sp4 subpartitions in the p1 partition of the t2_f_lr table.

    obclient> SELECT * FROM t2_f_lr;
    +------+------+
    | COL1 | COL2 |
    +------+------+
    |  199 | 02   |
    |  299 | 02   |
    +------+------+
    2 rows in set
    
  2. Truncate the subpartitions sp3 and sp4 from the partition p1 of the subpartitioned table t2_f_lr, and then update the global indexes.

    obclient> ALTER TABLE t2_f_lr TRUNCATE SUBPARTITION sp3,sp4 UPDATE GLOBAL INDEXES;
    Query OK, 0 rows affected
    
  3. View the sp3 and sp4 subpartitions in the p1 partition of the t2_f_lr table.

    obclient> SELECT * FROM t2_f_lr;
    Empty set
    

Previous topic

Create a subpartitioned table
Last

Next topic

Partition routing
Next
What is on this page
Add a partition
Syntax
Examples
Add a subpartition
Syntax
Parameters
Examples
Drop a partition
Syntax
Examples
Drop a subpartition
Syntax
Examples
Truncate a partition
Syntax
Examples
Truncate a subpartition
Syntax
Examples