content_image/788051.jpg
INFORMATION_SCHEMA.PARTITIONS  table once again, we can see that both rows were inserted into partition p0 : 

mysql> SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS, AVG_ROW_LENGTH, DATA_LENGTH > FROM INFORMATION_SCHEMA.PARTITIONS > WHERE TABLE_SCHEMA = ’p’ AND TABLE_NAME =’th’; +------------+----------------+------------+----------------+-------------+ | TABLE_NAME | PARTITION_NAME | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | +------------+----------------+------------+----------------+-------------+ | th | p0 | 2 | 20 | 20 | | th | p1 | 0 | 0 | 0 | +------------+----------------+------------+----------------+-------------+ 2 rows in set (0.00 sec) 

By repeating the last example using PARTITION BY KEY  in place of PARTITION BY HASH  in the definition of the table, you can verify that NULL  is also treated like 0 for this type of partitioning. 

## 24.3 Partition Management 

There are a number of ways using SQL statements to modify partitioned tables; it is possible to add, drop, redefine, merge, or split existing partitions using the partitioning extensions to the ALTER TABLE statement. There are also ways to obtain information about partitioned tables and partitions. We discuss these topics in the sections that follow. 

•For information about partition management in tables partitioned by RANGE  or LIST , see Section 24.3.1, “Management of RANGE and LIST Partitions” . 

•For a discussion of managing HASH  and KEY  partitions, see Section 24.3.2, “Management of HASH and KEY Partitions” . 

•See Section 24.3.5, “Obtaining Information About Partitions” , for a discussion of mechanisms provided in MySQL 8.0 for obtaining information about partitioned tables and partitions. 

•For a discussion of performing maintenance operations on partitions, see Section 24.3.4, “Maintenance of Partitions” . 

<img src='content_image/788051.jpg'>

## Note 

All partitions of a partitioned table must have the same number of subpartitions; it is not possible to change the subpartitioning once the table has been created. 

To change a table’s partitioning scheme, it is necessary only to use the ALTER TABLE  statement with a partition_options  option, which has the same syntax as that as used with CREATE TABLE  for creating a partitioned table; this option (also) always begins with the keywords PARTITION BY . Suppose that the following CREATE TABLE  statement was used to create a table that is partitioned by range: 

CREATE TABLE trb3 (id INT, name VARCHAR(50), purchased DATE) PARTITION BY RANGE( YEAR(purchased) ) ( PARTITION p0 VALUES LESS THAN (1990), PARTITION p1 VALUES LESS THAN (1995), PARTITION p2 VALUES LESS THAN (2000), PARTITION p3 VALUES LESS THAN (2005) ); 

To repartition this table so that it is partitioned by key into two partitions using the id  column value as the basis for the key, you can use this statement: 

ALTER TABLE trb3 PARTITION BY KEY(id) PARTITIONS 2; 

This has the same effect on the structure of the table as dropping the table and re-creating it using CREATE TABLE trb3 PARTITION BY KEY(id) PARTITIONS 2; . 

