ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
EXPLAIN:显示查询语句的执行计划,但不运行。 <br/> explain(执行计划)基本语法: ```sql explain [extended | dependency | authorization] query ``` ```txt extended:提供执行计划关于操作的额外信息,比如文件路径 dependency:提供json格式输出,包括查询所依赖的表和分区列表 authorization:列出所有需要授权的实体,包括查询的输入输出和授权失败 ``` **查看语句的执行计划** ```sql hive(default)> explain select * from emp; ``` **查看详细执行计划** ```sql hive(default)> explain extended select * from emp; ``` 一般显示如下信息: ```sql STAGE PLANS: Stage: Stage-1 Map Reduce Map Operator Tree: //发生在job的 map 处理阶段过程 TableScan        //读取表的数据 alias: emp //emp,若select * from emp e;表有别名则显示别名e Statistics: Num rows: 0 Data size: 74 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: age (type: int), name (type: string) outputColumnNames: _col0, _col1 Statistics: Num rows: 0 Data size: 74 Basic stats: PARTIAL Column stats: NONE Reduce Output Operator key expressions: _col0 (type: int) sort order: + Map-reduce partition columns: _col0 (type: int) Statistics: Num rows: 0 Data size: 74 Basic stats: PARTIAL Column stats: NONE value expressions: _col0 (type: int), _col1 (type: string) Reduce Operator Tree: //发生在job的 reduce 处理阶段过程 Extract Statistics: Num rows: 0 Data size: 74 Basic stats: PARTIAL Column stats: NONE File Output Operator compressed: false Statistics: Num rows: 0 Data size: 74 Basic stats: PARTIAL Column stats: NONE table: //说明输入格式是TextInputFormat input format: org.apache.hadoop.mapred.TextInputFormat //说明输出格式是HiveIgnoreKeyTextOutputFormat output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe Stage: Stage-0 Fetch Operator limit: -1 //--job中没有Limit ``` <br/> **通过工具生成可视化执行计划** ![](https://img.kancloud.cn/8c/d2/8cd28ae38b4d64104bf8b690d35a283a_699x641.png)