我按年月对数据表进行分区,如下命令
但是却出现错误:ERROR 1564 (HY000): This partition function is not allowed
是不是mysql不允许用DATE_FORMAT进行分区呢?
ALTER TABLE E_info PARTITION BY RANGE(DATE_FORMAT(info_time, 'YY-MM'))  
(     
    PARTITION p_2009_04 VALUES LESS THAN (2009-05),     
    PARTITION p_2009_03 VALUES LESS THAN (2009-04),     
    PARTITION p_2009_02 VALUES LESS THAN (2009-03),     
    PARTITION p_2009_01 VALUES LESS THAN (2009-02),      
    PARTITION p_2008_12 VALUES LESS THAN (2009-01),     
    PARTITION p_2008_11 VALUES LESS THAN (2008-12),    
    PARTITION p_catch_all VALUES LESS THAN MAXVALUE 
); 

解决方案 »

  1.   

    改一下用数字格式的表达式 PARTITION BY RANGE(info_time/100)
    
      

  2.   


    也不行:mysql> ALTER TABLE E_info PARTITION BY RANGE(info_time/100)  (     PARTITION p_2009_04 VALUES LESS THAN (2009-05),     PARTITION p_2009_03 VALUES LESS THAN (2009-04),     PARTITION p_2009_02 VALUES LESS THAN (2009-03),     PARTITION p_2009_01 VALUES LESS THAN (2009-02),      PARTITION p_2008_12 VALUES LESS THAN (2009-01),     PARTITION p_2008_11 VALUES LESS THAN (2008-12),    PARTITION p_catch_all VALUES LESS THAN MAXVALUE );                                
    ERROR 1564 (HY000): This partition function is not allowed
      

  3.   

    1. 要用增序
    2. 要用数字mysql> create table tx (
        ->  id int,
        ->  info_time timestamp
        -> )
        -> PARTITION BY RANGE(info_time div 100)
        -> (
        ->     PARTITION p_2008_11 VALUES LESS THAN (200812),
        ->     PARTITION p_2008_12 VALUES LESS THAN (200901),
        ->     PARTITION p_2009_01 VALUES LESS THAN (200902),
        ->     PARTITION p_2009_02 VALUES LESS THAN (200903),
        ->     PARTITION p_2009_03 VALUES LESS THAN (200904),
        ->     PARTITION p_2009_04 VALUES LESS THAN (200905),
        ->     PARTITION p_catch_all VALUES LESS THAN MAXVALUE
        -> );
    Query OK, 0 rows affected (0.16 sec)mysql>
      

  4.   

    学习一下..
    mysql没做过分区..
    sql server倒今天写了一个..http://topic.csdn.net/u/20090610/16/1a8b3462-9113-4b1a-96b6-845efefe8058.html?seed=728780202
      

  5.   


    明白了,有两个疑问
    1, info_time div 100,timestamp为什么要这么运算?适用于datetime吗?
    2,我在建立表的时候将id设置成为主键,结果出现错误:create table tx (
        id int not null primary key,
        info_time timestamp
        )
        PARTITION BY RANGE(info_time div 100)
        (
            PARTITION p_2008_11 VALUES LESS THAN (200812),
            PARTITION p_2008_12 VALUES LESS THAN (200901),
            PARTITION p_2009_01 VALUES LESS THAN (200902),
            PARTITION p_2009_02 VALUES LESS THAN (200903),
            PARTITION p_2009_03 VALUES LESS THAN (200904),
            PARTITION p_2009_04 VALUES LESS THAN (200905),
            PARTITION p_catch_all VALUES LESS THAN MAXVALUE
        );
    ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
    难道有主键的时候必须是主键吗?
      

  6.   

    1, info_time div 100,timestamp为什么要这么运算?适用于datetime吗?
    同样适用,当日期型与算术运行符一起时,mysql会将日期型数据隐式转换为数字。 200906112,我在建立表的时候将id设置成为主键,结果出现错误:
    MySQL主键的限制,每一个分区表中的公式中的列,必须在主键/unique key 中包括下面这段摘自MySQL的官方文档,斜体是文档本身就标识为斜体的。可惜在中文文档中我们没找到这 一句。
    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.) For example, each of the following table creation statements is invalid: 
    mysql> create table tx (
        ->     id int not null ,
        ->     info_time date,
        ->     primary key(id,info_time)
        -> )
        -> PARTITION BY RANGE(info_time div 100)
        -> (
        ->     PARTITION p_2008_11 VALUES LESS THAN (200812),
        ->     PARTITION p_2008_12 VALUES LESS THAN (200901),
        ->     PARTITION p_2009_01 VALUES LESS THAN (200902),
        ->     PARTITION p_2009_02 VALUES LESS THAN (200903),
        ->     PARTITION p_2009_03 VALUES LESS THAN (200904),
        ->     PARTITION p_2009_04 VALUES LESS THAN (200905),
        ->     PARTITION p_catch_all VALUES LESS THAN MAXVALUE
        -> );
    Query OK, 0 rows affected (0.17 sec)mysql>
      

  7.   

    mysql> create table tx (
        ->     id int not null ,
        ->     info_time date,
        ->     primary key(id,info_time)
        -> )
        -> PARTITION BY RANGE(MONTH(info_time))
        -> (
        ->     PARTITION p_2008_11 VALUES LESS THAN (MONTH('2008-12-12')),
        ->     PARTITION p_catch_all VALUES LESS THAN MAXVALUE
        -> );
      

  8.   

    你那样格式化一下,分区创建的依据就成了字符串了,只支持int 和date