在这种情况下,所选的排序规则重要吗?
我的 MySQL 表中有一个类型为 char(1) 的字段,它基本上只能包含值 m 或 f。其当前排序规则设置为 ut8_unicode_ci。我在想我是否应该将排序规则更改为更简单的东西,例如拉丁语,因为从未使用过完整的 utf8 字符集 - 仅使用字符 m 或 f。这会改变什么吗?
I've a field of type char(1)
in my MySQL table which basically can have only values m or f. Its current collation is set to ut8_unicode_ci. I was thinking whether I should or should not change the collation to something simpler like latin because the full set of utf8 chars is never used - only the chars m or f. Would that change something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑它会产生任何可测量的差异,但如果
m
和f
是唯一可能的值,那么utf8_bin
应该准确地产生 与 utf8_unicode_ci (或大多数其他排序算法)的结果相同。由于该排序规则执行简单的二进制比较,因此它必然是最快的排序规则。I doubt that it will make any measurable difference, but if
m
andf
are the only possible values, thenutf8_bin
should produce exactly the same results asutf8_unicode_ci
(or most other collation algorithms for that matter). And since that collation does a simple binary comparison it's bound to be the fastest one around.排序规则是定义字符应如何排序的规则。想象一个字母序列 - A 是第一个字母,Z 是最后一个字母(英文)。排序规则表示
A
在前,Z
在后,它还有助于定义如何比较字符。简而言之 - 整理与您的情况无关。你应该做的就是将该字段设置为tinyint,直到MySQL稍后推出布尔类型。这样您就可以绕过任何时候可能出现的任何字符集问题,尽管在您的示例中它们并不是真正重要的问题。
Collation is the rule that defines how the characters are supposed to be ordered. Imagine an alphabet sequence - A is 1st letter and Z is the last letter (in English). Collation is the rule that says that
A
is first andZ
is last and it also helps define how characters are compared. In short - collation has nothing to do with anything in your case.What you should do is set that field to tinyint, until MySQL comes up with boolean types later on. That way you'll bypass any charset issues that might arise at any point, although in your example they're not really what matters.