OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Developer Center

V4.5.0
  • Topics Overview
  • Overview
    • What is ODC?
    • Features
    • Architecture
    • Limitations
    • ODC console
  • Quick Start
    • Client ODC
      • Overview
      • Install Client ODC
      • Use Client ODC
    • Web ODC
      • Overview
      • Deploy Web ODC
      • Use Web ODC
  • Data Source Management
    • Create a data source
    • Data sources and project collaboration
    • Database O&M
      • Session management
      • Global variable management
      • Recycle bin management
  • SQL Development
    • Edit and execute SQL statements
    • Perform PL compilation and debugging
    • Use the command-line window
    • Edit and export the result set
    • Execution Analysis
    • Generate test data
    • System settings
    • Intelligent SQL development
    • Common features
    • Database objects
      • Table objects
        • Overview
        • Create a table
      • View objects
        • Overview
        • Create a view
        • Manage views
      • Materialized view objects
        • Overview
        • Create a materialized view
        • Manage materialized views
      • Function objects
        • Overview
        • Create a function
        • Manage functions
      • Stored procedure objects
        • Overview
        • Create a stored procedure
        • Manage stored procedures
      • Sequence objects
        • Overview
        • Create a sequence
        • Manage sequences
      • Package objects
        • Overview
        • Create a program package
        • Manage program packages
      • Trigger objects
        • Overview
        • Create a trigger
        • Manage triggers
      • Type objects
        • Overview
        • Create a type
        • Manage types
      • Synonym objects
        • Overview
        • Create a synonym
        • Manage synonyms
      • External resource objects
        • External resources
        • Create an external resource
        • Manage external resources
  • Database Change Risk Management
    • Project collaborative management
      • Project management
      • Manage databases
      • Manage logical databases
      • Add object storage files
      • Manage project members
      • Desensitize data
      • Notification management
        • Overview
        • View notification records
        • Manage notification channels
          • Create a notification channel
          • View, edit, and delete a notification channel
          • Configure a custom channel
        • Manage notification rules
    • Manage user permissions
      • Users and roles
      • Automatic authorization
      • Apply for project permissions
      • Apply for database permissions
      • Apply table/view permissions
    • Security standards
      • Environment configuration
        • SQL check specifications
        • SQL window specification
      • Risk Management
        • Overview
        • Manage risk identification rules
        • Manage approval processes
      • Desensitization algorithms
      • Operation audit
  • Ticket Management
    • Import schemas and data
    • Export schemas and data
    • Database change management
    • Manage changes to logical databases
    • Batch database change management
    • Online schema changes
    • Synchronize shadow tables
    • Schema comparison
  • Data Lifecycle Management
    • Data archiving
    • Data cleanup
    • Manage partitioning plans
      • Manage partitioning plans
      • Set partitioning strategies
      • Examples of partitioning strategies
    • SQL Plan
  • System Integration
    • Login integration
    • Approval integration
    • SQL approval integration
    • Bastion host integration
    • Integrate with LLMs
  • Deployment Guide
    • Deployment overview
    • Preparations before deployment
    • Deploy ODC in single-node mode
    • Deploy ODC in high-availability mode
    • Deployment verification
  • Upgrade Guide
    • Upgrade Overview
    • Preparations for upgrade
    • Update single-node ODC
    • Update high-avaliability ODC
    • Upgrade verification
    • Rollback after upgrade failed
  • Best Practices
    • Tips for SQL development
    • Explore ODC team workspaces
    • Understanding real-time SQL diagnostics for OceanBase AP
    • OceanBase historical database solutions
    • ODC SQL check for automatic identification of high-risk operations
    • Integration with ODC enterprise-level account system
    • Manage and modify sharded databases and tables via ODC
    • Data masking and control practices
    • Enterprise-level control and collaboration: Safeguard every database change
  • Troubleshooting
    • ODC troubleshooting process
    • Collect message
      • View the runtime environment and version information
      • View web ODC logs
      • View client ODC logs
      • View end-to-end ODC-related logs
      • View ODC MetaDB data
      • Query the index status in OceanBase Database V4.x
      • Query the index status in OceanBase Database V1.4.x to V3.2.x
      • Collect JVM runtime information
      • Use tcpdump to capture packets
    • FAQ
      • Installation of client ODC
      • Web ODC deployment and startup
      • Connection Information
      • Command-line window
      • DDL statement display
  • Release Notes
    • V4.5
      • ODC V4.5.0
    • V4.4
      • ODC V4.4.0
      • ODC V4.4.1
      • ODC V4.4.2
      • ODC V4.4.3
    • V4.3
      • ODC V4.3.4
      • ODC V4.3.3
      • ODC V4.3.2
      • ODC V4.3.1
      • ODC V4.3.0
    • V4.2
      • ODC V4.2.4
      • ODC V4.2.3
      • ODC V4.2.2
      • ODC V4.2.1
      • ODC V4.2.0
    • V4.1
      • ODC V4.1.3
      • ODC V4.1.2
      • ODC V4.1.1
      • ODC V4.1.0
    • V4.0
      • ODC V4.0.2
      • ODC V4.0.0
    • V3.4
      • ODC V3.4.0
    • V3.3
      • ODC V3.3.3
      • ODC V3.3.2
      • ODC V3.3.1
      • ODC V3.3.0
    • V3.2
      • ODC V3.2.3
      • ODC V3.2.2
      • ODC V3.2.1
      • ODC V3.2.0

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Developer Center
  3. V4.5.0

