1.尽量使用够用的类型
create table table_name
( col1 int not null auto_increment comment 'primary key',
col2 int not null default 1 comment 'test',
col3 varchar(20) not null default 'abc' comment 'col3',
updatetime timestamp not null default current_timestamp,
createtime datetime not null default current_timestamp unique key comment 'col4',
primary key(col1,createtime)
)
comment 'The table is test'
partition by range(year(createtime))
(
partition P201701 values less than (2017),
partition P201702 values less than (2018),
partition Pmax values less than maxvalue
);
或者建分区
create table ttt (date datetime)
partition by range (to_days(date)) (
partition p201201 values less than (to_days('2012-02-01')),
partition p201202 values less than (to_days('2012-03-01')),
partition p201203 values less than (to_days('2012-04-01'))
);
1.列comment 表comment 一定要有,方便以后查看具体含义
2. 主键使用int 自增(最大42亿行,大部分应该满足) bigint(1800亿亿行数据,一般用不到这么多数据)
3. not null default 尽量都要加上 unsigned 最好也添加上
4. 按时间分区表,时间字段必须是datetime或者date,不能使用timestamp 否则报错,主键必须是原主键+分区键,如果有其他唯一索引还需要添加到主键里面
ERROR 1486 (HY000): Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
5. select * from table_name partition (p2017); alter table table_name drop partition (p2017);
操作和oracle 差不多哦,
6. MySQL partitioning is optimized for use with the
TO_DAYS(),
YEAR(), and
TO_SECONDS() functions.
目前来看使用上面的函数才会使用分区裁剪功能,待继续测试
阅读(2154) | 评论(0) | 转发(0) |