问题遇到的现象和发生背景
请问这句MySQL怎么去掉 or ,因为删掉or b.bname = "" explain显示用到了索引,查询很快,但不删掉就是all没用到索引,查询要5s,怀疑是or使索引失效
select bid from book a ,querybook b where ( a.bname in (b.bname) or b.bname = "" ) and
(a.bauthor in (b.bauthor) or b.bauthor = "" )
请问这句MySQL怎么去掉 or ,因为删掉or b.bname = "" explain显示用到了索引,查询很快,但不删掉就是all没用到索引,查询要5s,怀疑是or使索引失效
select bid from book a ,querybook b where ( a.bname in (b.bname) or b.bname = "" ) and
(a.bauthor in (b.bauthor) or b.bauthor = "" )
优化的方法是改成 union。分成多个 sql,走各自的索引。
https://blog.csdn.net/wenniuwuren/article/details/89472136