All Products
Search
Document Center

PolarDB:Partitioning functions

Last Updated:Mar 28, 2026

PolarDB-X supports a fixed set of partitioning functions for databases in automatic partitioning mode. Only the functions listed in this topic are supported in partitioning expressions.

Key concepts

Partition key: One or more columns used to horizontally partition a table.

Partition key column: A single column that contributes to a partition key. A partition key consists of one or more partition key columns.

Single-column partition key: A partition key with exactly one column. Example: c1 in PARTITION BY HASH(c1).

Vector partition key: A partition key with one or more partition key columns. Example: (c1,c2,c3) in PARTITION BY HASH(c1,c2,c3).

Partitioning function: A function applied to partition key columns that returns a value PolarDB-X uses to route rows to the correct partition. Example: PARTITION BY HASH(TO_DAYS(c1)).

Monotonicity: The relationship between changes in the input value x and the output of func(x). Monotonicity determines whether PolarDB-X can apply partition pruning to range queries.

Monotonicity typeDefinitionRange query partition pruning
Strict monotonicityIf x > y, then func(x) > func(y). If x < y, then func(x) < func(y).Supported
Non-strict monotonicityIf x > y, then func(x) >= func(y). If x < y, then func(x) <= func(y).Supported
No monotonicityWhen x > y, func(x) may not be >= func(y).Not supported
Functions with no monotonicity (such as MONTH, DAYOFWEEK, DAYOFMONTH, DAYOFYEAR, SUBSTR/SUBSTRING, RIGHT, and LEFT) do not support partition pruning for range queries. Queries using range predicates on partitions keyed by these functions scan all partitions.

Function properties

The following table lists all supported partitioning functions, the minimum PolarDB-X version required, the monotonicity type, and the supported column data types.

Footnotes for the Supported data types column:

  • Integer types: BIGINT, BIGINT UNSIGNED, INT, INT UNSIGNED, MEDIUMINT, MEDIUMINT UNSIGNED, SMALLINT, SMALLINT UNSIGNED, TINYINT, TINYINT UNSIGNED

  • Date and time types: DATE, DATETIME, TIMESTAMP

  • String types: CHAR, VARCHAR

FunctionDescriptionMinimum versionMonotonicityInteger typesDate and time typesString types
YEAR(date)Returns the year of the input date. See YEAR(date) in the MySQL documentation.5.4.13Non-strict-Yes-
MONTH(date)Returns the month of the input date. See MONTH(date) in the MySQL documentation.5.4.13None-Yes-
TO_DAYS(date)Returns the number of days from January 1, 0000 to the input date. See TO_DAYS(date) in the MySQL documentation.5.4.13Non-strict-Yes-
TO_MONTHS(date)Returns the number of months from January 1, 0000 to the input date. This is a PolarDB-X-specific function.5.4.16-16717637Non-strict-Yes-
TO_WEEKS(date)Returns the number of weeks from January 1, 0000 to the input date. This is a PolarDB-X-specific function.5.4.16-16717637Non-strict-Yes-
TO_SECONDS(expr)Returns the number of seconds from January 1, 0000, 00:00:00 to the input time. See TO_SECONDS(expr) in the MySQL documentation.5.4.13Non-strict-Yes-
UNIX_TIMESTAMP([date])Returns the number of seconds from January 1, 1970, 00:00:00 UTC to the input time. See UNIX_TIMESTAMP([date]) in the MySQL documentation.5.4.13Non-strict-Yes-
DAYOFWEEK(date)Returns the day of the week as an integer (1 = Sunday, 2 = Monday, ..., 7 = Saturday). See DAYOFWEEK(date) in the MySQL documentation.5.4.16-16717637None-Yes-
DAYOFMONTH(date)Returns the day of the month as an integer (1-31). See DAYOFMONTH(date) in the MySQL documentation.5.4.16-16717637None-Yes-
DAYOFYEAR(date)Returns the day of the year as an integer (1-366). See DAYOFYEAR(date) in the MySQL documentation.5.4.16-16717637None-Yes-
SUBSTR/SUBSTRINGReturns a substring of the input string. See SUBSTRING() in the MySQL documentation.5.4.16-16717637None--Yes
RIGHT(str, len)Returns the rightmost len characters of the input string. See RIGHT(str,len) in the MySQL documentation.5.4.18-17034692None--Yes
LEFT(str, len)Returns the leftmost len characters of the input string. See LEFT(str,len) in the MySQL documentation.5.4.18-17034692None--Yes

Partitioning policy support

The following table shows which partitioning policies each function supports.

All functions support HASH (single-column), RANGE (single-column), and LIST (single-column). No function supports KEY, HASH (vector), RANGE COLUMNS, LIST COLUMNS, or LIST (vector). CO_HASH support is limited to the string functions.

FunctionKEYHASH (single-column)HASH (vector)RANGE (single-column)RANGE (vector)RANGE COLUMNSLIST (single-column)LIST (vector)LIST COLUMNSCO_HASH
YEARNoYesNoYesNoNoYesNoNoNo
MONTHNoYesNoYesNoNoYesNoNoNo
TO_DAYSNoYesNoYesNoNoYesNoNoNo
TO_MONTHSNoYesNoYesNoNoYesNoNoNo
TO_WEEKSNoYesNoYesNoNoYesNoNoNo
TO_SECONDSNoYesNoYesNoNoYesNoNoNo
UNIX_TIMESTAMPNoYesNoYesNoNoYesNoNoNo
DAYOFWEEKNoYesNoYesNoNoYesNoNoNo
DAYOFMONTHNoYesNoYesNoNoYesNoNoNo
DAYOFYEARNoYesNoYesNoNoYesNoNoNo
SUBSTR/SUBSTRINGNoYesNoYesNoNoYesNoNoYes
RIGHTNoYesNoYesNoNoYesNoNoYes
LEFTNoYesNoYesNoNoYesNoNoYes