使用 DATE 和 RANGE COLUMNS 进行分区修剪
Partition Pruning using DATE and RANGE COLUMNS
我正在尝试使用 DATE 列对数据库进行分区,以利用 MySQL 5.7 中的分区修剪功能。由于内部原因,我需要按 RANGE COLUMNS
进行分区,因为 add/drop 分区既简单又快速。
虽然 the MySQL website 说:
The optimizer can also perform pruning for WHERE conditions that involve comparisons of the preceding types on multiple columns for tables that use RANGE COLUMNS or LIST COLUMNS partitioning.
它还说:
This type of optimization can be applied whenever the partitioning expression consists of an equality or a range which can be reduced to a set of equalities, or when the partitioning expression represents an increasing or decreasing relationship. Pruning can also be applied for tables partitioned on a DATE or DATETIME column when the partitioning expression uses the YEAR() or TO_DAYS() function. In addition, in MySQL 5.7, pruning can be applied for such tables when the partitioning expression uses the TO_SECONDS() function.
这似乎是矛盾的。我想知道是否可以对 DATE 列进行分区,例如:
PARTITION BY RANGE COLUMNS(date) (
PARTITION partition_2016_04_28 VALUES LESS THAN ('2016-04-28'),
PARTITION partition_2016_04_29 VALUES LESS THAN ('2016-04-29'),
PARTITION partition_2016_04_30 VALUES LESS THAN ('2016-04-30')
);
并且仍然利用分区修剪?如果可能的话,我想避免使用 TO_DAYS 函数,因为它使表格更干净、更易于使用。有什么想法吗?
我创建了自己的表并编写了自己的查询。使用 EXPLAIN PARTITIONS
我发现使用这种方法对日期进行分区实际上使用了分区修剪。
我正在尝试使用 DATE 列对数据库进行分区,以利用 MySQL 5.7 中的分区修剪功能。由于内部原因,我需要按 RANGE COLUMNS
进行分区,因为 add/drop 分区既简单又快速。
虽然 the MySQL website 说:
The optimizer can also perform pruning for WHERE conditions that involve comparisons of the preceding types on multiple columns for tables that use RANGE COLUMNS or LIST COLUMNS partitioning.
它还说:
This type of optimization can be applied whenever the partitioning expression consists of an equality or a range which can be reduced to a set of equalities, or when the partitioning expression represents an increasing or decreasing relationship. Pruning can also be applied for tables partitioned on a DATE or DATETIME column when the partitioning expression uses the YEAR() or TO_DAYS() function. In addition, in MySQL 5.7, pruning can be applied for such tables when the partitioning expression uses the TO_SECONDS() function.
这似乎是矛盾的。我想知道是否可以对 DATE 列进行分区,例如:
PARTITION BY RANGE COLUMNS(date) (
PARTITION partition_2016_04_28 VALUES LESS THAN ('2016-04-28'),
PARTITION partition_2016_04_29 VALUES LESS THAN ('2016-04-29'),
PARTITION partition_2016_04_30 VALUES LESS THAN ('2016-04-30')
);
并且仍然利用分区修剪?如果可能的话,我想避免使用 TO_DAYS 函数,因为它使表格更干净、更易于使用。有什么想法吗?
我创建了自己的表并编写了自己的查询。使用 EXPLAIN PARTITIONS
我发现使用这种方法对日期进行分区实际上使用了分区修剪。