collation - MySQL: Collate in query - any side effects? -


my opencart table collation utf8_bin, unfortunately can't search product names accent in name. searched on google , found collation must utf8_general_ci accent compatible , case insensitive search.

what if add collate declaration search query?

select *   `address`  collate utf8_general_ci limit 0 , 30 

does have (bad) side effect? red problems indexing, performance? or totally safe?

i'm afraid have consider side effects on query performance, using indexes. here simple test:

mysql> create table aaa (a1 varchar(100) collate latin1_general_ci, tot int); insert aaa values('test1',3) , ('test2',4), ('test5',5);  mysql> create index aindex on aaa (a1); query ok, 0 rows affected (0.59 sec) records: 0  duplicates: 0  warnings: 0  mysql> desc aaa; +-------+--------------+------+-----+---------+-------+ | field | type         | null | key | default | | +-------+--------------+------+-----+---------+-------+ | a1    | varchar(100) | yes  | mul | null    |       | | tot   | int(11)      | yes  |     | null    |       | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.53 sec)   mysql> explain select * aaa a1='test1' ; +----+-------------+-------+------+---------------+--------+---------+-------+-- ----+-----------------------+ | id | select_type | table | type | possible_keys | key    | key_len | ref   | r ows |                 | +----+-------------+-------+------+---------------+--------+---------+-------+-- ----+-----------------------+ |  1 | simple      | aaa   | ref  | aindex        | aindex | 103     | const |   1 | using index condition | +----+-------------+-------+------+---------------+--------+---------+-------+-- ----+-----------------------+ 1 row in set (0.13 sec)  mysql> explain select * aaa a1='test1' collate utf8_general_ci; +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows  |       | +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ |  1 | simple      | aaa   |  | null          | null | null    | null |    3  | using | +----+-------------+-------+------+---------------+------+---------+------+----- -+-------------+ 1 row in set (0.06 sec) 

you can see mysql stopping using index on a1 when search using collation, can huge problem you.

to make sure indexes being used queries, may have change column collation used one.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -