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

  • 相关阅读:
    Android自动化测试解决方案
    Oracle数据库的DML命令的处理过程详解
    Oracle数据库的BULK COLLECT用法之批量增删改
    建设DevOps能力,实现业务敏捷
    强大的C# Expression在一个函数求导问题中的简单运用
    Visual Studio 11开发者预览版发布(附下载)
    js table隔行变色
    编译原理语法推导树
    巧用数据库归档技术解决性能下降问题
    编译原理正规式和有限自动机
  • 原文地址:https://www.cnblogs.com/hllnj2008/p/5310454.html
Copyright © 2020-2023  润新知