Teradata - 解釋



EXPLAIN 命令以英文返回解析引擎的執行計劃。它可以與除另一個 EXPLAIN 命令之外的任何 SQL 語句一起使用。當查詢前面帶有 EXPLAIN 命令時,解析引擎的執行計劃將返回給使用者,而不是 AMP。

EXPLAIN 示例

考慮具有以下定義的 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.

唯一二級索引

如果使用唯一二級索引訪問行,則這是一個兩個 AMP 操作。

示例

考慮具有以下定義的 Salary 表。

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 的暫存檔案。

…我們執行 SMS(集合操作步驟)…

使用 UNION、MINUS 或 INTERSECT 運算子組合行。

…它透過雜湊碼重新分佈到所有 AMP。

重新分佈資料以準備連線。

…它在所有 AMP 上都進行了複製。

複製來自較小表(在 SPOOL 方面)的資料以準備連線。

…(one_AMP)或(group_AMPs)

指示將使用一個 AMP 或 AMP 子集而不是所有 AMP。

廣告

© . All rights reserved.