Ben Kimpel
04/08/2026, 7:09 PMRocky
04/08/2026, 7:10 PMSTART, END, and EVERY syntax within the PARTITION BY RANGE clause.
sql
CREATE TABLE sales_data (
order_date DATE,
order_id INT,
total_amount DECIMAL(18, 2)
)
DUPLICATE KEY(order_date, order_id)
PARTITION BY RANGE (order_date) (
START ("2023-01-01") END ("2025-01-01") EVERY (INTERVAL 6 MONTH)
)
DISTRIBUTED BY HASH(order_id);
How it works:
* START / END: Defines the overall time range for the partitions.
* EVERY (INTERVAL 6 MONTH): Tells StarRocks to divide that range into 6-month buckets.
* The system will automatically name these partitions based on the interval (e.g., p202301, p202307).
──────────
Method 2: Expression Partitioning (Automatic/Recommended)
For a more modern approach where StarRocks automatically creates partitions as data arrives, you can use the time_slice function. This is often preferred because it handles new data without requiring you to manually add partitions in advance.
sql
CREATE TABLE sales_data (
order_date DATE,
order_id INT,
total_amount DECIMAL(18, 2)
)
DUPLICATE KEY(order_date, order_id)
-- This will automatically group data into 6-month slices
PARTITION BY time_slice(order_date, INTERVAL 6 MONTH)
DISTRIBUTED BY HASH(order_id);
Benefits:
* Automation: You don't need to specify START or END dates; partitions are created on the fly based on the order_date of the incoming data.
* Maintenance: Reduces the need for ALTER TABLE ADD PARTITION scripts.
Summary of Differences
Feature | Batch Partitioning (EVERY) | Expression Partitioning (time_slice)
Setup | Defined once at table creation | Defined at creation, scales automatically
Control | Precise control over start/end dates | Dynamic based on data
Maintenance | Need to add more partitions later | Zero-maintenance for new periods
If you are using StarRocks v3.1 or later, the Expression Partitioning method (time_slice) is generally the most efficient and easiest way to manage custom intervals like-sized time buckets.
References
• sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.md
• using_starrocks/async_mv/use_cases/create_partitioned_materialized_view.md
• table_design/data_distribution/expression_partitioning.md
• using_starrocks/async_mv/Materialized_view.md
• using_starrocks/Cost_based_optimizer.md
• best_practices/partitioning.md