All Products
Search
Document Center

PolarDB:RANGE partitioning

Last Updated:Mar 28, 2026

RANGE partitioning divides table rows into partitions based on whether a column value falls within a defined range. Each partition stores rows whose values are less than the specified boundary, making it well-suited for time-series data and ordered numeric sequences.

When to use RANGE partitioning

RANGE partitioning is particularly useful when:

  • Data has a time dimension: You store logs, events, or transactions by date and want to drop old data efficiently with ALTER TABLE ... DROP PARTITION instead of running large DELETE queries.

  • Queries filter by the partition key: MySQL-compatible engines can skip entire partitions when the WHERE clause matches the partition key, improving query performance on large tables.

  • Data grows monotonically: Order IDs, event sequences, or timestamps naturally map to incremental ranges, keeping partition boundaries stable.

For a comparison of RANGE partitioning and RANGE COLUMNS partitioning, see the Comparison between RANGE partitioning and RANGE COLUMNS partitioning table in the partition types overview.

Syntax

CREATE TABLE ...
PARTITION BY RANGE(partition_expr) [PARTITIONS number]
(
  PARTITION part_name VALUES LESS THAN (range_bound_value),
  PARTITION part_name VALUES LESS THAN (range_bound_value),
  ...
)

partition_expr:
    partition_column
  | partition_func(partition_column)

-- Supported partitioning functions
partition_func:
    TO_DAYS
  | TO_MONTHS
  | TO_WEEKS
  | TO_SECOND
  | UNIX_TIMESTAMP
  | MONTH
  | DAYOFWEEK
  | DAYOFMONTH
  | DAYOFYEAR
  | SUBSTR
  | SUBSTRING
  | RIGHT
  | LEFT

Key parameters:

ParameterDescription
partition_exprThe expression that determines which partition a row belongs to. Use a bare column name or wrap it in a supported partitioning function.
partition_funcA built-in function that transforms the column value before comparison. Only supported for single-column partition keys.
part_nameA unique name for the partition, up to 16 characters.
range_bound_valueThe exclusive upper bound for the partition. Boundaries must be strictly ascending. Use MAXVALUE as a catch-all upper bound for the last partition.

Limitations

LimitationDetails
Partitioning functionsSupported for single-column partition keys only. Not supported for multi-column (vector) partition keys.
Nested functionsNested partitioning functions are not supported.
Partition name lengthMust be unique and can be up to 16 characters.
TIMESTAMP columnsMust use the UNIX_TIMESTAMP partitioning function when the partition key column uses a time zone-sensitive type such as TIMESTAMP.
Maximum partitionsUp to 8,192 partitions per table.
Maximum partition key columnsUp to five columns.

Examples

Partition by date using a partitioning function

Use TO_DAYS to convert a DATETIME column to a day count, then partition by those day values. This is the standard approach for time-based RANGE partitioning with DATETIME or DATE columns.

CREATE TABLE tb_r_fn(
  id bigint NOT NULL AUTO_INCREMENT,
  bid int,
  name varchar(30),
  birthday datetime NOT NULL,
  PRIMARY KEY(id)
)
PARTITION BY RANGE(TO_DAYS(birthday))
(
  PARTITION p1 VALUES LESS THAN(TO_DAYS('2020-01-01')),
  PARTITION p2 VALUES LESS THAN(TO_DAYS('2021-01-01')),
  PARTITION p3 VALUES LESS THAN(TO_DAYS('2022-01-01')),
  PARTITION pm VALUES LESS THAN(MAXVALUE)
);

For TIMESTAMP columns, use UNIX_TIMESTAMP instead of TO_DAYS. For other supported functions, see Partitioning functions.

Partition by integer range without a partitioning function

When the partition key is an integer column, reference it directly without a partitioning function.

CREATE TABLE tb_r(
  id bigint NOT NULL AUTO_INCREMENT,
  bid int,
  name varchar(30),
  birthday datetime NOT NULL,
  PRIMARY KEY(id)
)
PARTITION BY RANGE(id)
(
  PARTITION p1 VALUES LESS THAN(1000),
  PARTITION p2 VALUES LESS THAN(2000),
  PARTITION p3 VALUES LESS THAN(3000),
  PARTITION pm VALUES LESS THAN(MAXVALUE)
);

Partition by multiple columns (auto-conversion to RANGE COLUMNS)

When you specify a multi-column (vector) partition key in a PARTITION BY RANGE(...) clause, PolarDB for Xscale automatically converts it to PARTITION BY RANGE COLUMNS(...).

Original RANGE definition with a vector partition key:

CREATE TABLE tb_r(
  id bigint NOT NULL AUTO_INCREMENT,
  bid int,
  name varchar(30),
  birthday datetime NOT NULL,
  PRIMARY KEY(id)
)
PARTITION BY RANGE(bid, id)
(
  PARTITION p1 VALUES LESS THAN(1, 1000),
  PARTITION p2 VALUES LESS THAN(2, 2000),
  PARTITION pm VALUES LESS THAN(MAXVALUE, MAXVALUE)
);

Equivalent RANGE COLUMNS definition after auto-conversion:

CREATE TABLE tb_r(
  id bigint NOT NULL AUTO_INCREMENT,
  bid int,
  name varchar(30),
  birthday datetime NOT NULL,
  PRIMARY KEY(id)
)
PARTITION BY RANGE COLUMNS(bid, id)
(
  PARTITION p1 VALUES LESS THAN(1, 1000),
  PARTITION p2 VALUES LESS THAN(2, 2000),
  PARTITION pm VALUES LESS THAN(MAXVALUE, MAXVALUE)
);

Supported data types

The following column data types are supported as RANGE partition keys:

CategorySupported types
IntegerBIGINT, BIGINT UNSIGNED, INT, INT UNSIGNED, MEDIUMINT, MEDIUMINT UNSIGNED, SMALLINT, SMALLINT UNSIGNED, TINYINT, TINYINT UNSIGNED
Date and timeDATETIME, DATE, TIMESTAMP
StringCHAR, VARCHAR

What's next