sql语句性能调优 mysql

1.select count(aa.delete_flag) from (
select e.delete_flag
from exercise e
where  1=1
and e.lib_id='808080aa3f7639b7013f7a1010cf0012'
and e.owner_id = 'ff8080813ec7d82f013ecb13f9d90237'
and e.delete_flag =0
) aa;

 

exercise表有100万,ower_id,lib_id,delete_flag建了联合索引

 

2.分布查询

如:select film_id, description from sakila.film order by title limit 12342, 12;

可以改成如下:

select film.film_id, film.description
from sakila.film
     inner join(
        select film_id from sakila.film
        order by title limit 12342, 12
     ) as lim USING(film_id);

 

你可能感兴趣的:(sql语句性能调优 mysql)