mysql primary partition分区

尝试把数据库一个表分区

 

Java代码   收藏代码
  1. ALTER TABLE user   
  2. PARTITION BY RANGE(TO_DAYS(`date`)) (  
  3. PARTITION p1004 VALUES LESS THAN (TO_DAYS('2010-5-1')),  
  4. PARTITION p1005 VALUES LESS THAN (TO_DAYS('2010-6-1')),  
  5. PARTITION p1006 VALUES LESS THAN (TO_DAYS('2010-7-1')),  
  6. PARTITION p1007 VALUES LESS THAN (TO_DAYS('2010-8-1')),  
  7. PARTITION p1008 VALUES LESS THAN (TO_DAYS('2010-9-1')),  
  8. PARTITION p1009 VALUES LESS THAN (TO_DAYS('2010-10-1')),  
  9. PARTITION p1010 VALUES LESS THAN (TO_DAYS('2010-11-1')),  
  10. PARTITION p1011 VALUES LESS THAN (TO_DAYS('2010-12-1')),  
  11. PARTITION p1012 VALUES LESS THAN (TO_DAYS('2011-1-1')),  
  12. PARTITION p9999 VALUES LESS THAN MAXVALUE);  

 结果出现

ERROR 1503  A PRIMARY KEY must include all columns in the table's partitioning function

 

google一下,查出以下解释,来自官方文档,意思是在分区的表达式中的条件字段必须是那个表定义的唯一键的一部分(part of every unique key that the table may have.) 我上面会出错就是因为我在user表定义了主键,但`date`不是主键

解决的话可以把主键ID扩展成联合主键(`ID`,`date`),这样分区的条件字段就成了主键的一部分,这样就可以解决,理论上我想是这样,还没没实际试过, todo。

 

 

18.5.1.Partitioning Keys, Primary Keys, and Unique Keys
This section discusses the relationship of partitioning keys with primary keys and unique keys. The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

 

In other words, every unique key on the table must use every column in the table's partitioning expression. (This also includes the table's primary key, since it is by definition a unique key. This particular case is discussed later in this section.)

转载于:https://www.cnblogs.com/hllnj2008/p/5310454.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值