开发者

Mysql compare using left(X,2)="AB" or X like "AB%" for speed?

开发者 https://www.devze.com 2022-12-23 00:13 出处:网络
Which will perform better when searching for a key with a specific prefix in MySQL? ;- i) where left(X,2)=\"AB\"

Which will perform better when searching for a key with a specific prefix in MySQL? ;-

i) where left(X,2)="AB"

or

ii) 开发者_Python百科where X like "AB%"


Assuming you have an index on the column, the second is faster. The database can use an index when you use LIKE but it cannot when you use LEFT. In technical terms, LIKE is sargable but LEFT is not. You can find more information here.

0

精彩评论

暂无评论...
验证码 换一张
取 消