mysql 敏感字符_如何在MySQL上對SQL大小寫敏感的字符串進行比較?

18

Answer posted Craig White, has big performance penalty

回答發布克雷格懷特,有很大的表現懲罰

SELECT * FROM `table` WHERE BINARY `column` = 'value'

because it don't use indexes. So, either you need to change the table collation like mention here https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html.

因為它不使用索引。因此,您需要更改表排序,比如這里提到的https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html。

OR

Easiest fix, you should use a BINARY of value.

最簡單的方法,應該使用二進制的值。

SELECT * FROM `table` WHERE `column` = BINARY 'value'

Eg.

如。

mysql> EXPLAIN SELECT * FROM temp1 WHERE BINARY col1 = "ABC" AND col2 = "DEF" ;

+----+-------------+--------+------+---------------+------+---------+------+--------+-------------+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+----+-------------+--------+------+---------------+------+---------+------+--------+-------------+

| 1 | SIMPLE | temp1 | ALL | NULL | NULL | NULL | NULL | 190543 | Using where |

+----+-------------+--------+------+---------------+------+---------+------+--------+-------------+

VS

VS

mysql> EXPLAIN SELECT * FROM temp1 WHERE col1 = BINARY "ABC" AND col2 = "DEF" ;

+----+-------------+-------+-------+---------------+---------------+---------+------+------+------------------------------------+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+----+-------------+-------+-------+---------------+---------------+---------+------+------+------------------------------------+

| 1 | SIMPLE | temp1 | range | col1_2e9e898e | col1_2e9e898e | 93 | NULL | 2 | Using index condition; Using where |

+----+-------------+-------+-------+---------------+---------------+---------+------+------+------------------------------------+

enter code here

1 row in set (0.00 sec)

一組一行(0.00秒)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值