MySQL 5.1 分区

发布于 2024-10-29 10:12:48 字数 1150 浏览 1 评论 0原文

我有以下示例表...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

且行且努力 2024-11-05 10:12:48

回答你确切的问题

我想在 p11 处插入 2011 年分区,然后设置 p12 最大值

这是查询

ALTER TABLE part_date3 REORGANIZE PARTITION p11 INTO (
    PARTITION p11 VALUES LESS THAN (TO_DAYS('2011-01-01')),
    PARTITION p12 VALUES LESS THAN MAXVALUE
);

To answer you exact question

I want to slot in a 2011 partition at p11 and then make the p12 maxvalue

Here is the query

ALTER TABLE part_date3 REORGANIZE PARTITION p11 INTO (
    PARTITION p11 VALUES LESS THAN (TO_DAYS('2011-01-01')),
    PARTITION p12 VALUES LESS THAN MAXVALUE
);
夜无邪 2024-11-05 10:12:48

您需要删除 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

笑忘罢 2024-11-05 10:12:48

http://dev.mysql.com/doc /refman/5.1/en/partitioning-management-range-list.html 建议您可以简单地通过添加另一个分区

ALTER TABLE `part_date3`
ADD PARTITION (PARTITION p12 VALUES LESS THAN (to_days('2011-01-01')));

,但显然,您应该首先对其进行测试。

http://dev.mysql.com/doc/refman/5.1/en/partitioning-management-range-list.html suggests that you can simply add another partition via

ALTER TABLE `part_date3`
ADD PARTITION (PARTITION p12 VALUES LESS THAN (to_days('2011-01-01')));

though obviously, you should test that first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文