Professional Documents
Culture Documents
Join Strategy
LEVEL LEARNER
Created By:
Credential
Information:
Version and
Date:
TD/PPT/2012-09-10/1.0
Icons Used
Questions
Tools
Coding
Standards
Test Your
Understandi
ng
Referenc
e
A Welcome
Break
Contacts
Demonstration
Hands on
Exercise
The inner join above focuses on returning all rows when there
is a match between the two tables.
Teradata can perform this join with rapid speed.
9
12
The reason is
because neither
columns selected in
the ON Clause are the
Primary Index of the
respective tables.
14
15
In this inner join above, the two tables involved in the join are the
Employee table and the Department table.
The DEPT column is the join equality and is the Primary Index
Column in the Department table.
The Employee table has the EMP column as the Primary Index.
The final analysis of this join is that the Department table is small
and makes a good candidate for this type of join strategy.
Teradata will choose to duplicate the entire Department table on
each AMP into spool.
Once this is completed, then the next step is for the AMPs to join
the base Employee rows with the Department rows.
16
17
18
19
20
21
Product Join
Product Joins compare every row of one table to every row of
another table.
The result of this join is a product of the number of rows in table
one multiplied by the number of rows in table two.
About 99% of the time, product joins are major mistakes, because
all rows in both tables will be compared.
SELECT EMP, E.Dept, Name , DeptName
FROM EMPLOYEE E, DEPARTMENT D
WHERE EMP LIKE '_b%';
To avoid a product join, the join should be based on an EQUALITY
condition.
The equality statement reads WHERE EMP Like _b%, but no
common domain condition between the two tables (i.e., e.dept =
d.dept).
Another cause of a product join is when aliases are not used after
24being established.
26
30
Hash IndexPurpose
Hash Index is used for same purpose as single table join index,
i.e. generate the result set from the join and store in PERM space
for PEs use.
Hash Index create a partial or full replication of Base table with a
primary index on a foreign key column table to facilitate the joins
of very large table by hashing them to the same AMP.
Hash Index can not work on aggregates like single table join
index.
Hash Index can be defined on one table only.
The result set generated by Hash Index cannot be accessed by
the query.
The rows of Hash Index are sometimes a little shorter than the
31
Single table join index rows. Hence have a small storage
32
Hash IndexExamples
This index is built for the table 'emp1' which is defined as follows:
CREATE SET TABLE emp1
(employee_number INTEGER
, manager_employee_number INTEGER
, department_number INTEGER
, job_code INTEGER
, last_name CHAR(20) NOT NULL
, first_name VARCHAR(30) NOT NULL
, salary_amount DECIMAL(10,2) NOT NULL)
UNIQUE PRIMARY INDEX ( employee_number );
Example 1:
CREATE HASH INDEX hash_1
(employee_number, department_number) ON emp1
BY (employee_number)
ORDER BY HASH (employee_number);
33
Hash IndexExamples
Contd.
Each hash index row contains the employee number, the
department number.
Specifying the employee number is unnecessary, since it is the
primary index of the base table and will therefore be
automatically included.
The BY clause indicates that the rows of this index will be
distributed by the employee_number hash value.
The ORDER BY clause indicates that the index rows will be
ordered on each AMP in sequence by the employee_number
hash value.
Example 2:
The same hash index definition could have been abbreviated as
follows:
CREATE HASH INDEX hash_1
(employee_number, department_number) ON emp1;
34
Questions
35
Welcome Break
36
37
Source
Teradata Forum
Release 13.10
Disclaimer: Parts of the content of this course is based on the materials available from the
Web sites and books listed above. The materials that can be accessed from linked sites are
not maintained by Cognizant Academy and we are not responsible for the contents thereof.
All trademarks, service marks, and trade names in this course are the marks of the
respective owner(s).
38
Teradata 13.0
You have successfully
completed Join Strategy