本节讨论 MySQL 分区中与用于分区表达式的函数相关的限制。This section discusses limitations in MySQL Partitioning relating specifically to functions used in partitioning expressions.
只有下列列表中显示的 MySQL 函数允许用于分区表达式:Only the MySQL functions shown in the following list are allowed in partitioning expressions:
CEILING()(参见 CEILING() 和 FLOOR())CEILING()(see CEILING() and FLOOR())EXTRACT()(参见 使用 WEEK 指定符的 EXTRACT() 函数)EXTRACT()(see EXTRACT() function with WEEK specifier)FLOOR()(参见 CEILING() 和 FLOOR())FLOOR()(see CEILING() and FLOOR())UNIX_TIMESTAMP()(适用于TIMESTAMP列)UNIX_TIMESTAMP()(withTIMESTAMPcolumns)
在 MySQL 8.4 中,分区修剪支持 TO_DAYS()、TO_SECONDS()、YEAR() 和 UNIX_TIMESTAMP() 函数。有关更多信息,请参见 第 26.4 节,“分区修剪”。In MySQL 8.4, partition pruning is supported for
the TO_DAYS(),
TO_SECONDS(),
YEAR(), and
UNIX_TIMESTAMP() functions. See
Section 26.4, “Partition Pruning”, for more information.
CEILING() 和 FLOOR()。 这些函数只有在传入精确数值类型的参数时才返回整数,例如 INT 类型或 DECIMAL。这意味着,例如,以下 CREATE
TABLE 语句会因错误而失败,如下所示:CEILING() and FLOOR().
Each of these functions returns an integer only if it is
passed an argument of an exact numeric type, such as one of
the INT types or
DECIMAL. This means, for
example, that the following CREATE
TABLE statement fails with an error, as shown here:
mysql>CREATE TABLE t (c FLOAT) PARTITION BY LIST( FLOOR(c) )(->PARTITION p0 VALUES IN (1,3,5),->PARTITION p1 VALUES IN (2,4,6)->);ERROR 1490 (HY000): The PARTITION function returns the wrong type
带有 WEEK 指定符的 EXTRACT() 函数。 当 EXTRACT() 函数以 EXTRACT(WEEK FROM
col) 的形式使用时,其返回值取决于 default_week_format 系统变量的值。因此,当指定单位为 WEEK 时,不允许将 EXTRACT() 用作分区函数。(Bug #54483)EXTRACT() function with WEEK specifier.
The value returned by the
EXTRACT() function, when used
as EXTRACT(WEEK FROM
, depends on the
value of the
col)default_week_format system
variable. For this reason,
EXTRACT() is not permitted as a
partitioning function when it specifies the unit as
WEEK. (Bug #54483)
有关这些函数的返回类型的更多信息,请参见第 14.6.2 节,“数学函数”,以及第 13.1 节,“数值数据类型”。See Section 14.6.2, “Mathematical Functions”, for more information about the return types of these functions, as well as Section 13.1, “Numeric Data Types”.