在这种情况下,所选的排序规则重要吗?

发布于 2024-11-15 11:59:22 字数 150 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断爱 2024-11-22 11:59:22

我怀疑它会产生任何可测量的差异,但如果 mf 是唯一可能的值,那么 utf8_bin 应该准确地产生 与 utf8_unicode_ci (或大多数其他排序算法)的结果相同。由于该排序规则执行简单的二进制比较,因此它必然是最快的排序规则。

I doubt that it will make any measurable difference, but if m and f are the only possible values, then utf8_bin should produce exactly the same results as utf8_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.

笔芯 2024-11-22 11:59:22

排序规则是定义字符应如何排序的规则。想象一个字母序列 - 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 and Z 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文