I have a table like:
create table registrations( id int not null auto_increment primary key, name varchar(50), mobile_number varchar(13)) engine=innodb partition by range(id) ( partition p0 values less than (10000), partition p0 values less than (20000), partition p0 values less than max value);
Not exactly like above but similar to that....
Now assume that my table has 200000 rows and now I want to remove partitions on the table and reorganize them in accordance to requirement without MAX VALUE in it.
Can any one help me to rearrange partition without dropping data or dropping table and recreating it ?
Use ALTER TABLE ... REMOVE PARTITIONING to remove a table's partitioning. See Section 13.1. 7, “ALTER TABLE Statement”. Only a single PARTITION BY , ADD PARTITION , DROP PARTITION , REORGANIZE PARTITION , or COALESCE PARTITION clause can be used in a given ALTER TABLE statement.
Data itself are stored in files in the partition location(folder). If you drop partition of external table, the location remain untouched, but unmounted as partition (metadata about this partition is deleted). You can have few versions of partition location unmounted (for example previous versions).
The ALTER TABLE… DROP PARTITION command deletes a partition and any data stored on that partition. The ALTER TABLE… DROP PARTITION command can drop partitions of a LIST or RANGE partitioned table.
This table can be partitioned by HASH , using the id column as the partitioning key, into 8 partitions by means of this statement: ALTER TABLE t1 PARTITION BY HASH(id) PARTITIONS 8; MySQL supports an ALGORITHM option with [SUB]PARTITION BY [LINEAR] KEY .
ALTER TABLE tbl REMOVE PARTITIONING;
You can reorganize the partition p0
using the ALTER TABLE .. REORGANIZE PARTITION
command.
http://dev.mysql.com/doc/refman/5.5/en/partitioning-management-range-list.html
If you intend to change the partitioning of a table without losing data, use ALTER TABLE ... REORGANIZE PARTITION
ALTER TABLE registrations REORGANIZE PARTITION p0 INTO ( PARTITION p0 VALUES LESS THAN (10000), PARTITION p0 VALUES LESS THAN (20000) );
Note that this will not make sense until you actually create several partitions e.g.
ALTER TABLE registrations REORGANIZE PARTITION p0 INTO ( PARTITION p0 VALUES LESS THAN (10000), PARTITION p1 VALUES LESS THAN (20000), PARTITION p2 VALUES LESS THAN MAXVALUE );
Have a look at RANGE partitioning in MySQL
If your partition p2
is becoming too large you can split it the same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With