简体   繁体   English

MySQL 5.5(InnoDB)的分区策略

[英]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. 尝试为MySQL 5.5(InnoDB)表实现分区策略,但我不确定我的理解是否正确,或者不确定是否需要在创建分区时更改语法。

Table "Apple" has 10 mill rows...Columns "A" to "H" PK is columns "A", "B" and "C" 表“ Apple”有10行行...列“ A”至“ H” PK为列“ A”,“ B”和“ C”

Column "A" is a char column and can identify groups of 2 million rows. 列“ A”是char列,可以标识200万行的组。 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. 我认为列“ A”将是尝试实现分区的理想选择,因为我选择并删除了该列,并且实际上可以在不再需要数据时截断该分区。

I issued this command: ALTER TABLE Apple PARTITION BY KEY (A); 我发出了以下命令: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'; 使用以下命令查看分区信息后:SELECT PARTITION_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME ='Apple';

I see all the data is on partition p0 我看到所有数据都在分区p0上

I am wrong in thinking that MySQL was going to break out the partitions in groups of 2 million automagically? 我以为MySQL会自动拆分成200万个组的分区是我的错?

Did I need to specify the number of partitions in the Alter command? 我是否需要在Alter命令中指定分区数?

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". 我希望这将在一个分区中创建200万行的组,然后在新数据输入时为列“ A”提供唯一值,从而创建一个新分区。

Sorry if this was too wordy. 对不起,如果这太罗word了。 Thanks - JeffSpicoli 谢谢-JeffSpicoli

Yes, you need to specify the number of partitions (I assume the default was to create 1 partition). 是的,您需要指定分区数(我假设默认值为创建1个分区)。 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. 按KEY分区使用内部哈希函数http://dev.mysql.com/doc/refman/5.1/en/partitioning-key.html ,因此不是基于列的值来选择分区,而是根据从中计算出的哈希值来选择分区。 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). 但是,如果您希望能够DROP PARTITION,则可能想按RANGE进行分区(因为如果按KEY进行分区,则您仅知道行在分区中的间隔是均匀的,但是许多不同的值最终会出现在同一分区中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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