簡介¶
sql where 條件有like,需要走索引
內容¶
select * from table where columnName like 'keyword%' //只有這一條會走索引
select * from table where columnName like '%keyword%' //無法走索引
select * from table where columnName like '%keyword' // 如果index是reverse,這條會生效
第3條改寫locate,可走索引
select * from table where columnName locate('keyword' , table.field) > 0 // 返回keyword第一次出现的index位置
select * from table where columnName and reverse(table.field) like reverse('%keyword')