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.)

  • 相关阅读:
    字符串的全排列

    链表
    青蛙跳一格或者两格,n格跳法
    二叉树
    Concurrent实现原理
    sql语句总结 (转) http://blog.csdn.net/fengfeng91/article/details/15029173
    ArrayList实现原理
    java虚拟机 内存分配
    【转】关于Quartus ii无法识别Modelsim路径的问题
  • 原文地址:https://www.cnblogs.com/hllnj2008/p/5310454.html
Copyright © 2011-2022 走看看