需要建议对数据库表进行分区。该表有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
分区方式的优缺点是什么?它更快吗?