zoukankan      html  css  js  c++  java
  • 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.)

  • 相关阅读:
    ActiveJDBC 学习笔记
    selenium相关技术研究(从1.0-3.0)
    如何记录selenium自动化测试过程中接口的调用信息
    TestNG进行接口测试,脚本及可维护性框架
    贪多必失,精通一样再往下一样
    测试开发之路:英雄迟暮,我心未老
    接口测试面试题
    自动化测试中的滚动
    maven配置环境变量失败解决办法
    注释——创建新的类(文件)时,自动添加作者创建时间(文件注释)等信息的设置方法
  • 原文地址:https://www.cnblogs.com/hllnj2008/p/5310454.html
Copyright © 2011-2022 走看看