【发布时间】:2019-09-07 13:18:15
【问题描述】:
我还有来自this question 的后续跟进。尽管LIKE 模式搜索(由于排序规则集)使用索引并且比LIKE BINARY 快得多,但对这两个查询进行解释似乎表明两个查询都使用索引。
explain select count(*) from TransactionApp_transactions where merchantId like 'VCARD000%'
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------------------+-------+--------------------------------------+--------------------------------------+---------+------+----------+--------------------------+
| 1 | SIMPLE | TransactionApp_transactions | range | TransactionApp_transactions_fc3e7169 | TransactionApp_transactions_fc3e7169 | 767 | NULL | 12906834 | Using where; Using index |
我得到与explain select count(*) from TransactionApp_transactions where merchantId like binary 'VCARD000%'; 完全相同的EXPLAIN 输出(rows 是一个稍小的数字)
key 列包含两个 EXPLAIN 输出的索引名称,但 LIKE BINARY 需要 26 秒,而简单的 LIKE 只需 2 秒。
【问题讨论】:
-
请将代码发布为文本而不是图像
-
很抱歉。现在用文字编辑我的问题。
-
stackoverflow.com/questions/8097996/… 你能检查一下这个答案吗
-
@AshishMahajan - 是的,我知道
LIKE BINARY不使用索引,因为排序规则集是非二进制的,但为什么EXPLAIN输出说它使用索引?跨度> -
你有
merchantId的索引吗?请提供SHOW CREATE TABLE。
标签: mysql database collation database-indexes