Examples of partitioning strategies

Last Updated:2026-09-03 09:11:30

Set a partitioning strategy for an OceanBase MySQL compatible mode table
Set a partitioning strategy for an OceanBase Oracle compatible mode table
References

This topic describes how to set partition creation strategies and partition deletion strategies.

Set a partitioning strategy for an OceanBase MySQL compatible mode table

The following example describes how to set a partitioning strategy for the order table in the doc_test_data_1 database of the mysql441 data source. The example also describes how to set a drop partitioning strategy for the order table.

  1. In the SQL window, execute the following statement to create the order table.

    CREATE TABLE `order` (
     `time` date NOT NULL,
     `parti_key` int(11),
     `name` varchar(120) DEFAULT NULL
    ) partition by range columns(time, parti_key)
    (partition p2023_01 values less than ('2023-01-01', 20230101),
    partition p2023_02 values less than ('2023-02-01', 20230201))
    
  2. Click Jobs > Partitioning Plan > Create New in the SQL window.

  3. Select the target database, and click edit next to the target partition table to edit the partitioning strategy.

  4. In the configure partitioning strategy panel, select Creation Strategy and Deletion Strategy under Partitioning Strategy to create a partitioning strategy.

  5. In the Create Partitions section, set the partitioning strategy.

    1. Specify the number of partitions to be created.

    2. Create rules.

      For example, you can set the partitioning strategy for the time and parti_key partitioning keys of the order table.

      • time: The time partitioning key is of the DATE type, which is a time type. Therefore, you can set the Sequential Increment strategy as the partitioning strategy for this partitioning key. In this example, the creation strategy of the time partitioning key is to generate several partitions based on the current time (that is, the time when the partitioning plan task actually runs) as the starting point, with a monthly interval.

      • parti_key: The parti_key partitioning key is of the INT type. You can set the Custom strategy as the partitioning strategy. Assume that you want to generate partitions based on the current time as the starting point, with a monthly interval. To set a custom partitioning strategy, follow the steps described in the Custom Partitioning Strategy section. The expression can be generated based on the following steps:

        1. Obtain the base time for generating partitions. In this example, the current time serves as the base time. Therefore, you can directly use the now() function.

        2. Define the interval for generating partitions. In this example, partitions are to be generated with a monthly interval. To set the Create Rule, click Rule Details > Interval. Enter 1 as the fixed interval and add the interval expression to the basis expression in Step 1 to generate the next partition. The expression is now () + interval ${INTERVAL} month, where ${INTERVAL} refers to the value entered in Creation Rule > Rule Details > Interval.

        3. Generate a partitioning expression corresponding to the type of the partitioning key. The parti_key partitioning key is of the int type, but the expression generated in Step 1 is of the time type. Therefore, you need to convert it to an int type. You can first convert it to a numeric string and then convert it to an int type. The expression is: cast(date_format(now() + interval ${INTERVAL} month, '%Y%m01') as signed).

          Here:

          • CAST(xxx AS SIGNED): converts a field to an integer.

          • DATE_FORMAT(): converts a field to a date format.

          • NOW(): returns the current date.

            Note

            In ODC, you can also use the ${LAST_PARTITION_VALUE} variable to introduce the upper limit of the partition in the current database for subsequent partition generation. For example, ${LAST_PARTITION_VALUE} + interval ${INTERVAL} month generates partitions from the upper limit of the latest partition in the database.

          • INTERVAL ${INTERVAL} MONTH: a monthly interval expression. ${INTERVAL} is a fixed usage in ODC.

          • '%Y%m01': the date format.

    3. Select a naming method.

      For example, the selected naming method is Prefix+Suffix, which consists of a fixed prefix and a time-based suffix.

      1. Prefix: You can specify the prefix as you like.

      2. Suffix: You can select the upper bound of the time-type partitioning key as the suffix for naming the current partition. You can also specify the formatted output format and the incremental interval of time.

      3. After the settings are completed, you can click Test Generation to view the partition names.

    4. Copy Statistics from Table's Last Partition to New Partition: No.

  6. In the Delete Partitions section, configure the partition deletion strategy. The following table describes the parameters in the current example.

    • Number of Reserved Partitions: Retain the most recent 1 partition, which means that the other partitions except the most recent 1 partition will be deleted.

    • Set Partition Data Retention Time: Retain data in the most recent 12 months. When a partition is deleted, the upper bound of the partition must be earlier than the retention time point. Otherwise, the partition will not be deleted.

    • Rebuild Index after Deletion: Rebuild the index automatically after a partition is deleted.

  7. Click Preview SQL in the lower-right corner of the Partitioning Strategy panel to view the SQL statements generated based on the partition strategy.

  8. Click OK to complete the partition strategy configuration.

