Chinaunix首页 | 论坛 | 博客
  • 博客访问: 353116
  • 博文数量: 86
  • 博客积分: 1460
  • 博客等级: 上尉
  • 技术积分: 848
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-12 14:07
文章分类

全部博文(86)

文章存档

2017年(36)

2016年(17)

2015年(1)

2013年(12)

2012年(2)

2011年(1)

2010年(1)

2009年(16)

我的朋友

分类: Mysql/postgreSQL

2017-02-17 16:32:41

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.
   目前来看使用上面的函数才会使用分区裁剪功能,待继续测试
阅读(2092) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~