优化 or 语句

mysql 演示数据库:http://downloads.mysql.com/docs/sakila-db.zip

对于 or  语句,如果要利用索引,则 or 之间的每个条件都必须有索引

rental 表索引情况

 or查询的前后都有索引列---(使用到了索引)

explain select * from rental where staff_id='' or inventory_id=''G;

复合索引的列  ---(没有使用索引)

 explain select * from rental where rental_date='' or inventory_id=''G;

原文地址:https://www.cnblogs.com/dsitn/p/7092298.html