Set a partitioning strategy for an OceanBase Oracle compatible mode table

The following example describes how to set a partitioning strategy for the order table in the database named SYS.

  1. In the SQL window, execute the following statement to create the order table.

    CREATE TABLE "SYS"."order" (
    "TIME" DATE NOT NULL ENABLE,
    "KEY" NUMBER(*,0) NOT NULL ENABLE,
    "NAME" VARCHAR2(120) DEFAULT NULL
    ) COMPRESS FOR ARCHIVE REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
    partition by range("TIME", "KEY")
    (partition "p2024_01" values less than (TO_DATE(' 2024-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),20240101),
    partition "p2024_02" values less than (TO_DATE(' 2024-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),20240201));
    
  2. Click Jobs > Partitioning Plan > Create New in the SQL window.

  3. Select the target database, and click edit next to the target partition table to edit the partitioning strategy.

  4. In the configure partitioning strategy panel, select Creation Strategy and Deletion Strategy under Partitioning Strategy to create a partitioning strategy.

  5. In the Create Partitions section, set the partitioning strategy.

    1. Specify the number of partitions to be created.

    2. Create rules.

      For example, you can set a partitioning strategy for the TIME and KEY partitioning keys of the order table.

      • TIME: This partitioning key is of the DATE type and therefore a time type. You can use Sequential Increment as the partitioning strategy for this key. In this example, the creation strategy for the TIME partitioning key is to generate several partitions starting from the current time (that is, the time when the partitioning plan task actually runs) with an interval of 1 month.

      • KEY: This partitioning key is of the NUMBER type. You can use Custom as the partitioning strategy. Assume that you want to generate partitions with an interval of 1 month starting from the current system time as the baseline. To create a custom partitioning strategy, follow the steps outlined in Create a custom partitioning strategy. The expression can be generated in the following steps:

        1. Obtain the baseline time for partition generation. In this example, the current system time is used as the baseline. You can directly use the sysdate function.

        2. Define the interval for partition generation. In this example, partitions are to be generated with an interval of 1 month. To create partitions with an interval of 1 month, set Creation Rule > Rule Details > Interval to NUMTOYMINTERVAL(1, 'MONTH') for fixed intervals, and add this to the expression in step 1 to generate the next partition. The expression will be in a datetime format, such as SYSDATE + ${INTERVAL}, where ${INTERVAL} indicates the value set in Creation Rule > Rule Details > Interval.

        3. Generate an expression for the partitioning key type. The KEY partitioning key is of the NUMBER type, but the expression generated in step 1 is in a datetime format. You need to convert it to the NUMBER type. You can first convert it to a numeric string and then convert it to the NUMBER type. The expression will be TO_CHAR(SYSDATE + ${INTERVAL}, 'YYYYMM"01"').

          Here:

          • TO_CHAR: converts a field to a character string.

          • SYSDATE: returns the current system time.

          • YYYYMM"01": the datetime format.

    3. Select a naming method.

      For example, the selected naming method is Prefix+Suffix, which consists of a fixed prefix and a time-based suffix.

      1. Prefix: You can specify this prefix as you like.

      2. Suffix: You can select the upper bound of a time-type partition key as the suffix for the current partition. You can also specify the datetime format and the increment interval of the time.

      3. After you configure the preceding parameters, click Test Generation to view the partition names.

    4. Copy Statistics from Table's Last Partition to New Partition: No.

  6. In the Delete Partitions section, configure the partition deletion strategy. The following table describes the parameters in the current example.

    • Number of Reserved Partitions: Retain the most recent 200 partitions, which means that the other partitions except the most recent 200 partitions will be deleted.

    • Set Partition Data Retention Time: Retain data in the most recent 12 months. When a partition is deleted, the upper bound of the partition must be earlier than the retention time point. Otherwise, the partition will not be deleted.

    • Rebuild Index after Deletion: Rebuild the index automatically after a partition is deleted.

  7. Click Preview SQL in the lower-right corner of the Partitioning Strategy panel to view the SQL statements generated based on the partition strategy.

  8. Click OK to complete the partition strategy configuration.

References

  • Manage partitioning plans

  • Set partitioning strategies

Previous topic

Set partitioning strategies
Last

Next topic

SQL Plan
Next
on this page
Set a partitioning strategy for an OceanBase MySQL compatible mode table
Set a partitioning strategy for an OceanBase Oracle compatible mode table
References