mysql的trace跟踪


root@D0DCS 15:17:24 [jing]> show create table t1\G;
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `c1` int(11) NOT NULL DEFAULT '0',
  `c2` varchar(128) DEFAULT NULL,
  `c3` varchar(64) DEFAULT NULL,
  `c4` int(11) DEFAULT NULL,
  PRIMARY KEY (`c1`),
  KEY `ind_c2` (`c2`),
  KEY `ind_c4` (`c4`),
  KEY `ind_c2_c4` (`c2`,`c4`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)


ERROR: 
No query specified


root@D0DCS 15:17:30 [jing]> select * from t1;
+----+------+------+------+
| c1 | c2   | c3   | c4   |
+----+------+------+------+
|  1 | a    | A    |   10 |
|  2 | b    | B    |   20 |
|  3 | b    | BB   |   20 |
|  4 | b    | BBB  |   30 |
|  5 | b    | BBB  |   40 |
|  6 | c    | C    |   50 |
|  7 | d    | D    |   60 |
+----+------+------+------+
7 rows in set (0.00 sec)






#打开profiling 的设置  
SET profiling = 1;  
SHOW VARIABLES LIKE '%profiling%';  
  
#查看队列的内容  
show profiles;    
#来查看统计信息  
show profile block io,cpu for query 3;  




root@D0DCS 14:46:31 [jing]> explain select * from t1 where  c2='b' and c4=20;
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys           | key    | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
|  1 | SIMPLE      | t1    | ref  | ind_c2,ind_c4,ind_c2_c4 | ind_c4 | 5       | const |    2 | Using where |
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
1 row in set (0.00 sec)






查看查看OPTIMIZER_TRACE方法:
set optimizer_trace="enabled=on"; 
set optimizer_trace_max_mem_size=1000000;




root@D0DCS 14:47:12 [jing]>   set end_markers_in_json=on;  
Query OK, 0 rows affected (0.00 sec)


root@D0DCS 14:55:15 [jing]> explain select * from t1 where  c2='b' and c4=20;
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys           | key    | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
|  1 | SIMPLE      | t1    | ref  | ind_c2,ind_c4,ind_c2_c4 | ind_c4 | 5       | const |    2 | Using where |
+----+-------------+-------+------+-------------------------+--------+---------+-------+------+-------------+
1 row in set (0.00 sec)


root@D0DCS 14:55:44 [jing]> select * from information_schema.optimizer_trace\G;
*************************** 1. row ***************************
                            QUERY: explain select * from t1 where  c2='b' and c4=20
                            TRACE: {
  "steps": [
    {
      "join_preparation": {   ---优化准备工作
        "select#": 1,
        "steps": [
          {
     

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值