日期:2014-05-16  浏览次数:20747 次

mysql 分区问题!!!
我创建了一个表:
create table mytest(
  id int not null,
  starttime timestamp,
  primary key(id, starttime)
)
现在想根据周来分区,该怎么写???
如果想让它这样循环下去,又该怎么写,或者说可以自动添加分区

------解决方案--------------------
-- 一般都是根据月来分区,你根据周来分区能有什么好处呢?
------解决方案--------------------
SQL code
-- 按月分区给个例子给你:

ALTER TABLE mytest
partition BY range(to_days(starttime)) (
partition p_2010   VALUES LESS THAN (to_days('2011-01-01')),
partition p_201101 VALUES LESS THAN (to_days('2011-02-01')),
partition p_201102 VALUES LESS THAN (to_days('2011-03-01')),
partition p_201103 VALUES LESS THAN (to_days('2011-04-01')),
partition p_201104 VALUES LESS THAN (to_days('2011-05-01')),
partition p_201105 VALUES LESS THAN (to_days('2011-06-01')),
partition p_201106 VALUES LESS THAN (to_days('2011-07-01')),
partition p_201107 VALUES LESS THAN (to_days('2011-08-01')),
partition p_201108 VALUES LESS THAN (to_days('2011-09-01')),
partition p_201109 VALUES LESS THAN (to_days('2011-10-01')),
partition p_201110 VALUES LESS THAN (to_days('2011-11-01')),
partition p_201111 VALUES LESS THAN (to_days('2011-12-01')),
partition p_201112 VALUES LESS THAN (to_days('2012-01-01')),
partition p_2012   VALUES LESS THAN (to_days('2013-01-01')),
partition p_max    VALUES LESS THAN (maxvalue) );

------解决方案--------------------
用组合分区吧 单独分区的话 数据量还是太大
------解决方案--------------------
一周300W那按周来分区可以
------解决方案--------------------
按YEARWEEK分就行了。

partition BY range(YEARWEEK(starttime))