OceanBase Partitioning Fundamentals
Introduction
Analytical workloads usually need to perform analytical computation over massive amounts of data, placing high demands on a database’s query capability and data management capability. Through partitioning, OceanBase horizontally splits a table’s data into multiple subsets according to the partition key, which helps improve query efficiency and data management:
1. Improved query efficiency: partition pruning can reduce scans of irrelevant data.
2. Data maintenance: supports managing data at partition granularity, such as data archiving and cleanup.
3. Data distribution: distributing data at partition granularity can spread data across multiple nodes, giving good scalability.
This article first introduces the role of partitioning in OceanBase, then describes the basic partitioning methods in OceanBase and their applicable scenarios, and finally discusses how OceanBase’s flexible partition management capabilities apply to business scenarios such as data maintenance and data management.
The Role of Partitioning in OceanBase
In OceanBase, a partition is the basic unit of horizontal sharding — the smallest physical unit of data distribution, load balancing, and parallel operations. A large table is logically split into multiple smaller, more manageable independent chunks, and each partition (or even different replicas of a partition) can be distributed across different OBServer nodes in the cluster.
This design brings a fundamental advantage to analytical workloads: when a single node’s storage or compute capacity becomes a bottleneck, you can achieve near-linear horizontal scaling by adding nodes and redistributing partitions, thereby handling PB-scale data volumes.
Partition Pruning Improves Query Efficiency
With partitioning, when you query by specifying the partition column, in some scenarios the engine can prune out the partitions that satisfy the query condition, so the query doesn’t need to scan the partitions that don’t.
Consider the following example. We create a hash partition on column c2, and specifying the query condition c2=1 allows pruning down to only partition p1.
1 | -- Create a table t1 with four hash partitions, partition key c2 |
Partition pruning can filter out unneeded data, but too many partitions can cause other problems — for example, excessive metadata or reduced pruning efficiency. Therefore, in OceanBase columnar tables, it’s recommended that the number of rows per partition be >= 1 million.
Partitioning as a Data Maintenance Unit
In database operations, using the partition as the basic data-maintenance unit can greatly simplify day-to-day management — for example, data cleanup scenarios and partition-level statistics collection. Take data cleanup: once data is partitioned by time, cleaning up expired data no longer requires deleting it row by row; instead, you simply drop the entire historical partition. This operation only modifies metadata, yet it also fully releases disk space, avoiding the performance overhead of a traditional DML delete. By naturally categorizing data via the partition key (such as time), maintenance operations shift from “row-by-row scanning” to “batch processing,” dramatically improving management efficiency and lowering operational complexity.
Partitioning as a Data Distribution Unit
As OceanBase’s data distribution unit, each partition’s replicas can be placed on different OBServer nodes to scale both storage and compute.
1. Storage scaling: when you create a partitioned table, these partitions and their replicas can be automatically scheduled onto different physical nodes by OceanBase based on the cluster’s resource situation. This means a single table’s capacity is no longer limited by a single machine’s disk, but by the storage capacity of the entire cluster; when the cluster runs short of storage, you can scale out simply by adding nodes.
2. Compute parallelism: this is one of the keys to high performance for analytical workloads. When a query is executed (especially one involving a full-table scan or large-scale aggregation), OceanBase’s optimizer identifies the partitions the query involves. The query task can be decomposed into multiple subtasks and pushed down to the nodes where each data partition resides, to execute in parallel. For example, a SUM() operation first computes a subtotal locally within each partition, then aggregates the intermediate results to get the final total. This fully leverages the compute power of multiple nodes, significantly accelerating the query.
OceanBase’s Basic Partitioning Methods
OceanBase currently supports three major categories of basic partitioning methods: Hash/Key, Range/Range Columns, and List/List Columns. Each of the three has somewhat different use cases.
HASH/KEY Partitioning
Generally suited to cases where the partition column’s NDV (number of distinct values) is large and hard to divide into clear ranges. The advantage is that it easily distributes data with no particular pattern evenly across partitions; the disadvantage is that partition pruning is hard during range queries.
Example use case: no obvious query pattern, and data needs to be distributed evenly across multiple nodes (e.g., user ID, transaction ID).
Design points:
- Partition key selection:
- NDV (number of distinct values) far greater than the number of partitions (e.g., the NDV of user ID should be far greater than the number of partitions).
- Prefer skew-free (or only slightly skewed) integer/time columns (e.g., user_id, order_time, or an auto-increment column).
- High-frequency query condition fields (e.g., user_id used as a Join key).
- Recommended number of partitions:
- Ensure the number of partitions matches the number of machines in the cluster, to avoid uneven resource allocation.
Example scenario (Hash partitioning use case)
1 | -- Hash partitioning, distributed evenly by user_id |
Range/Range Columns Partitioning
Generally suited to cases where the partition key can be easily divided into clear ranges — for example, a large table recording transaction/log information can be RANGE-partitioned by the column representing the information’s timestamp.
Example use cases:
- Data grows by time/value range (e.g., order_time, price).
- Need to quickly prune historical data (e.g., querying only the last month’s data).
Design points:
- Partition key selection:
- A time field (e.g., order_time) or a continuous numeric field.
- Partition boundaries should align with business query conditions (e.g., divided by day/month).
- Recommended number of partitions:
- Set partitions according to data growth, e.g., partitioning by month.
Example scenario (Range/Range Columns partitioning example)
1 | -- Create a system log table, RANGE-partitioned monthly by log time, supporting fast queries and data archiving |
List/List Columns Partitioning
Generally suited to cases where you need to explicitly control how each row maps to a specific partition. The advantage is that it can precisely partition unordered or unrelated datasets; the disadvantage is that partition pruning is hard during range queries.
Example use cases:
- Discrete fields (e.g., region, channel type).
- Need to quickly prune data by fixed category (e.g., querying users in the East China region).
Design points:
- Partition key selection:
- Discrete values with a limited count (e.g., the region field has only [‘east’,’west’,’south’,’north’]).
- Partition values must cover all possible values, with no omissions.
- Partition count limits:
- Configure the number of partitions according to business logic.
Example scenario (List/List Columns partitioning use case)
1 | CREATE TABLE orders_by_region( |
Flexible Partition Management Capabilities
OceanBase has very flexible partition management capabilities. From a data management perspective, it provides both data maintenance and data distribution functions; in terms of usage, it offers both manual and automatic management; and in terms of partition hierarchy, it supports combining primary partitions and secondary partitions. Through different combinations, it meets users’ varied data-management needs.
This section unfolds from the two angles of data maintenance and data distribution, considering within each angle the combination of usage methods and partition-hierarchy capabilities.
Data Maintenance
The business layer usually manages partitions along the time dimension, which makes operations like data archiving and cleanup convenient. We describe our manual partition management capabilities in the context of the complete data lifecycle of a business.
1. Business table creation: create a table partitioned by time, pre-creating the partitions needed for some period into the future.
2. Business data import: import the data.
3. Business running: as time advances, the pre-created partitions may run short, so continue pre-creating the partitions needed for some period into the future.
4. Periodic data cleanup: once data has accumulated for a certain period, the earlier data may no longer be needed, at which point you can drop the unneeded partitions.
Below is a concrete example of the above use case:
1 | -- 1. Create a partitioned table (partitioned by day, pre-creating partitions for the next 7 days) |
Since data keeps being written in, manually maintaining pre-created partitions and periodically cleaning up partitions is fairly cumbersome. To simplify this process, OceanBase provides a dynamic partitioning feature, supporting partitioning by a fixed time, how far ahead to pre-create partitions, how long to retain historical partitions, and so on. For the example above, suppose we need to retain 30 days of data and pre-create 7 days of partitions each time; then we use the following syntax to create it:
1 | -- 1. Create a partitioned table, setting the dynamic partitioning policy |
Besides the Range partitioning mode, businesses can also choose other basic partitioning methods as needed.
Data Distribution
A partition can also serve as the unit of data distribution management. Usually, to spread data out, HASH partitioning is used, which has the following advantages:
- It generally achieves good data spreading and also fairly accurate partition pruning;
- For multiple tables that need to Join, if you hash-partition by the join key and keep the partition counts identical, then together with OceanBase’s table group capability, partitions with the same hash rule and corresponding index are bound together — enabling Partition-Wise Join during joins and avoiding data shuffling.
HASH partitioning also has some drawbacks:
- Once the number of HASH partitions is set, changing it is a fairly heavy operation that involves rewriting the entire table’s data. So generally, once the HASH partition count is set, it stays fixed, making scalability hard to achieve;
- For range queries on the partition key, no partitions can be pruned and all partitions must be accessed, which may incur read amplification.
To solve the scalability and range-query problems of HASH partitioning, OceanBase already supports automatic partition splitting for row-store tables, and in a future version it will also offer two automatic-partition-splitting modes for columnar tables: the heap-table splitting mode and the clustering-key-table splitting mode.
The heap-table splitting mode partitions automatically based on the heap table’s hidden primary-key column. Because the hidden primary key is randomly generated in this splitting mode, and because the number of partitions automatically expands or shrinks when a tenant’s machine resources scale up or down, this mode can scale automatically and has good scalability. However, in this mode the data rows are randomly distributed across arbitrary partitions, so no partition pruning is possible, and query performance may not be optimal. This mode suits cases that don’t have high performance requirements, don’t want to provide a manual or automatic partition key, but still want the table to scale automatically.
The clustering-key-table splitting mode partitions automatically based on a user-specified clustering key, automatically splitting partitions of appropriate size by data volume. When a tenant’s machine resources scale up or down, since there are already enough split partitions, these partitions can be rebalanced. Because this mode splits automatically by the clustering key, when a query can specify the clustering key — whether a point lookup or a range query — partition pruning is possible, so query performance is fairly good, and it can also adaptively scale up or down based on machine resources. At the same time, clustering-key-table automatic splitting can also support configuring a table group for multiple tables that need to Join: the auto-split key can be configured as the join key, also enabling Partition-Wise Join.
To make this easier to understand, the characteristics of the three methods — Hash, heap-table splitting, and clustering-key-table splitting — are compared below:

Besides the above partitioning methods, businesses can also choose other basic partitioning methods as needed.
Mixing Data Maintenance and Data Distribution Management
We can also use secondary partitioning to support both data-maintenance and data-distribution needs at once. The most commonly used scenario is the primary partition for data-maintenance needs and the secondary partition for data-distribution needs, with each need combined using the methods that need supports.
A Typical Manual Partition Management Approach
- Primary partition:
- Type selection: use Range or List partitioning to match high-frequency query conditions (e.g., time range, region).
- Partition-count suggestion: set a reasonable range based on the time distribution of query conditions and the data-maintenance needs (e.g., monthly partitions retaining 12 months, or 4 List partitions by region).
- Secondary partition:
- Type selection: use Hash partitioning to ensure data spreading.
- Recommended number of partitions:
- If only one primary partition is written, then that primary partition’s number of secondary partitions must satisfy the resource needs for spreading out writes.
- If multiple primary partitions can be written, then it’s enough that (number of writable primary partitions) × (number of secondary partitions) satisfies the resource needs for spreading out writes.
Below are two scenario cases, Range + Hash and List + Hash:
1. Range + Hash: the primary partition uses Range partitioning; specifying order_date lets you quickly filter out partitions whose data doesn’t need scanning, and you can also quickly perform data maintenance via partition management operations. The secondary partition uses Hash partitioning, spreading the current month’s writes or reads across 8 partitions to avoid hot spots.
1 | CREATE TABLE orders( |
2. List + Hash: the primary partition uses List partitioning; specifying the province can prune to the corresponding partition, and data maintenance can also be done at the province level. The secondary partition uses Hash/Key partitioning, spreading a province’s read/write traffic across multiple partitions for load balancing.
1 | -- Primary partition: LIST partitioned by province (31 provincial-level administrative regions) |
A Typical Automatic Partition Management Approach
- Primary partition: choose dynamic partitioning, configuring parameters such as partitioning by a fixed time, how far ahead to pre-create partitions, and how long to retain historical partitions;
- Secondary partition: choose automatic Range partition splitting, which can split automatically without configuring the number of partitions or a partitioning rule.
Summary
OceanBase currently supports the common basic partitioning methods, and by combining them it can meet a business’s needs for data maintenance, data distribution, and improved query efficiency. Dynamic partitioning provides standard automated management for the general need of time-based partitioned data maintenance, reducing the cost of data maintenance for users. In the future, we will strengthen automatic partition management capabilities, supporting automatic partition splitting for columnar tables — reducing the current cost and scalability problems of manual data-distribution maintenance — and further improving the data-management automation of columnar tables, making it easier for analytical workloads to use OceanBase.