不幸的OpenCart是utf8_bin,我的表格整理是无法搜索名称中带有重音的产品名称.我在谷歌搜索,发现校对必须是utf8_general_ci兼容重音和不区分大小写的搜索.
如果我在搜索查询中添加整理声明怎么办?
SELECT *
FROM `address`
COLLATE utf8_general_ci
LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
它有任何(坏)副作用吗?我是关于索引,性能的问题?还是完全安全的?
恐怕您必须考虑对查询性能的副作用,尤其是那些使用索引的查询。这是一个简单的测试:
mysql> create table aaa (a1 varchar(100) collate latin1_general_ci, tot int);
insert into 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 | Extra |
+-------+--------------+------+-----+---------+-------+
| a1 | varchar(100) | YES | MUL | NULL | |
| tot | int(11) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.53 sec)
mysql> explain select * from aaa where a1='test1' ;
+----+-------------+-------+------+---------------+--------+---------+-------+--
----+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | r
ows | Extra |
+----+-------------+-------+------+---------------+--------+---------+-------+--
----+-----------------------+
| 1 | SIMPLE | aaa | ref | aindex | aindex | 103 | const |
1 | Using index condition |
+----+-------------+-------+------+---------------+--------+---------+-------+--
----+-----------------------+
1 row in set (0.13 sec)
mysql> explain select * from aaa where a1='test1' collate utf8_general_ci;
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows
| Extra |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+
| 1 | SIMPLE | aaa | ALL | NULL | NULL | NULL | NULL | 3
| Using where |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+
1 row in set (0.06 sec)
Run Code Online (Sandbox Code Playgroud)
您可以看到,当您使用其他排序规则搜索 a1 时,MySQL 停止使用 a1 上的索引,这对您来说可能是一个大问题。
为了确保索引用于查询,您可能必须将列排序规则更改为最常用的排序规则。
| 归档时间: |
|
| 查看次数: |
14863 次 |
| 最近记录: |