Teradata - Explain
EXPLAIN command returns the execution
plan of parsing engine in English. It can be
used with any SQL statement except on
another EXPLAIN command. When a query
is preceded with EXPLAIN command, the
execution plan of the Parsing Engine is
returned to the user instead of AMPs.
Examples of EXPLAIN
Consider the table Employee with the
following definition.
CREATE SET TABLE EMPLOYEE,FALLBACK (
EmployeeNo INTEGER,
FirstName VARCHAR(30),
LastName VARCHAR(30),
DOB DATE FORMAT 'YYYY-MM-DD',
JoinedDate DATE FORMAT 'YYYY-MM-D
DepartmentNo BYTEINT
)
UNIQUE PRIMARY INDEX ( EmployeeNo );
Some examples of EXPLAIN plan are given
below.
Full Table Scan (FTS)
When no conditions are specified in the
SELECT statement, then the optimizer may
choose to use Full Table Scan where each
and every row of the table is accessed.
Example
Following is a sample query where the
optimizer may choose FTS.
EXPLAIN SELECT * FROM employee;
When the above query is executed, it
produces the following output. As can be
seen the optimizer chooses to access all
AMPs and all rows within the AMP.
irst, we lock a distinct TDUSER."pseudo
owHash to prevent global deadlock for TD
ext, we lock TDUSER.employee for read.
e do an all-AMPs RETRIEVE step from TDUS
ll-rows scan with no residual conditions
group_amps), which is built locally on t
pool 1 is estimated with low confidence
he estimated time for this step is 0.03
inally, we send out an END TRANSACTION s
n processing the request.
he contents of Spool 1 are sent back to t
tatement 1. The total estimated time is
Unique Primary Index
When the rows are accessed using Unique
Primary Index, then it is one AMP operation.
EXPLAIN SELECT * FROM employee WHERE Em
When the above query is executed, it
produces the following output. As can be
seen it is a single-AMP retrieval and the
optimizer is using the unique primary index
to access the row.
1) First, we do a single-AMP RETRIEVE s
way of the unique primary index "TDU
with no residual conditions. The est
0.01 seconds.
→ The row is sent directly back to the
statement 1. The total estimated ti
Unique Secondary Index
When the rows are accessed using Unique
Secondary Index, it’s a two amp operation.
Example
Consider the table Salary with the following
definition.
CREATE SET TABLE SALARY,FALLBACK (
EmployeeNo INTEGER,
Gross INTEGER,
Deduction INTEGER,
NetPay INTEGER
)
PRIMARY INDEX ( EmployeeNo )
UNIQUE INDEX (EmployeeNo);
Consider the following SELECT statement.
EXPLAIN SELECT * FROM Salary WHERE Empl
When the above query is executed, it
produces the following output. As can be
seen the optimizer retrieves the row in two
amp operation using unique secondary
index.
1) First, we do a two-AMP RETRIEVE step
by way of unique index # 4 "TDUSER.S
101" with no residual conditions. T
step is 0.01 seconds.
→ The row is sent directly back to the
statement 1. The total estimated ti
Additional Terms
Following is the list of terms commonly seen
in EXPLAIN plan.
... (Last Use) …
A spool file is no longer needed and will
be released when this step completes.
... with no residual conditions …
All applicable conditions have been
applied to the rows.
... END TRANSACTION …
Transaction locks are released, and
changes are committed.
... eliminating duplicate rows ...
Duplicate rows only exist in spool files,
not set tables. Doing a DISTINCT
operation.
... by way of a traversal of index #n
extracting row ids only …
A spool file is built containing the Row
IDs found in a secondary index (index
#n)
... we do a SMS (set manipulation step) …
Combining rows using a UNION,
MINUS, or INTERSECT operator.
... which is redistributed by hash code to all
AMPs.
Redistributing data in preparation for a
join.
... which is duplicated on all AMPs.
Duplicating data from the smaller table
(in terms of SPOOL) in preparation for a
join.
... (one_AMP) or (group_AMPs)
Indicates one AMP or subset of AMPs
will be used instead of all AMPs.
Print Page