MySQL复合分区

究竟还是开源软件,MySQL对复合分区的支撑远远没Oracle丰富。

于MySQL
5.6版被,只支持RANGE和LIST的子分区,且子分区的路只能为HASH和KEY。

譬如:

CREATE TABLE ts (id INT, purchased DATE)
    PARTITION BY RANGE( YEAR(purchased) )
    SUBPARTITION BY HASH( TO_DAYS(purchased) )
    SUBPARTITIONS 2 (
        PARTITION p0 VALUES LESS THAN (1990),
        PARTITION p1 VALUES LESS THAN (2000),
        PARTITION p2 VALUES LESS THAN MAXVALUE
    );

上述创建语句被,最外层是RANGE分区,分为3只区,里面凡是HASH子分区,分呢2独区,这样,该表一共分了3*2=6个分区。

本来,也得据此SUBPARTITION语句来展示定义子分区。

CREATE TABLE ts (id INT, purchased DATE)
    PARTITION BY RANGE( YEAR(purchased) )
    SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
        PARTITION p0 VALUES LESS THAN (1990) (
            SUBPARTITION s0,
            SUBPARTITION s1
        ),
        PARTITION p1 VALUES LESS THAN (2000) (
            SUBPARTITION s2,
            SUBPARTITION s3
        ),
        PARTITION p2 VALUES LESS THAN MAXVALUE (
            SUBPARTITION s4,
            SUBPARTITION s5
        )
    );

注意:

1>
如果你在分区中行使了SUBPARTITION语句,则每个分区中还要定义,且每个分区中子分区的数码要保持一致。譬如以下简单种用法就会报错:

CREATE TABLE ts (id INT, purchased DATE)
    PARTITION BY RANGE( YEAR(purchased) )
    SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
        PARTITION p0 VALUES LESS THAN (1990) (
            SUBPARTITION s0,
            SUBPARTITION s1
        ),
        PARTITION p1 VALUES LESS THAN (2000) (
            SUBPARTITION s2
        ),
        PARTITION p2 VALUES LESS THAN MAXVALUE (
            SUBPARTITION s3,
            SUBPARTITION s4
        )
    );

CREATE TABLE ts (id INT, purchased DATE)
    PARTITION BY RANGE( YEAR(purchased) )
    SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
        PARTITION p0 VALUES LESS THAN (1990) (
            SUBPARTITION s0,
            SUBPARTITION s1
        ),
        PARTITION p1 VALUES LESS THAN (2000),
        PARTITION p2 VALUES LESS THAN MAXVALUE (
            SUBPARTITION s2,
            SUBPARTITION s3
        )
    );

2> 在SUBPARTITION语句被,可指定该分区的大体位置。譬如:

CREATE TABLE ts (id INT, purchased DATE)
    PARTITION BY RANGE(YEAR(purchased))
    SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
        PARTITION p0 VALUES LESS THAN (1990) (
            SUBPARTITION s0a
                DATA DIRECTORY = '/disk0'
                INDEX DIRECTORY = '/disk1',
            SUBPARTITION s0b
                DATA DIRECTORY = '/disk2'
                INDEX DIRECTORY = '/disk3'
        ),
        PARTITION p1 VALUES LESS THAN (2000) (
            SUBPARTITION s1a
                DATA DIRECTORY = '/disk4/data'
                INDEX DIRECTORY = '/disk4/idx',
            SUBPARTITION s1b
                DATA DIRECTORY = '/disk5/data'
                INDEX DIRECTORY = '/disk5/idx'
        ),
        PARTITION p2 VALUES LESS THAN MAXVALUE (
            SUBPARTITION s2a,
            SUBPARTITION s2b
        )
    );

如上是创造语句,将不同之分区分布及不同的情理路径下,无疑会极大的疏散IO,这一点要么挺吸引人口的。

惋惜,在本机测试过程遭到,报“ERROR 1030 (HY000): Got error -1 from storage
engine”错误,具体原因尚未极端知道,怀疑是MySQL的bug。

参考:

http://dev.mysql.com/doc/refman/5.6/en/partitioning-subpartitions.html

http://dev.mysql.com/doc/refman/5.6/en/tablespace-placing.html

网站地图xml地图