首页 > 数据库 > MySQL > 重新学习MySQL数据库12:从实践sql语句优化开始
show global variables like "%slow%";
set global slow_query_log=on;
show global variables like "%long%";
set global long_query_time=1;
Sql查询语句:select sql_no_cache * from employees_tmp where first_name='Duangkaew' and gender='M'
explain select sql_no_cache * from employees_tmp where first_name='Duangkaew' and gender='M';
create index firstname on employees_tmp(first_name);
show index from employees_tmp;
select sql_no_cache * from employees_tmp where first_name='Duangkaew' and gender='M'
drop index first_name on employees_tmp;
create index index_gendar on employees_tmp(gender);
alter table employees_tmp add index idx_union (first_name,gender);
select * from user limit **1**,**20**
SELECT * from user limit **100001**,**20**; //time **0**.151s explain SELECT * from user limit **100001**,**20**;
select * from user where id>(select id from user where id>=**100000** limit **1**) limit **20**; //time **0**.003s
explain select * from user where id>(select id from user where id>=**100000** limit **1**) limit **20**;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69951287/viewspace-2664468/ ,如需转载,请注明出处,否则将追究法律责任。
注册时间:2019-10-19