优化 or 语句

时间:2023-03-09 22:21:34
优化 or 语句

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

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

rental 表索引情况

优化 or 语句

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

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

优化 or 语句

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

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

优化 or 语句