select count(*) as num from userinfo where name like '%班%' 这条语句怎么优化
来源:9-10 Mysql数据层的优化
下一秒若还能微笑着多好
2018-04-28
数据库1000万条数据,统计
select count(*) as num from userinfo where name like '%班%'
下面是我测试的结果:
select count(*) as num from lifi_a where name like "%班%" //5.28 查询统计结果11336
select count(id) as num from lifi_a where name like "%班%" //5.64 查询统计结果11336
select count(*) as num from lifi_a where name like '班%' //0秒 查询统计结果3739
select count(*) as num from lifi_a where name like '%班' //5.40秒 查询统计结果3828
有什么更好的方法优化吗? 我看like '班%' 加上索引以后是挺快 但是查询出来的结果就不对了
写回答
1回答
-
Jason
2018-04-29
%在前会导致全表扫描,因此%在前会导致SQL查询低效,最好的提高效率的方式就是使用全文索引引擎,例如:coreseek或者elasticsearch
00
相似问题