EXPLAIN Request Modifier and Standard Indexed Access - Analytics Database - Teradata Vantage

SQL Request and Transaction Processing

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
zfm1628111633230.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
evd1472255317510
lifecycle
latest
Product Category
Teradata Vantage™

The EXPLAIN request modifier is useful in determining whether the indexes defined for a table are properly defined, useful, and efficient.

As illustrated in other join examples, EXPLAIN identifies any unique indexes that may be used to process a request.

When conditional expressions use nonunique secondary indexes, EXPLAIN also indicates whether the data rows are retrieved using spooling or bit mapping.

This feature is illustrated in the following examples. Compare the two requests and their corresponding EXPLAIN descriptions.

Note that in the first request the table is small (and that dept_no, salary, yrs_exp, and ed_lev have been defined as separate, nonunique indexes), so a full-table scan is used to access the data rows.

In the second request, however, the table is extremely large. Because of this, the Optimizer determines that bit mapping of the subtable rowIDs is the faster retrieval method.

Full-Table Scan Example

This request returns the following EXPLAIN report:

EXPLAIN 
SELECT COUNT(*)
FROM employee
WHERE dept_no = 500
AND salary > 25000
AND yrs_exp >= 3
AND ed_lev >= 12;
Explanation 
--------------------------------------------------------
1) First, we lock PERSONNEL.employee for read on a resereved 
   RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for read.
3) We do an all-AMPs SUM step to aggregate from PERSONNEL.Employee by
   way of an all-rows scan with a condition of
   ("(PERSONNEL.employee.DeptNo = 500) AND
   ((PERSONNEL.employee.Salary > 25000.00) AND
   ((PERSONNEL.employee.YrsExp >= 3) AND
   (PERSONNEL.employee.EdLev >= 12 )))").
   Aggregate Intermediate Results are computed globally, then placed in
   Spool 2.
4) We do an all-AMPs RETRIEVE step from Spool 2 (Last Use) by way of
   an all-rows scan into Spool 1, which is built locally on the AMPs.
   The size of Spool 1 is estimated with high confidence to be 1 row (32 bytes). 
   The estimated time for this step is 0.06 seconds.
5) 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.

New terminology in this explanation is defined as follows:

Phrase Definition
SUM step to aggregate The table is searched row by row, the qualifying rows are counted for each AMP on which they were found, and each count is held in a local spool.
computed globally The final computation involves all the intermediate spool data.

Unique Primary Index Example

The EXPLAIN request modifier generates the following response for this request:

EXPLAIN 
SELECT name, dept_no
FROM employee
WHERE empno = 10009;
Explanation
-----------------------------------------------------
1) First, we do a single-AMP RETRIEVE step from Personnel.Employee by way of the unique primary index "PERSONNEL.Employee.EmpNo = 10009" with no residual conditions. The estimated time for this step is 0.04 seconds.
-> The row is sent directly back to the user as the result of statement 1. The total estimated time is 0.04 seconds.

SELECT Example with a Condition on a Nonunique Index

The WHERE condition in this example is based on a column that is defined as a nonunique index. Note that the system places a READ lock on the table.

The EXPLAIN request modifier generates the following response for this request:

EXPLAIN 
SELECT emp_no, dept_no
FROM employee
WHERE name = 'Smith T';
Explanation
-----------------------------------------------------------------------
1) First, we lock PERSONNEL.employee for read on a
   RowHash to prevent global deadlock.
2) Next, we lock PERSONNEL.employee for read.
3) We do an all-AMPs RETRIEVE step from PERSONNEL.employee by way of
   index # 4 "PERSONNEL.employee.Name = 'Smith T '" 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 33,563 rows (1,443,209 bytes). The estimated time for this
   step is 0.34 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.34 seconds.

SELECT Example with a Condition on a Unique Secondary Index

Assume that the employee table has another column (socsecno), where soc_sec_no is defined as a unique secondary index.

If the WHERE condition is based on this column, then the EXPLAIN request modifier generates the following response for this request:

EXPLAIN 
SELECT name, emp_no
FROM employee
WHERE soc_sec_no = '123456789';
Explanation
-----------------------------------------------------
1) First, we do a two-AMP RETRIEVE step from PERSONNEL.Employee by way
   of unique index # 20 "PERSONNEL.Employee.socSecNo = 123456789" with 
   no residual conditions. The estimated time for this step 
   is 0.09 seconds.
-> The row is sent directly back to the user as the result of statement 1.
   The total estimated time is 0.09 seconds.

Indexed Access with Bit Mapping Example

This request returns the following EXPLAIN report:

EXPLAIN 
SELECT COUNT(*)
FROM main
WHERE num_a = '101'    
AND num_b  = '02'    
AND kind  = 'B'    
AND event = '001';
Explanation 
------------------------------------------------------ 
...
2) Next, we do a BMSMS (bit map set manipulation) step that intersects
   the following row id bit maps: 
   1) The bit map built for TESTING.Main by way of index # 12
      "TESTING.Main.Kind = ’B’".
   2) The bit map build for TESTING.Main by way of index # 8
      "TESTING.Main.Num_B = ’02’". 
   3) The bit map built for TESTING.Main by way of index # 16
      "TESTING.Main.Event =’001’". 
   The resulting bit map is placed in Spool 3. The estimated time
   for this step is 17.77 seconds.
3) We do a SUM step to aggregate from TESTING.Main by way of
   index # 4 "TESTING.Main.Num_A = ’101’" and the bit map in Spool
   3 (Last Use) with a residual condition of
   ("(TESTING.Main.Num_B = ’02’) and
   ((TESTING.Main.Kind = ’B’) and TESTING.Main.Event = ’001’))").
   Aggregate Intermediate Results are  computed globally, then
   placed in Spool 2.
4) We do an all-AMPs RETRIEVE step from Spool 2 (Last Use) by way
   of an all-rows scan into Spool 1, which is built locally on the
   AMPs. The size of Spool 1 is estimated to be 20 rows. The
   estimated time for this step is 0.11 seconds.
...

New terminology in this explanation is defined as follows:

Phrase Definition
A BMSMS (bit map set manipulation step) that intersects the following Row-Id bit maps:

The bit map built for … by way of index # n

The bit map built for … by way of index # n

On each nonunique secondary index subtable, each data rowID is assigned a number from 0 to 32,767. This number is used as an index into a bit map in which the bit for each qualifying row is turned on.

BMSMS indicates that the intersection of sets of qualifying rows is computed by applying the logical AND operation to the bitmap representation of the sets.

residual condition Selected rows are further qualified by one or more conditional expressions.