1

根据 mysql 解释“分区表的分区表达式中使用的所有列必须是表可能具有的每个唯一键的一部分”。为什么只有唯一/主键,为什么没有其他键?

4

1 回答 1

1

I assume by a non-unique key you mean an index.

Imagine you have a key as a balanced-tree, here a B-tree, and you partition it by a certain criteria, to have a desired number of partitions, or a desired number of members in each partition. If you do so, because the tree is a tree of a unique-key, you are dividing your actual data into partitions of almost balanced size.

Now imagine you have a B-tree of values for an index (for example a secondary index in InnoDB), and each key of the tree points to several data members of the table. In this case, partitioning according to the B-tree, does not imply partitioning of the data into balanced chunks, so there is no point in considering it.

On the other hand, in practice, at least according to my own experience, primary and unique keys are a design question to which you usually have to answer when you design the table, in contrast to indices that sometimes you add to the table to improve the performance of your queries which happen to be executed very often. If you add the constraint of having partition fields in all keys and indices, they for each index that does not have a field in the partitioning fields, you will have to remove that field from partitioning or add all the fields of your partitioning fields as a default to all you indices. Hence it doesn't to be a good practice.

于 2014-01-06T16:25:13.630 回答