utf8mb4_unicode_ci 和 utf8mb4_unicode_520_ci 排序规则在 MariaDB/MySQL 中的区别?

Difference between utf8mb4_unicode_ci and utf8mb4_unicode_520_ci collations in MariaDB/MySQL?

我登录 MariaDB/MySQL 并输入:

SHOW COLLATION;

我在可用的排序规则中看到 utf8mb4_unicode_ciutf8mb4_unicode_520_ci。这两种归类之间有什么区别,我们应该使用哪种?

好吧,您可以阅读文档中的差异。我不能告诉你应该使用什么,因为每个项目都不一样。

10.1.3 Collation Naming Conventions

MySQL collation names follow these conventions:

A collation name starts with the name of the character set with which it is associated, followed by one or more suffixes indicating other collation characteristics. For example, utf8_general_ci and latin_swedish_ci are collations for the utf8 and latin1 character sets, respectively.

A language-specific collation includes a language name. For example, utf8_turkish_ci and utf8_hungarian_ci sort characters for the utf8 character set using the rules of Turkish and Hungarian, respectively.

Case sensitivity for sorting is indicated by _ci (case insensitive), _cs (case sensitive), or _bin (binary; character comparisons are based on character binary code values). For example, latin1_general_ci is case insensitive, latin1_general_cs is case sensitive, and latin1_bin uses binary code values.

For Unicode, collation names may include a version number to indicate the version of the Unicode Collation Algorithm (UCA) on which the collation is based. UCA-based collations without a version number in the name use the version-4.0.0 UCA weight keys. For example:

utf8_unicode_ci (with no version named) is based on UCA 4.0.0 weight keys >(http://www.unicode.org/Public/UCA/4.0.0/allkeys-4.0.0.txt).

utf8_unicode_520_ci is based on UCA 5.2.0 weight keys (http://www.unicode.org/Public/UCA/5.2.0/allkeys.txt).

For Unicode, the xxx_general_mysql500_ci collations preserve the pre-5.1.24 ordering of the original xxx_general_ci collations and permit upgrades for tables created before MySQL 5.1.24. For more information, see Section 2.11.3, “Checking Whether Tables or Indexes Must Be Rebuilt”, and Section 2.11.4, “Rebuilding or Repairing Tables or Indexes”.

Source

要查看对实际差异的更多讨论,您可以转到 https://dev.mysql.com/worklog/task/?id=2673 并单击 "High Level Architecture"。

我将开发 答案并专注于 utf8mb4_unicode_ci/utf8mb4_unicode_520_ci 的细节:

如您所见,here (Peter Gulutzan) sorting/comparing 波兰语字母“Ł”(带笔画的 L)(小写)有问题: "ł"; html esc: ł and Ł ) - 我们在编码中有以下假设(与 mb4 相同):

utf8_polish_ci      Ł greater than L and less than M
utf8_unicode_ci     Ł greater than L and less than M
utf8_unicode_520_ci Ł equal to L
utf8_general_ci     Ł greater than Z

在波兰语中,字母 Ł 在字母 L 之后和 M 之前。对于不同的编码系统,您会得到不同的排序结果。这种编码没有任何一种是好是坏——这取决于你的需要。

http://mysql.rjweb.org/utf8mb4_collations.html 显示了这两个排序规则以及许多其他排序规则之间的差异。

Unicode 提供了一个随着以下数字不断发展的标准:

4.0.0 - utf8mb4_unicode_ci
5.2.0 - utf8mb4_unicode_520_ci
9.0.0 - utf8mb4_0900_ai_ci

通常最好使用可用的最新标准。

例如,在那个页面上有

utf8mb4_unicode_ci: 
 A=a=ª=À=Á=Â=Ã=Ä=Å=à=á=â=ã=ä=å=Ā=ā=Ă=ă=Ą=ą  Aa  ae     az  Æ=æ
utf8mb4_unicode_520_ci and utf8mb4_0900_ai_ci:
 A=a=ª=À=Á=Â=Ã=Ä=Å=à=á=â=ã=ä=å=Ā=ā=Ă=ă=Ą=ą  Aa  ae=Æ=æ az

这显示了与“A”的一个区别,即“æ”曾经在“az”之后,但在 5.2.0 和 9.0.0 中被视为等于“ae”。

“æ”可能是这些排序规则中重音字母的唯一变化。甚至“-”始终等于“oe”