Teradata Explain17 Mar 2025 | 6 分钟阅读 EXPLAIN 命令是解析引擎 (PE) 对 AMP 的计划。EXPLAIN 命令以英文翻译形式返回解析引擎的执行计划。它可用于任何 SQL 语句,但不能用于另一个 EXPLAIN 命令。 当查询前置 EXPLAIN 命令时,解析引擎的执行计划将返回给用户,而不是 AMP。Explain 计划可以清晰地展示优化器将如何执行查询。 在 Teradata 系统中运行新开发的查询之前,最好先分析一下 explain 计划。 explain 计划可以通过两种方式获得。首先,在任何查询前添加 "EXPLAIN" 关键字,其次只需从键盘上按 "F6" 即可。 Explain 计划有助于分析查询的性能问题,因为它将任何复杂的查询分解到最低级别。Explain 计划提供了大量信息,例如
如果我们在查询语句前加上 explain 命令,或者只按 F6 键,优化器会向用户传递以下估计置信度消息,例如
Explain 计划关键字为了理解 EXPLAIN 计划,我们应该知道以下关键字。
EXPLAIN 计划的工作原理在任何 SQL 请求之前的 EXPLAIN 请求修饰符会使 Teradata 数据库显示该请求的执行计划。请求本身不会被提交执行。
使用 EXPLAIN 的好处以下是使用 Explain 计划的一些重要好处,例如
EXPLAIN 的示例考虑定义如下的 Employee 表。 全表扫描 (FTS)如果在 SELECT 语句中未指定任何条件,则优化器可以使用全表扫描,访问表的每一行。 示例 以下是优化器可以选择 FTS 的一个查询。 当执行上述查询时,它会产生以下输出。可以看出,优化器选择访问所有 AMP 和 AMP 内的所有行。 1. First, we lock a distinct TDUSER."pseudo table" for reading on a RowHash to prevent global deadlock for TDUSER.Employee. 2. Next, we lock TDUSER.Employee to read. 3. We do an all-AMPs RETRIEVE step from TDUSER.Employee by way of an all-rows scan with no residual conditions into Spool 1 (group_amps) built locally on the AMPs. The size of Spool 1 is estimated with low confidence to be 2 rows (116 bytes). The estimated time for this step is 0.03 seconds. 4. Finally, we send out an END TRANSACTION step to all AMPs involved in processing the request. //The contents of Spool 1 are sent back to the user as the result of statement 1. //The total estimated time is 0.03 seconds. 唯一主索引当使用唯一主索引访问行时,它是一个 AMP 操作。 当执行上述查询时,它会产生单 AMP 检索,优化器使用唯一主索引访问行。 1. First, we do a single-AMP RETRIEVE step from TDUSER.Employee by way of the unique primary index "TDUSER.Employee.Employee_Id = 1001" with no residual conditions. //The row is sent directly back to the user as the result of statement 1. //The total estimated time is 0.01 seconds. 唯一辅助索引当使用唯一辅助索引访问行时,它是一个双 AMP 操作。 示例 考虑定义如下的 Salary 表。 考虑以下 SELECT 语句。 当执行上述查询时,优化器使用唯一辅助索引在两个 AMP 操作中检索行。 1. First, we do a two-AMP RETRIEVE step from TDUSER.Salary by way of unique index # 4 "TDUSER.Salary.Employee_Id = 1001" with no residual conditions. //The row is sent directly back to the user as the result of statement 1. //The total estimated time is 0.01 seconds. 下一个主题Teradata 联接索引 |
我们请求您订阅我们的新闻通讯以获取最新更新。