按日期列上的范围性能进行mysql分区

时间:2015-10-09 17:42:45

标签: mysql partitioning

需要建议对数据库表进行分区。该表有12M行。

我目前构建了以下分区。导致我的查询性能大幅提升。

ALTER TABLE sales_data_mkt
PARTITION BY RANGE ( TO_DAYS(`ACTIVITY_DT`) ) (
    PARTITION p0 VALUES LESS THAN ( TO_DAYS('2015-01-01') ),
    PARTITION p1 VALUES LESS THAN ( TO_DAYS('2015-02-01') ),
    PARTITION p2 VALUES LESS THAN ( TO_DAYS('2015-03-01') ),
    PARTITION p3 VALUES LESS THAN ( TO_DAYS('2015-04-01') ),
    PARTITION p4 VALUES LESS THAN ( TO_DAYS('2015-05-01') ),
    PARTITION p5 VALUES LESS THAN (MAXVALUE)
);

完成所有这些后,我发现您还可以使用To_DAYS()

在没有Partition by Range columns方法的情况下进行分区
ALTER TABLE sales_data_mkt
PARTITION BY RANGE columns (`ACTIVITY_DT`) (
    PARTITION p0 VALUES LESS THAN ('2015-01-01'),
    PARTITION p1 VALUES LESS THAN ('2015-02-01'),
    PARTITION p2 VALUES LESS THAN ('2015-03-01'),
    PARTITION p3 VALUES LESS THAN ('2015-04-01'),
    PARTITION p4 VALUES LESS THAN ('2015-05-01'),
    PARTITION p5 VALUES LESS THAN (MAXVALUE)
);

range columns分区方式的优缺点是什么?它更快吗?

0 个答案:

没有答案