mysql-How to delete a hash table partition

Source: Internet
Author: User

A large table, previously in the form of a hash partition table,

Mysql> Show CREATE table history_uint;| History_uint |  CREATE TABLE ' history_uint ' (' Itemid ' bigint () unsigned not NULL, ' clock ' int (one-by-one) not null DEFAULT ' 0 ', ' Value ' bigint (20) unsigned NOT NULL default ' 0 ', ' ns ' int (one) not null default ' 0 ', PRIMARY key (' itemid ', ' clock ', ' ns '), key ' I_clock ' (' clock ') Engine=innodb DEFAULT charset=utf8/*!50100 PARTITION by HASH (ITEMID) Partitions 512 * * |

Now we have to remove the partition, how to go?

Check the syntax as follows:

Alter table Table Coalesce partition Num;num refers to the number of table partitions you want to remove

That now has 512 partitions, finally this table I still want, so try to remove 511 partitions to see (of course, before the online operation I have tested in the TEST library!!!) On-line operation should be cautious!!! )

mysql> Alter table History_uint coalesce partition 511; Query OK, 0 rows affected (4 min 41.71 sec)

  

View after operation, sure enough, there's only one partition left.

Mysql> SELECT table_name, partition_name, table_rows from INFORMATION_SCHEMA. Partitions WHERE table_name= ' history_uint '; +--------------+----------------+------------+| TABLE_NAME   | Partition_name | Table_rows |+--------------+----------------+------------+| History_uint | P0          |   34909051 |+--------------+----------------+------------+1 row in Set (0.01 sec)

  

Let's get rid of this partition, and take care to remove it, and drop it, delete the partition and the data together.

mysql> ALTER TABLE history_uint REMOVE partitioning; Query OK, 0 rows affected (3 min 52.38 sec)

  

Last view table structure

Mysql> Show CREATE table history_uint;| History_uint | CREATE TABLE ' history_uint ' (  ' itemid ' bigint () unsigned not null,  ' clock ' int (one-by-one) not null DEFAULT ' 0 ',  ' VA Lue ' bigint () unsigned NOT null default ' 0 ',  ' ns ' int (one) not null default ' 0 ',  PRIMARY KEY (' itemid ', ' clock ', ' n S '),  KEY ' i_clock ' (' clock ')) Engine=innodb DEFAULT Charset=utf8 |

  

Table partition disappears, complete.

mysql-How to delete a hash table partition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.