MySQL 5.5 の unicode collation で同一視される文字

MySQL の collation について調べてたら、

今回の実験で、utf8_unicode_ciによる大文字-小文字や全角-半角の同一視に

関する動作はなんとなく分かりましたが、どの文字が同一視されるのかを記載した資料ってあるのだろうか?

http://d.hatena.ne.jp/end0tknr/20100613/1276427626

という記事を見かけたので調べてみました。

MySQL の マニュアルによると UCA というアルゴリズムを使用しているようです。

MySQL implements the xxx_unicode_ci collations according to the Unicode Collation Algorithm (UCA) described at http://www.unicode.org/reports/tr10/. The collation uses the version-4.0.0 UCA weight keys: http://www.unicode.org/Public/UCA/4.0.0/allkeys-4.0.0.txt. Currently, the xxx_unicode_ci collations have only partial support for the Unicode Collation Algorithm. Some characters are not supported yet. Also, combining marks are not fully supported. This affects primarily Vietnamese, Yoruba, and some smaller languages such as Navajo.

http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-sets.html

UCA はちゃんと読んでませんが、文字毎に weight という値が割り当てられていて、同じ weight であれば同じ文字とみなすという感じみたいです。

MySQL のソース中では、strings/ctype-uca.c で処理されています。このファイルから、どの文字が同一視されるかを調べてみました。

結果はこちら→ MySQL 5.5.11 unicode_ci で同一視される文字

これを作成するためのスクリプト→ https://gist.github.com/tmtm/922928

日本語の範囲で関係あるのは、英数字記号ひらがなカタカナくらいみたいです。