简体   繁体   中英

How to partition and subpartition MySQL by key?

I want to add partition to my innoDB table. I have tried to search the syntax for this, but have not found specifics.

Is this syntax wrong? :

ALTER TABLE Product PARTITION BY HASH(catetoryID1) PARTITIONS 6
SUBPARTITION BY KEY(catetoryID2) SUBPARTITIONS 10;

Does SUBPARTITIONS 10 mean each main partition has 10 subpartitions, or does it mean all main partitions have 10 subpartitions divided among them?

It's strange you didn't find the syntax. The MySQL online documentation has quite detailed syntax listed for most common operations.

Look here for overall syntax of the alter table to work with partitions:

http://dev.mysql.com/doc/refman/5.5/en/create-table.html

The syntax for partition management would remain same even when used with the alter table statement, with a few nuances that are listed on the alter table syntax pages in the MySQL docs.

To answer your first question, the problem is not your syntax but rather that you are trying sub-partition a table partitioned first by Hash partitioning - this is not allowed, at least in MySQL 5.5. Only Range or List partitions can be sub-partitioned.

Look here for a complete list of partitioning types:

http://dev.mysql.com/doc/refman/5.5/en/partitioning-types.html

As for the second question, assuming what you were trying would work, you'd be creating 6 partitions hashed by catetoryID1, and then within these you'd have 10 sub-partitions hashed by catetoryID2. So you'd have in all

6 x 10 = 60 partitions

Rules of thumb:

  • SUBPARTITION is useless. It provides no speed, and nothing else.
  • Due to various inefficiencies, don't have more than about 50 partitions.
  • PARTITION BY RANGE is the only useful one.

Often an INDEX can provide better performance than PARTITION; let's see your SELECT .

My blog on partitioning: http://mysql.rjweb.org/doc.php/partitionmaint

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