MySQL5.1 引入表分区功能,使得MySQL在处理大表的能力上得到增强。使用过表分区功能的朋友应该知道,MySQL5.1中使用表分区的时候,对字段是有要求的,那就是必须是整数型,或者可以将其他类型的字段通过函数转换成整数型才可以。
/* with MySQL 5.1 ivan @ MySQL实验室(mysqlab.net/blog/) */
CREATE TABLE mysqlab_net
(
ivan DATE
)
PARTITION BY RANGE (TO_DAYS(ivan))
(
PARTITION p01 VALUES LESS THAN (TO_DAYS(‘2007-08-08′)),
PARTITION p02 VALUES LESS THAN (TO_DAYS(‘2008-08-08′)),
PARTITION p03 VALUES LESS THAN (TO_DAYS(‘2009-08-08′)),
PARTITION p04 VALUES LESS THAN (MAXVALUE));
SHOW CREATE TABLE mysqlab_net\G
*************************** 1. row ***************************
TABLE: mysqlab_net
CREATE TABLE: CREATE TABLE `mysqlab_net` (
`ivan` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (TO_DAYS(ivan))
(PARTITION p01 VALUES LESS THAN (733261) ENGINE = InnoDB,
PARTITION p02 VALUES LESS THAN (733627) ENGINE = InnoDB,
PARTITION p03 VALUES LESS THAN (733992) ENGINE = InnoDB,
PARTITION p04 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
怎么样?读取的时候谁知道那个数字是多少?(不过也可以通过自定义函数实现还原)
MySQL5.5中加入了columns关键字,使得可读性好多了。看例子
/* with MySQL 5.5 ivan @ MySQL实验室(mysqlab.net/blog/) */
CREATE TABLE `mysqlab.net`
(
ivan DATE
)
PARTITION BY RANGE COLUMNS(ivan)
(
PARTITION p01 VALUES LESS THAN (‘2007-08-08′),
PARTITION p02 VALUES LESS THAN (‘2008-08-08′),
PARTITION p03 VALUES LESS THAN (‘2009-08-08′),
PARTITION p04 VALUES LESS THAN (MAXVALUE);
SHOW CREATE TABLE `mysqlab.net`\G
*************************** 1. row ***************************
TABLE: mysqlab.net
CREATE TABLE: CREATE TABLE `mysqlab.net` (
`ivan` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50500 PARTITION BY RANGE COLUMNS(ivan)
(PARTITION p01 VALUES LESS THAN (’2007-08-08′) ENGINE = InnoDB,
PARTITION p02 VALUES LESS THAN (’2008-08-08′) ENGINE = InnoDB,
PARTITION p03 VALUES LESS THAN (’2009-08-08′) ENGINE = InnoDB,
PARTITION p04 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) */
另外MySQL5.5表分区(partition) columns关键字还支持多字段,比如 partition by range columns(a,b);将支持清空指定的分区TRUNCATE PARTITION。MySQL5.5有望在明年(2010)夏季GA。另外MySQL5.5支持的半同步功能在高可用上的使用,让人非常期待!
/* with MySQL 5.1 ivan @ MySQL实验室(mysqlab.net/blog/) */
CREATE TABLE mysqlab_net
(
ivan DATE
)
PARTITION BY RANGE (TO_DAYS(ivan))
(
PARTITION p01 VALUES LESS THAN (TO_DAYS(‘2007-08-08′)),
PARTITION p02 VALUES LESS THAN (TO_DAYS(‘2008-08-08′)),
PARTITION p03 VALUES LESS THAN (TO_DAYS(‘2009-08-08′)),
PARTITION p04 VALUES LESS THAN (MAXVALUE));
SHOW CREATE TABLE mysqlab_net\G
*************************** 1. row ***************************
TABLE: mysqlab_net
CREATE TABLE: CREATE TABLE `mysqlab_net` (
`ivan` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (TO_DAYS(ivan))
(PARTITION p01 VALUES LESS THAN (733261) ENGINE = InnoDB,
PARTITION p02 VALUES LESS THAN (733627) ENGINE = InnoDB,
PARTITION p03 VALUES LESS THAN (733992) ENGINE = InnoDB,
PARTITION p04 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
怎么样?读取的时候谁知道那个数字是多少?(不过也可以通过自定义函数实现还原)
MySQL5.5中加入了columns关键字,使得可读性好多了。看例子
/* with MySQL 5.5 ivan @ MySQL实验室(mysqlab.net/blog/) */
CREATE TABLE `mysqlab.net`
(
ivan DATE
)
PARTITION BY RANGE COLUMNS(ivan)
(
PARTITION p01 VALUES LESS THAN (‘2007-08-08′),
PARTITION p02 VALUES LESS THAN (‘2008-08-08′),
PARTITION p03 VALUES LESS THAN (‘2009-08-08′),
PARTITION p04 VALUES LESS THAN (MAXVALUE);
SHOW CREATE TABLE `mysqlab.net`\G
*************************** 1. row ***************************
TABLE: mysqlab.net
CREATE TABLE: CREATE TABLE `mysqlab.net` (
`ivan` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50500 PARTITION BY RANGE COLUMNS(ivan)
(PARTITION p01 VALUES LESS THAN (’2007-08-08′) ENGINE = InnoDB,
PARTITION p02 VALUES LESS THAN (’2008-08-08′) ENGINE = InnoDB,
PARTITION p03 VALUES LESS THAN (’2009-08-08′) ENGINE = InnoDB,
PARTITION p04 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) */
另外MySQL5.5表分区(partition) columns关键字还支持多字段,比如 partition by range columns(a,b);将支持清空指定的分区TRUNCATE PARTITION。MySQL5.5有望在明年(2010)夏季GA。另外MySQL5.5支持的半同步功能在高可用上的使用,让人非常期待!
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2622/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表