简体   繁体   中英

Partition strategy for MySQL 5.5 (InnoDB)

Trying to implement a partition strategy for a MySQL 5.5 (InnoDB) table and I am not sure my understanding is right or if I need to change the syntax in creating the partition.

Table "Apple" has 10 mill rows...Columns "A" to "H" PK is columns "A", "B" and "C"

Column "A" is a char column and can identify groups of 2 million rows. I thought column "A" would be a nice candidate to try and implement a partition around since I select and delete by this column and could really just truncate the partition when the data is no longer needed.

I issued this command: ALTER TABLE Apple PARTITION BY KEY (A);

After looking at the partition info using this command: SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'Apple';

I see all the data is on partition p0

I am wrong in thinking that MySQL was going to break out the partitions in groups of 2 million automagically?

Did I need to specify the number of partitions in the Alter command?

I was hoping this would create groups of 2 million rows in a partition and then create a new partition as new data comes in with a unique value for column "A".

Sorry if this was too wordy. Thanks - JeffSpicoli

Yes, you need to specify the number of partitions (I assume the default was to create 1 partition). Partition by KEY uses internal hashing function http://dev.mysql.com/doc/refman/5.1/en/partitioning-key.html , so the partition is not selected based on the value of column, but on hash computed from it. Hashing functions return the same result for same input, so yes, all rows having the same value will be in the same partition.

But maybe you want to partition by RANGE if you want to be able to DROP PARTITION (because if partitioned by KEY, you only know that the rows are spaced evenly in the partitions, but you many different values end up in the same partition).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM