Module 3: Teradata Basics
After completing this module, you will be able to:
List and describe the major components of the Teradata
architecture.
Describe how the components interact to manage
incoming and outgoing data
List 5 types of Teradata database objects
Teradata Storage Architecture
Records From Client (in random sequence)
2
32
67
12
90
54
75
18
25
80
41
Notes:
Teradata
The Parsing Engine dispatches
request to insert a row.
Parsing
Engine(s)
The Message Passing Layer
insures that a row gets to the
appropriate AMP (Access Module
Processor).
Message Passing Layer
AMP 1
2
18
5
4
AMP 2
12
41
AMP 3
80
9
0
75
The AMP stores the row on its
associated (logical) disk.
AMP 4
3
2
67
2
5
An AMP manages a logical or
virtual disk which is mapped to
multiple physical disks in a disk
array.
Teradata Retrieval Architecture
Rows retrieved from table
2
32
67
12
90
54
75
18
25
80
41
Teradata
Notes:
The Parsing Engine dispatches a
request to retrieve one or more
rows.
Parsing
Engine(s)
The Message Passing Layer
insures that the appropriate
AMP(s) are activated.
Message Passing Layer
AMP 1
2
18
5
4
AMP 2
12
41
AMP 3
80
9
0
75
The AMP(s) locate and retrieve
desired row(s) in parallel access.
AMP 4
3
2
67
2
5
Message Passing Layer returns to
retrieved rows to PE.
The PE returns row(s) to
requesting client application.
Multiple Tables on Multiple AMPs
EMPLOYEE Table
DEPARTMENT Table
JOB Table
Notes:
Some rows from each table may
be found on each AMP.
Parsing Engine
Each AMP may have rows from
all tables.
Message Passing Layer
AMP #1
AMP #2
EMPLOYEE Rows
EMPLOYEE Rows
DEPARTMENT Rows DEPARTMENT Rows
JOB Rows
JOB Rows
AMP #3
EMPLOYEE Rows
DEPARTMENT Rows
JOB Rows
Ideally, each AMP will hold
roughly the same amount of
data.
AMP #4
EMPLOYEE Rows
DEPARTMENT Rows
JOB Rows
Linear Growth and Expandability
Parsing
Engine
Parsing
Engine
Parsing
Engine
SESSIO
Teradata is a linearly
NS
expandable RDBMS.
Components may be added as
AMP
requirements grow.
AMP
AMP
I
OCESS
R
P
L
E
L
PARAL
Linear scalability allows for
NG
Disk
increased workload without
decreased throughput.
Performance impact of adding
Disk
Disk
Notes:
components is shown below.
DATA
USERS
Same
Double
Same
Same
AMPs
Same
Double
Double
Double
DATA
Same
Same
Double
Same
Performance
Same
Same
Same
Double
Teradata Objects
There are eight types of objects which may be found in a Teradata database/user.
Tables rows and columns of data
Views predefined subsets of existing tables
Macros predefined, stored SQL statements
Triggers SQL statements associated with a table
Stored Procedures program stored within Teradata
Join and Hash Indexes separate index structures stored as objects within a database
Permanent Journals table used to store before and/or after images for recovery
DATABASE or USER
These objects are created,
maintained and deleted using
Structured Query Language (SQL).
Object definitions are stored in the
Data Dictionary / Directory (DD/D).
DD/D
DEFINITIONS OF
ALL DATABASE
OBJECTS
TABLE 1
TABLE 2
TABLE 3
VIEW 1
VIEW 2
VIEW 3
MACRO 1
MACRO 2
MACRO 3
TRIGGER 1
TRIGGER 2
TRIGGER 3
Stored Procedure 1
Stored Procedure 2
Stored Procedure 2
Join/Hash Index 1
Join/Hash Index 2
Join/Hash Index 3
Permanent Journal
These aren't directly accessed by users.
The Data Dictionary Directory (DD/D)
The DD/D ...
is an integrated set of system tables
contains definitions of and information about all objects in the system
is entirely maintained by the RDBMS
is data about the data or metadata
is distributed across all AMPs like all tables
may be queried by administrators or support staff
is accessed via Teradata supplied views
Examples of DD/D views:
DBC.Tables
- information about all tables
DBC.Users
- information about all users
DBC.AllRights
- information about access rights
DBC.AllSpace
- information about space utilization
Structured Query Language (SQL)
SQL is a query language for Relational Database Systems.
A fourth-generation language
A set-oriented language
A non-procedural language
(e.g, doesnt have IF, GO TO, DO, FOR NEXT, or PERFORM statements)
SQL consists of:
Data Definition Language (DDL)
Defines database structures (tables, users, views, macros, triggers, etc.)
CREATE
DROP
ALTER
Data Manipulation Language (DML)
Manipulates rows and data values
SELECT
INSERT
UPDATE
DELETE
Data Control Language (DCL)
Grants and revokes access rights
GRANT
REVOKE
Teradata SQL also includes Teradata Extensions to SQL
HELP
SHOW
EXPLAIN
CREATE MACRO
CREATE TABLE Example of DDL
CREATE TABLE
Employee
,FALLBACK
(employee_number
INTEGER NOT NULL
,manager_emp_number INTEGER
,dept_number
SMALLINT
,job_code
INTEGER COMPRESS
,last_name
CHAR(20) NOT NULL
,first_name
VARCHAR (20)
,hire_date
DATE
FORMAT 'YYYY-MM-DD'
,birth_date
DATE
FORMAT 'YYYY-MM-DD'
,salary_amount
DECIMAL (10,2)
)
UNIQUE PRIMARY INDEX (employee_number)
,INDEX (dept_number);
Other DDL Examples
CREATE INDEX (job_code) ON Employee ;
DROP INDEX (job_code) ON Employee ;
DROP TABLE Employee ;
Views
Views are pre-defined subsets of existing tables consisting of specified
columns and/or rows from the table(s).
A single table view:
is a window into an underlying table
allows users to read and update a subset of the underlying table
has no data of its own
EMPLOYEE (Table)
MANAGER
EMPLOYEE EMP
NUMBER
NUMBER
DEPT
NUMBER
JOB
CODE
PK
FK
FK
FK
1006
1008
1005
1004
1007
1003
1019
1019
0801
1003
1005
0801
301
301
403
401
403
401
312101
312102
431100
412101
432101
411100
LAST
NAME
Stein
Kanieski
Ryan
Johnson
Villegas
Trader
FIRST
NAME
HIRE
DATE
BIRTH
DATE
SALARY
AMOUNT
John
Carol
Loretta
Darlene
Arnando
James
861015
870201
861015
861015
870102
860731
631015
680517
650910
560423
470131
570619
3945000
3925000
4120000
4630000
5970000
4785000
Emp_403 (View)
EMP NO
1005
801
DEPT NO
403
403
LAST NAME
Villegas
Ryan
FIRST NAME
Arnando
Loretta
HIRE DATE
870102
861015
Multi-Table Views
A multi-table view allows users to access data from multiple tables as if it were in a single
table. Multi-table views are also called join views. Join views are used for reading only,
not updating.
EMPLOYEE (Table)
MANAGER
EMPLOYEE EMP
NUMBER
NUMBER
DEPT
NUMBER
JOB
CODE
PK
FK
FK
FK
1006
1008
1005
1004
1007
1003
1019
1019
0801
1003
1005
0801
301
301
403
401
403
401
312101
312102
431100
412101
432101
411100
LAST
NAME
Stein
Kanieski
Ryan
Johnson
Villegas
Trader
FIRST
NAME
HIRE
DATE
BIRTH
DATE
SALARY
AMOUNT
John
Carol
Loretta
Darlene
Arnando
James
861015
870201
861015
861015
870102
860731
631015
680517
650910
560423
470131
570619
3945000
3925000
4120000
4630000
5970000
4785000
DEPARTMENT (Table)
DEPT
NUMBER
DEPARTMENT
NAME
MANAGER
BUDGET EMP
AMOUNT NUMBER
PK
501
301
302
403
402
401
201
FK
marketing sales
research and development
product planning
education
software support
customer support
technical operations
80050000
46560000
22600000
93200000
30800000
98230000
29380000
1017
1019
1016
1005
1011
1003
1025
"Joined Together"
EmpDept (View)
LAST
DEPARTMENT
NAME
NAME
Stein
Kanieski
Ryan
Johnson
Villegas
Trader
research & development
research & development
education
customer support
education
customer support
SELECT Example of DML
The SELECT statement is used to retrieve data from tables.
Who was hired on October 15, 1986?
EMPLOYEE (partial listing)
MANAGER
EMPLOYEE EMP
NUMBER
NUMBER
DEPT
NUMBER
JOB
CODE
PK
FK
FK
FK
1006
1008
1005
1004
1007
1003
1019
1019
0801
1003
1005
0801
301
301
403
401
403
401
312101
312102
431100
412101
432101
411100
LAST
NAME
Stein
Kanieski
Ryan
Johnson
Villegas
Trader
FIRST
NAME
HIRE
DATE
BIRTH
DATE
SALARY
AMOUNT
John
Carol
Loretta
Darlene
Arnando
James
861015
870201
861015
861015
870102
860731
631015
680517
650910
560423
470131
570619
3945000
3925000
4120000
4630000
5970000
4785000
Result
SELECT Last_Name
,First_Name
FROM
Employee
WHERE Hire_Date = '1986-10-15'
;
LAST
NAME
Stein
Ryan
Johnson
FIRST
NAME
John
Loretta
Darlene
The JOIN Operation
A join operation is used when the SQL query requires information from multiple
tables.
Who works in Research and Development?
EMPLOYEE
MANAGER
EMPLOYEE EMP
NUMBER
NUMBER
DEPT
NUMBER
JOB
CODE
PK
FK
FK
FK
1006
1008
1005
1004
1007
1003
1019
1019
0801
1003
1005
0801
301
301
403
401
403
401
312101
312102
431100
412101
432101
411100
LAST
NAME
Stein
Kanieski
Ryan
Johnson
Villegas
Trader
FIRST
NAME
HIRE
DATE
BIRTH
DATE
SALARY
AMOUNT
John
Carol
Loretta
Darlene
Arnando
James
861015
870201
861015
861015
870102
860731
631015
680517
650910
560423
470131
570619
3945000
3925000
4120000
4630000
5970000
4785000
DEPARTMENT
DEPT
NUMBER
DEPARTMENT
NAME
MANAGER
BUDGET EMP
AMOUNT NUMBER
PK
501
301
302
403
402
401
201
FK
marketing sales
research and development
product planning
education
software support
customer support
technical operations
80050000
46560000
22600000
93200000
30800000
98230000
29380000
1017
1019
1016
1005
1011
1003
1025
Result
LAST
NAME
Stein
Kanieski
FIRST
NAME
John
Carol
Macros Teradata SQL Extension
A MACRO is a predefined set of SQL statements which is logically stored in a database.
Macros may be created for frequently occurring queries of sets of operations.
Macros have many features and benefits:
Simplify end-user access
Control which operations may be performed by users
May accept user-provided parameter values
Are stored on the RDBMS, thus available to all clients
Reduces query size, thus reduces LAN/channel traffic
Are optimized at execution time
May contain multiple SQL statements
To create a macro:
CREATE MACRO Customer_List AS (SELECT customer_name FROM Customer;);
To execute a macro:
EXEC Customer_List;
To replace a macro:
REPLACE MACRO Customer_List AS
(SELECT customer_name, customer_number FROM Customer;);
HELP Commands Teradata SQL Extension
Databases and Users:
HELP
DATABASE
Customer_Service ;
HELP
USER
Dave_Jones ;
Tables, Views, and Macros:
HELP
TABLE
Employee ;
HELP
VIEW
Emp;
HELP
MACRO
Payroll_3;
HELP
COLUMN
Employee.*;
Employee.last_name;
Emp.* ;
Emp.last;
HELP
INDEX
Employee;
HELP
STATISTICS
Employee;
HELP
CONSTRAINT Employee.over_21;
Example of HELP DATABASE
Command:
HELP DATABASE Customer_Service;
*** Help information returned. 15 rows.
*** Total elapsed time was 1 second.
Table/View/Macro name
Contact
Customer
Cust_Comp_Orders
Cust_Pend_Orders
Cust_Order_ix
Department
Employee
Employee_Phone
Job
Location
Location_Employee
Location_Phone
Orders
Set_Ansidate_on
Set_Integerdate_on
Kind
T
T
V
V
I
T
T
T
T
T
T
T
T
M
M
Comment
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
SHOW Command Teradata SQL Extension
SHOW commands display how an object was created.
Command
SHOW TABLE
SHOW VIEW
SHOW MACRO
SHOW TRIGGER
SHOW PROCEDURE
tablename;
viewname;
macroname;
triggername;
procedurename;
Returns statement
CREATE TABLE statement
CREATE VIEW ...
CREATE MACRO ...
CREATE TRIGGER
CREATE PROCEDURE
SHOW TABLE Employee;
CREATE SET TABLE CUSTOMER_SERVICE.Employee, FALLBACK,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
employee_number INTEGER,
manager_employee_number INTEGER,
department_number INTEGER,
job_code INTEGER,
:
salary_amount DECIMAL(10,2) NOT NULL)
UNIQUE PRIMARY INDEX ( employee_number );
EXPLAIN Facility Teradata SQL Extension
The EXPLAIN modifier in front of any SQL statement generates an English translation of
the Parsers plan.
The request is fully parsed and optimized, but not actually executed.
EXPLAIN returns:
Text showing how a statement will be processed (a plan)
An estimate of how many rows will be involved
A relative cost of the request (in units of time)
This information is useful for:
predicting row counts
predicting performance
testing queries before production
analyzing various approaches to a problem EXPLAIN
EXPLAIN SELECT last_name, department_number FROM Employee ;
Explanation (partial):
3) We do an all-AMPs RETRIEVE step from CUSTOMER_SERVICE.Employee by way of an all-rows
scan with no residual conditions into Spool 1, which is built locally on the AMPs. The size of
Spool 1 is estimated to be 24 rows. The estimated time for this step is 0.15 seconds.
Teradata Features Review
Designed for decision-support and tactical queries
Ideal for data warehouse applications
Parallelism makes possible access to very large tables
Performance increase is linear as components are added
Uses standard SQL
Runs as a database server to client applications
Runs on multiple hardware platforms
Open architecture uses industry standard components
Win 2000
Win XP
Teradata
DATABASE
UNIX
Client
Mainframe
Client
Review Questions
1. What language is used to access a Teradata table?
2. What are five Teradata database objects?
3. What are four major components of the Teradata architecture?
4. What are views?
5. What are macros?
Module 3: Review Question Answers
1. What language is used to access a Teradata table?
SQL
2. What are five Teradata database objects?
Tables, views, macros, triggers, and stored procedures
3. What are four major components of the Teradata architecture?
PE, AMPs, Vdisks, and Message Passing Layer
4. What are views?
- Subset of rows and columns or one or more tables
- Virtual tables
- Window into one or more tables
5. What are macros?
Predefined, stored set of SQL statements