有一个表, 因为太大, 需要用分区来优化速度.
但是建表的时候,
不能允许存在unique索引的字段.
否则就不能建立分区.
刚好我又有一个字段需要用unique在表内标识唯一的.请问这种情况怎么办?

解决方案 »

  1.   

    可以啊!!
    可以分区的!!
    我的表里面也有UNIQUE索引,我就在这个索引字段上建立的分区。确实是可以分区的。
    如果你不能的话,看看你的引擎是INnoDB的?如果是,就这样处理:
    先建立表和分区,最后,等分完区后再用
    ALTER TABL tableName ADD UNIQUE INDEX idx_unique (唯一索引的字段).这样是可以建立了吧!!
      

  2.   

    是InnoDB引擎的没错, 但是除了PRIMARY KEY的字段外, 不能建立其他字段的UNIQUE索引.
    其他字段, 非UNIQUE的索引就OK.
      

  3.   

    回6楼的,这就是mysql比较**的地方……
    所以偶在装了5.1几天就又换回5.0.
      

  4.   


    5.0是没有分区功能的。 ?? 
    你不会是分区字段是unique的吧。没出现过如此问题,啥分区,List,Range or Hash ?
      

  5.   

    对primary key 字段创建unique index试试 。
      

  6.   

    对于分区表partition表的partition key必须被包含在在所有unique key中,我想是因为你的unique key中没有包含partition key吧
      

  7.   

    具体见手册的21.5.1. Partitioning Keys, 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.)