Teradata教程

Teradata EXPLAIN

EXPLAIN 命令返回英文解析引擎的执行计划。它可以与任何 SQL 语句一起使用,除了另一个 EXPLAIN 命令。当查询之前带有 EXPLAIN 命令时,解析引擎的执行计划将返回给用户而不是 AMP。

解释示例

考虑具有以下定义的 Employee 表。
CREATE SET TABLE EMPLOYEE,FALLBACK ( 
   EmployeeNo INTEGER, 
   FirstName VARCHAR(30), 
   LastName VARCHAR(30),
   DOB DATE FORMAT 'YYYY-MM-DD', 
   JoinedDate DATE FORMAT 'YYYY-MM-DD', 
   DepartmentNo BYTEint 
) 
UNIQUE PRIMARY INDEX ( EmployeeNo );
下面给出了 EXPLAIN 计划的一些例子。

全表扫描 (FTS)

当在 SELECT 语句中没有指定条件时,优化器可以选择使用全表扫描来访问表的每一行。

示例

以下是优化器可以选择 FTS 的示例查询。
EXPLAIN SELECT * FROM employee;
执行上述查询时,会产生以下输出。可以看出,优化器选择访问所有 AMP 和 AMP 中的所有行。
1) First, we lock a distinct TDUSER."pseudo table" for read on a 
   RowHash to prevent global deadlock for TDUSER.employee.  
2) Next, we lock TDUSER.employee for 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), which is 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 操作。
EXPLAIN SELECT * FROM employee WHERE EmployeeNo = 101;
执行上述查询时,会产生以下输出。可以看出,这是一个单 AMP 检索,优化器使用唯一的主索引来访问该行。
1) First, we do a single-AMP RETRIEVE step from TDUSER.employee by 
   way of the unique primary index "TDUSER.employee.EmployeeNo = 101" 
   with no residual conditions. The estimated time for this step is 
   0.01 seconds.  
→ The row is sent directly back to the user as the result of 
   statement 1.  The total estimated time is 0.01 seconds.

唯一二级索引

当使用唯一二级索引访问行时,这是一个两级操作。

示例

考虑具有以下定义的表薪水。
CREATE SET TABLE SALARY,FALLBACK ( 
   EmployeeNo INTEGER, 
   Gross INTEGER, 
   Deduction INTEGER, 
   NetPay INTEGER 
)
PRIMARY INDEX ( EmployeeNo ) 
UNIQUE INDEX (EmployeeNo);
考虑以下 SELECT 语句。
EXPLAIN SELECT * FROM Salary WHERE EmployeeNo = 101;
执行上述查询时,会产生以下输出。可以看出,优化器使用唯一的二级索引在两次 amp 操作中检索行。
1) First, we do a two-AMP RETRIEVE step from TDUSER.Salary 
   by way of unique index # 4 "TDUSER.Salary.EmployeeNo = 
   101" with no residual conditions.  The estimated time for this 
   step is 0.01 seconds.  
→ The row is sent directly back to the user as the result of 
   statement 1.  The total estimated time is 0.01 seconds.

附加条款

以下是 EXPLAIN 计划中常见的术语列表。
...(最后一次使用)...
不再需要假脱机文件,将在此步骤完成后释放。
... 没有剩余条件...
所有适用条件已应用于行。
...结束交易...
释放事务锁,并提交更改。
...消除重复行...
重复行只存在于假脱机文件中,不存在于设置表中。进行 DISTINCT 操作。
... 通过遍历索引 #n 只提取行 ID...
构建一个包含在二级索引(索引#n)中找到的行 ID 的假脱机文件
...我们做一个短信(设置操作步骤)...
使用 UNION、MINUS 或 INTERSECT 运算符组合行。
... 通过哈希码重新分配给所有 AMP。
重新分配数据以准备连接。
... 在所有 AMP 上重复。
从较小的表(就 SPOOL 而言)复制数据以准备连接。
... (one_AMP) 或 (group_AMPs)
表示将使用一个 AMP 或 AMP 子集而不是所有 AMP。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4