ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
From: Michael Bykov <m.bykov@gmail.com>
To: ALT Linux Sisyphus discussions <sisyphus@lists.altlinux.org>
Subject: Re: [sisyphus] странное и некрасивое поведение utf8 в паре rails/mysql
Date: Sun, 28 Jun 2009 10:55:17 +0400
Message-ID: <69c7dc8b0906272355u15d1f40boa56e82bdedceeb6b@mail.gmail.com> (raw)
In-Reply-To: <240e377b0906272316n5233c43fn2a807c73f3a3e23b@mail.gmail.com>

28 июня 2009 г. 10:16 пользователь Mikhail Yakshin
(greycat@altlinux.org) написал:
>> MySQL продолжает упорствовать в своих заблуждениях.
>>
> [...]
>
>>  Dict.find_by_word "ᾆδω"
>> => #<Dict id: 2622, parent_id: nil, group_id: nil, variant_id: nil, word: "ἄδω"
>>
>> но  "ᾆδω"  это не "ἄδω" совсем.
>>
>> Интересно, может быть постгрес будет проще настроить?
>
> Это unicode case-insensitive (ci) collation, который вполне себе
> корректно отрабатывает. С точки зрения unicode - это два символа,
> которые равны по sort values - т.к. и "ᾆ", и "ἄ" равны просто "α":
>
> mysql> select 'ᾆ'='α';
> +------------+
> | 'ᾆ'='α'    |
> +------------+
> |          1 |
> +------------+
>
> Это в целом полезный механизм - например, пользователь может написать
> "елка", и оно из-за этого case insensitivity смэтчится со словами
> "ёлка", "Елка" или "Ёлка", которые найдутся в базе.
>
> Более подробно об этом можно почитать в руководстве MySQL:
> http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
>
> Quick solution, если надо просто отключить любые case- и sort-
> sensitivity - использовать тип BINARY (или collation utf8_bin). Их
> можно поставить на БД целиком, на таблицы/поля/переменные или даже
> индивидуальные сравнения:
>
> mysql> select 'ᾆ' COLLATE utf8_bin='α';
> +-----------------------------+
> | 'ᾆ' COLLATE utf8_bin='α'    |
> +-----------------------------+
> |                           0 |
> +-----------------------------+
>
> Postgresql в данном случае будет вести себя точно так же - эти вещи
> (классы эквивалентности по sort value для различных characters)
> прописаны в стандарте unicode.
>
> P.S. Вопрос, видимо, всё-таки не имеет отношения к sisyphus@ -
> предлагаю переместиться в личную почту для дальнейших обсуждений, если
> таковые будут иметь место.
>


Да, спасибо, Михаил, я уже разобрался, всё перевел в utf8 и прописал
collation. Теперь у меня настройки такие:

mysql> show variables like '%collation\_%'
+----------------------+----------+
| Variable_name        | Value    |
+----------------------+----------+
| collation_connection | utf8_bin |
| collation_database   | utf8_bin |
| collation_server     | utf8_bin |
+----------------------+----------+
3 rows in set (0.00 sec)

mysql> show variables like '%character_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | utf8   |
| character_set_connection | utf8   |
| character_set_database   | utf8   |
| character_set_filesystem | binary |
| character_set_results    | utf8   |
| character_set_server     | utf8   |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.00 sec)

и выполнил после создания базы:

ALTER TABLE dicts MODIFY wo_stress varchar(255) CHARACTER SET utf8
COLLATE utf8_bin;

Всё работает корректно. Вопрос остался скорее теоретический - почему
character_set utf8 мы не используем по-умолчанию, сильно ли это снизит
эффективность? Тут с полгода назад это уже обсуждалось. На глаз
скорость работы не меняется, всё летает.

М.

  reply	other threads:[~2009-06-28  6:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-24 16:31 Michael Bykov
2009-06-25  6:57 ` Anton V. Boyarshinov
2009-06-26 10:30   ` Michael Bykov
2009-06-28  6:16     ` Mikhail Yakshin
2009-06-28  6:55       ` Michael Bykov [this message]
2009-06-28  8:41       ` Afanasov Dmitry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69c7dc8b0906272355u15d1f40boa56e82bdedceeb6b@mail.gmail.com \
    --to=m.bykov@gmail.com \
    --cc=sisyphus@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git