sql查询与索引

背景:有以下一个查询语句

SELECT b.id , b.product_name,b.generate_time,b.expiry_date,b.uid,b.query_times,b.state FROM product_bottle b where 1=1 and b.product_name LIKE concat('%',?,'%') and b.state = ? limit ?,? 

查询很慢,刚开始不知道为什么,前辈说这样让索引无用武之地。


在bottle表中,存在product_name,但同时也存在product_id 。所以即使需求是根据name来查询,自己也应该通过转换来使用索引id来查询。

索引:索引是一种增强式的存在,这意味着,即使没有索引,SQL仍然可以实现应有的功能。


猜你喜欢

转载自blog.csdn.net/qq_34638435/article/details/80910475