Home > Database > Mysql Tutorial > body text

十六、mysql 分区之 简单sql优化1_MySQL

WBOY
Release: 2016-05-31 08:46:35
Original
942 people have browsed it
1.使用 show session status like '%Com_%'; 可以查看当前连接的各个sql的执行频率       show global status like '%Com_%'; 可以查看从上次mysql服务器启动到目前为止sql的执行频率2.explain select * from tmp;    mysql> explain select * from zi_emp where tid = 1000/G    *************************** 1. row ***************************               id: 1      select_type: SIMPLE            table: zi_emp             type: ALL    possible_keys: NULL              key: NULL          key_len: NULL              ref: NULL             rows: 2            Extra: Using where    1 row in set (0.00 sec)        PS::type类型中,ALL为效率最差,因为这样意味着进行全表扫描        index类型为索引全扫描        range为索引范围扫描        ref为非唯一索引或唯一索引的前缀扫描        eq_ref唯一索引扫描        const/system 单表中只有一个匹配的行,比如用户表        NULL  没有访问到表或索引 比如:select 1=1;3.哈哈,发现一个很好的东西    explain extended select * from zi_emp; 查看执行sql语句前,mysql优化器做了点什么    show warnings;    mysql> show warnings/G    *************************** 1. row ***************************      Level: Note       Code: 1003    Message: select `bin`.`zi_emp`.`tid` AS `tid`,`bin`.`zi_emp`.`tname` AS `tname` from `bin`.`zi_emp`    1 row in set (0.00 sec)        PS::没错,你看的就是一条完整的sql语句,也就是说这可能是msyql给定的最好的sql语句了,可以学习并复用4.explain partitions select * from zi_emp where xxxxx 可以查看当前记录的分区所在位置
Copy after login

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template