手头刚好有大表,所以直接测了一下。
MySQL中的like模糊匹配、locate(substr,str,pos)函数、instr(str,substr)函数 实测比较:
在303934条数据中查询body字段(未建索引)包含 [ 的数据:
select * from message where body like '%[%'; 查得112779条(like对[的兼容较好)
select * from message where locate('[',body)>0; 查得112778条
select * from message where instr(body,'[')>0; 查得112778条
查询方式 第1次用时 第2次用时 第3次用时 第4次用时
like 5.513s 5.586s 5.523s 5.422s
locate 5.524s 5.549s 5.440s 5.562s
instr 5.673s 5.671s 5.499s 5.487s
可见,like还是可以滴!