For the complete documentation index, see llms.txt. This page is also available as Markdown.

RANGE COLUMNS INTERVAL Partitioning Type

A RANGE COLUMNS variant that adds new partitions automatically, by a fixed time interval, as data is written.

INTERVAL for RANGE COLUMNS partitioning was added in MariaDB 13.1.

Adding an INTERVAL clause to a RANGE COLUMNS partitioned table makes the server extend the table's partitions automatically. You define one starting partition; whenever a write reaches the table, MariaDB adds as many partitions of the given interval as it takes for the newest partition to cover the current date and time.

This removes the routine maintenance that a time-ranged table normally needs, where a scheduled job or a person has to run ALTER TABLE ... ADD PARTITION before the data catches up with the last defined partition.

In every other respect the table behaves like an ordinary RANGE COLUMNS partitioned table.

Syntax

PARTITION BY RANGE COLUMNS (col_name)
INTERVAL interval_expression time_unit [AUTO]
(
	PARTITION partition_name VALUES LESS THAN (value)
	[, PARTITION partition_name VALUES LESS THAN (value) ... ]
)

Oracle's interval functions are accepted as an alternative spelling of the interval:

PARTITION BY RANGE COLUMNS (col_name)
INTERVAL ( NUMTODSINTERVAL(number, 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND') )
(
	PARTITION partition_name VALUES LESS THAN (value)
	[, PARTITION partition_name VALUES LESS THAN (value) ... ]
)

PARTITION BY RANGE COLUMNS (col_name)
INTERVAL ( NUMTOYMINTERVAL(number, 'YEAR' | 'MONTH') )
(
	PARTITION partition_name VALUES LESS THAN (value)
	[, PARTITION partition_name VALUES LESS THAN (value) ... ]
)

The AUTO keyword is optional and has no effect — automatic partition creation is always enabled when an INTERVAL clause is present. SHOW CREATE TABLE does not report it.

Requirements and Restrictions

  • Exactly one partitioning column, of type DATE, DATETIME or TIMESTAMP. TIMESTAMP is permitted only in combination with INTERVAL; plain RANGE COLUMNS partitioning rejects it.

  • At least one partition must be defined. PARTITION BY RANGE COLUMNS (col) INTERVAL 1 DAY on its own fails with For RANGE partitions each partition must be defined.

  • No partition may use MAXVALUE, at table creation or later through ALTER TABLE ... ADD PARTITION. A MAXVALUE partition would swallow every future row and make automatic creation pointless.

  • The interval must be positive and must not carry a sub-second component. INTERVAL 1.1 SECOND_MICROSECOND is rejected, as are INTERVAL 0 DAY and INTERVAL -1 DAY.

  • For a DATE column, the interval must be at least one day.

  • NUMTODSINTERVAL() accepts only DAY, HOUR, MINUTE and SECOND; NUMTOYMINTERVAL() accepts only YEAR and MONTH. In both forms the number must be greater than zero.

  • The interval may be an expression, but not a subquery or a stored function call.

  • LIST COLUMNS partitioning does not accept INTERVAL.

  • Subpartitioning is allowed, restricted as usual to [LINEAR] KEY and [LINEAR] HASH.

  • The 8192-partition limit still applies. A short interval combined with an old starting partition can reach it in a single statement, which fails with Too many partitions (including subpartitions) were defined.

How Partitions Are Added

The upper bound of the highest partition is the transition point. When a write arrives, the server repeatedly adds the interval to that bound until it passes the current date and time, and creates one partition per step. New partitions are named pN, where N is chosen from the first gap in the existing pN names that is large enough to hold all of them.

Automatic creation happens for these statements:

It also happens when one of those statements runs inside a trigger body, and on a replica when it applies the corresponding row events. Read-only statements and DDL never create partitions.

Rows earlier than the lowest partition are not accommodated either; partitions are only ever added at the top. Automatic creation happens only in DML, so an ALTER TABLE that introduces an INTERVAL clause whose starting partition does not already cover the existing rows fails.

Transactions and Replication

Adding partitions does not cause the implicit commit that DDL normally would, so the surrounding transaction stays open. If that transaction is rolled back, the rows are undone but the new partitions remain.

The implicit ADD PARTITION is not written to the binary log. A replica creates the same partitions itself while applying the row events, so primary and replica converge without a separate DDL event.

Examples

Start from a single partition covering everything before 20 April 2026, and add a day's worth at a time:

With the server clock at 2 May 2026, a single insert fills in the missing days:

The same table using Oracle's interval spelling, and a TIMESTAMP column:

Subpartitioned by KEY:

INTERVAL can be added to or removed from an existing table by repartitioning it:

See Also

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?