mysql模糊查询like优化
生活随笔
收集整理的這篇文章主要介紹了
mysql模糊查询like优化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、使用全文索引
MySQL 之全文索引:https://blog.csdn.net/mrzhouxiaofei/article/details/79940958
-- 直接查詢400ms SELECT * from item where title like '%小米%'; -- 創建全文索引,然后使用全文索引 35ms create fulltext index item_title_fulltext on item(title); select * from item where match(title) against('小米*' in boolean mode);幾個注意點
- 對于中文,可以使用 MySQL 5.7.6 之后的版本,或者第三方插件。
- 使用全文索引前,搞清楚版本支持情況;
- 全文索引比 like + % 快 N 倍,但是可能存在精度問題;
- 如果需要全文索引的是大量數據,建議先添加數據,再創建索引;
2、使用ICP特性
【mysql】關于ICP、MRR、BKA等特性:https://www.cnblogs.com/chenpingzhao/p/6720531.html
連模糊匹配like %%怎么優化都不知道:https://mp.weixin.qq.com/s/ygvuP35B_sJAlBHuuEJhfg
3、使用覆蓋索引優化
-- 直接查詢和添加了索引都是400ms SELECT * from item where title like '%小米%';-- 添加title列添加索引,使用覆蓋索引 explain SELECT title from item where title like '%小米%'; -- id也能使用覆蓋索引,因為innodb存儲引擎的輔助索引的葉子結點存的是主鍵id -- 300ms相比之前快了100ms select * from item a , (SELECT id from item where title like '%小米%') b where a.id = b.id; explain select * from item a , (SELECT id from item where title like '%小米%') b where a.id = b.id;總結
以上是生活随笔為你收集整理的mysql模糊查询like优化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 即刻下载|连锁零售数字化转型难?领先企业
- 下一篇: 人工智障聊天机器人