如何根据 char 列对 MySQL 表进行分区?
是否可以根据char列进行分区?
查看 MySQL 5.1 文档后发现只能使用整数类型。
这是正确的吗?或者我可以使用一些函数将 char 转换为整数吗?
所讨论的 char 字段包含唯一标识符。
Is it possible to partition based on char column?
After reviewing the MySQL 5.1 documentation it appears that only integer types can be used.
Is this correct? Or can I use some function to convert the char into an integer?
The char field in question contains a unique identifier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MySQL 5.1 中的分区只能处理整数列(来源)。您只能使用少数分区函数非整数列。例如:
您还可以在MySQL中使用键分区 5.1,只要主键包含表的分区函数中的所有列:
另一方面,在 MySQL 5.5 中,可以使用 范围列分区 或 针对各种数据类型(包括基于字符的列)进行列表列分区。
列表列示例:
范围列示例:
进一步阅读:
Partitioning in MySQL 5.1 can only deal with integer columns (Source). You can only use a few partitioning functions on non-integer columns. For example:
You can also use key partitioning in MySQL 5.1, as long as the primary key includes all the columns in the table's partitioning function:
On the other hand, in MySQL 5.5, you can use range column partitioning or list column partitioning on a wide variety of data types, including character-based columns.
List Columns Example:
Range Columns Example:
Further reading:
您希望通过 PARTITIONing 获得什么? HASH 和 LIST 不太可能提供任何性能提升。对少于一百万行的表进行分区很少有用。
关于分区的其他评论: http://mysql.rjweb.org/doc.php/partitionmaint
5.6 和 5.7 放宽了其他答案中提到的一些限制,但分区仍然很少比索引更好。
What do you hope to gain by PARTITIONing? HASH and LIST are unlikely to provide any performance gain. It is rarely useful to partition a table with less than a million rows.
Other comments on partitioning: http://mysql.rjweb.org/doc.php/partitionmaint
5.6 and 5.7 have relaxed some of the restrictions mention in the other answers, but still partitioning is rarely better than indexing.