EXPLAIN命令以英語返回解析引擎的執(zhí)行計(jì)劃。 它可以與除另一個(gè)EXPLAIN命令之外的任何SQL語句一起使用。 當(dāng)查詢前面有EXPLAIN命令時(shí),解析引擎的執(zhí)行計(jì)劃將返回給用戶,而不是AMP。
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計(jì)劃的一些示例。
EXPLAIN SELECT * FROM employee;
當(dāng)執(zhí)行上述查詢時(shí),它將產(chǎn)生以下輸出。 可以看出,優(yōu)化器選擇訪問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.
當(dāng)使用唯一主索引訪問行時(shí),則它是一個(gè)AMP操作。
EXPLAIN SELECT * FROM employee WHERE EmployeeNo = 101;
當(dāng)執(zhí)行上述查詢時(shí),它將產(chǎn)生以下輸出。 可以看出,它是單AMP檢索,優(yōu)化器使用唯一的主索引訪問該行。
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);
請(qǐng)考慮以下SELECT語句。
EXPLAIN SELECT * FROM Salary WHERE EmployeeNo = 101;
當(dāng)執(zhí)行上述查詢時(shí),它將產(chǎn)生以下輸出。 可以看出,優(yōu)化器在使用唯一二級(jí)索引的兩個(gè)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.
更多建議: