mysql 演示数据库:http://downloads.mysql.com/docs/sakila-db.zip
匹配全值
explain select * from rental where rental_date=‘2005-05-25 17:22:10‘ and inventory_id=373 and customer_id=343
匹配值的范围查询
explain select * from rental where customer_id >= 373 and customer_id<400
匹配最左前缀
仅仅使用索引中的最左列进行查询,比如:在col1+col2+col3字段上的联合索引中,能够使用的索引情况可以有:col1 (col2+col3) ,col1+col2+col3。不能被使用的索引:col2 (col2+col3) 等情况。以payment表为例
alter table payment add index idx_payment_date (payment_date,amount,last_update);
explain select * from payment where payment_date=‘2006-02-14 15:16:03‘ and last_update=‘2006-02-15 22:12:32‘\G;
explain select * from payment where amount=3.98 and last_update=‘2006-02-15 22:12:32‘\G;
仅仅对索引进行查询
mysql中能够使用索引的典型场景
时间: 2024-10-22 08:49:07