MySQL 5.1 分区
我有以下示例表...
mysql> CREATE TABLE part_date3
-> ( c1 int default NULL,
-> c2 varchar(30) default NULL,
-> c3 date default NULL) engine=myisam
-> partition by range (to_days(c3))
-> (PARTITION p0 VALUES LESS THAN (to_days('1995-01-01')),
-> PARTITION p1 VALUES LESS THAN (to_days('1996-01-01')) ,
-> PARTITION p2 VALUES LESS THAN (to_days('1997-01-01')) ,
-> PARTITION p3 VALUES LESS THAN (to_days('1998-01-01')) ,
-> PARTITION p4 VALUES LESS THAN (to_days('1999-01-01')) ,
-> PARTITION p5 VALUES LESS THAN (to_days('2000-01-01')) ,
-> PARTITION p6 VALUES LESS THAN (to_days('2001-01-01')) ,
-> PARTITION p7 VALUES LESS THAN (to_days('2002-01-01')) ,
-> PARTITION p8 VALUES LESS THAN (to_days('2003-01-01')) ,
-> PARTITION p9 VALUES LESS THAN (to_days('2004-01-01')) ,
-> PARTITION p10 VALUES LESS THAN (to_days('2010-01-01')),
-> PARTITION p11 VALUES LESS THAN MAXVALUE );
Query OK, 0 rows affected (0.00 sec)
假设这充满了数据,我想在 p11 处插入 2011 年分区,然后使 p12 最大值,有没有一种有效的方法可以做到这一点,而无需转储和重新加载整个表?
I have the following example table...
mysql> CREATE TABLE part_date3
-> ( c1 int default NULL,
-> c2 varchar(30) default NULL,
-> c3 date default NULL) engine=myisam
-> partition by range (to_days(c3))
-> (PARTITION p0 VALUES LESS THAN (to_days('1995-01-01')),
-> PARTITION p1 VALUES LESS THAN (to_days('1996-01-01')) ,
-> PARTITION p2 VALUES LESS THAN (to_days('1997-01-01')) ,
-> PARTITION p3 VALUES LESS THAN (to_days('1998-01-01')) ,
-> PARTITION p4 VALUES LESS THAN (to_days('1999-01-01')) ,
-> PARTITION p5 VALUES LESS THAN (to_days('2000-01-01')) ,
-> PARTITION p6 VALUES LESS THAN (to_days('2001-01-01')) ,
-> PARTITION p7 VALUES LESS THAN (to_days('2002-01-01')) ,
-> PARTITION p8 VALUES LESS THAN (to_days('2003-01-01')) ,
-> PARTITION p9 VALUES LESS THAN (to_days('2004-01-01')) ,
-> PARTITION p10 VALUES LESS THAN (to_days('2010-01-01')),
-> PARTITION p11 VALUES LESS THAN MAXVALUE );
Query OK, 0 rows affected (0.00 sec)
Say this is full of data and I want to slot in a 2011 partition at p11 and then make the p12 maxvalue is there an efficient way of doing this without dumping and reloading the entire table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回答你确切的问题
这是查询
To answer you exact question
Here is the query
您需要删除 MAXVALUE 分区,添加新分区,然后再次添加新的 MAXVALUE 分区。这是一个快速操作,您不会丢失除 MAXVALUE 分区之外的任何分区中的数据。
如果您想将数据保留在 MAXVALUE 分区中,请查看 ALTER TABLE 的 REORGAINZE PARTITION 和 COALESCE PARTITION 子句
http://dev.mysql.com/doc/refman/5.1 /en/alter-table.html
我也遇到了同样的问题。我删除了 MAXVALUE 分区,添加了新分区,但没有再次添加 MAXVALUE 分区。就我而言,应用程序将来永远不会插入任何数据过多的记录,以至于需要 MAXVALUE 分区。
分区维护与事件配合得很好。看
http://dev.mysql.com/tech-resources/articles/partitioning -event_scheduler.html
You need to drop the MAXVALUE partition, add the new partition and add a new MAXVALUE partition again. This is a fast operation and you would not lose data in any partition other than the MAXVALUE partition.
If you want to preserve data in MAXVALUE partion, have a look at REORGAINZE PARTITION and COALESCE PARTITION clauses of ALTER TABLE
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
I had the same problem. I dropped the MAXVALUE partition, added the new partition but did not add the MAXVALUE partition again. In my case, the app would never insert any record dataed so much in the future that it would require a MAXVALUE partition.
Partition maintenance goes very well with Events. See
http://dev.mysql.com/tech-resources/articles/partitioning-event_scheduler.html
http://dev.mysql.com/doc /refman/5.1/en/partitioning-management-range-list.html 建议您可以简单地通过添加另一个分区
,但显然,您应该首先对其进行测试。
http://dev.mysql.com/doc/refman/5.1/en/partitioning-management-range-list.html suggests that you can simply add another partition via
though obviously, you should test that first.