TRACE 语句用于查看具体 SQL 的执行情况。TRACE [SQL] 和 SHOW TRACE 要结合使用。
注意:TRACE SQL 和 EXPLAIN SQL 的区别在于 TRACE SQL 会实际执行该语句。
例如查看 select 1
这条语句的执行情况。
mysql> trace select1;
+---+
|1|
+---+
|1|
+---+
1 row inset(0.03 sec)
mysql> show trace;
+------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
| ID | TYPE | GROUP_NAME | DBKEY_NAME | TIME_COST(MS)| CONNECTION_TIME_COST(MS)| ROWS | STATEMENT | PARAMS |
+------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
| 0|Optimize| DRDS | DRDS |3 |0.00 | 0|select1 | NULL |
| 1|Query | TDDL5_00_GROUP | db218249098_sqa_zmf_tddl5_00_3309 |7 |0.15 | 1|select1 | NULL |
+------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
2 rows inset(0.01 sec)