DESCRIBE 语句

DESCRIBEEXPLAIN 是同义词,另外还可以缩写为 DESC。请参考 EXPLAIN 语句的用法。

EXPLAIN 语句

  1. {EXPLAIN | DESCRIBE | DESC}
  2. tbl_name [col_name]
  3. {EXPLAIN | DESCRIBE | DESC}
  4. [explain_type]
  5. explainable_stmt
  6. explain_type:
  7. FORMAT = format_name
  8. format_name:
  9. "DOT"
  10. explainable_stmt: {
  11. SELECT statement
  12. | DELETE statement
  13. | INSERT statement
  14. | REPLACE statement
  15. | UPDATE statement
  16. }

EXPLAIN 语句详细信息参考理解 TiDB 执行计划章节。

除了 MySQL 标准的结果格式之外,TiDB 还支持输出 DotGraph 结果,这时需要指定 FORMAT = "dot",示例如下:

  1. create table t(a bigint, b bigint);
  2. desc format = "dot" select A.a, B.b from t A join t B on A.a > B.b where A.a < 10;
  3. TiDB > desc format = "dot" select A.a, B.b from t A join t B on A.a > B.b where A.a < 10;desc format = "dot" select A.a, B.b from t A join t B on A.a > B.b where A.a < 10;
  4. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  5. | dot contents |
  6. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  7. |
  8. digraph HashRightJoin_7 {
  9. subgraph cluster7{
  10. node [style=filled, color=lightgrey]
  11. color=black
  12. label = "root"
  13. "HashRightJoin_7" -> "TableReader_10"
  14. "HashRightJoin_7" -> "TableReader_12"
  15. }
  16. subgraph cluster9{
  17. node [style=filled, color=lightgrey]
  18. color=black
  19. label = "cop"
  20. "Selection_9" -> "TableScan_8"
  21. }
  22. subgraph cluster11{
  23. node [style=filled, color=lightgrey]
  24. color=black
  25. label = "cop"
  26. "TableScan_11"
  27. }
  28. "TableReader_10" -> "Selection_9"
  29. "TableReader_12" -> "TableScan_11"
  30. }
  31. |
  32. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. 1 row in set (0.00 sec)

如果电脑上安装了 dot 程序 (包含在 graphviz 软件包中),可以通过如下方式生成 PNG 文件:

  1. dot xx.dot -T png -O
  2. 这里的 xx.dot 是上面的语句返回结果。

如果没有安装 dot,可以将结果拷贝到这个网站,可以得到一个树状图:

Explain Dot

USE 语句

  1. USE db_name

切换默认 Database,当 SQL 语句中的表没有显示指定 Database 时,即使用默认 Database。