Monday, December 15, 2014

Teradata - Tables


Teradata Architecture :

Teradata Architecture

The above diagram shows a very basic architecture of TERADATA and is very useful and easy for learning purpose. The first component is PE (Parsing Engine)
1) Session Control –> It checks for user authorization before processing any SQL queries. A PE can support up-to 120 sessions.
2) Parser –> It checks for the SQL syntax and user rights to access various database objects referred in the SQL query submitted by user.
3) Optimizer –> It create a plan or execution steps to follow in order to perform actions on database objects as per SQL query submitted by user.
4) Dispatcher –> It passes the execution steps to BYNET. Dispatcher also plays an important role by combining all the responses received and send it to user.
5.) Next component is BYNET. It is used for communication between PE’s and AMP’s (Access Module Processor). There are two BYNET’s available in any TERADATA environment: BYNET-0 & BYNET-1. Two BYNET’s allows for continuos sending and receiving messages between PE’s and AMP’s. 
6.) Next to BYNET, we have AMP’s. AMP’s can be considered as the worker in TERADATA Architecture. Each AMP has it’s own dedicated VDISK (Virtual DISK) to which it queries and process the steps planned by Optimizer. AMP’s work only on their own VDISK and do not have access to other AMP’s VDISK. Once the AMP perform the steps, it send back response to PE via BYNET where all the responses from various AMP’s is collected and sent back to user.

Copy table structure with data

Use the following SQL to copy table with data in Teradata: 
CREATE TABLE PROD_DB.D_PRODUCTS AS 
PROD_DB.D_PRODUCTS WITH DATA;


The same results can be achieved by issuing the following statements: 
CREATE TABLE PROD_DB.D_PRODUCTS AS PROD_DB.D_PRODUCTSWITH NO DATA;INSERT PROD_DB.D_PRODUCTS SELECT * FROM PROD_DB.D_PRODUCTS;
Note that the CREATE TABLE AS statement will not work if the source table has referential integrity constraints or any columns are defined as identity columns. 

COPY TABLE STRUCTURE

Run the following SQL in Teradata to copy table structure only without data


CREATE TABLE PROD_DB.D_PRODUCTS AS 
PROD_DB.D_PRODUCTS WITH NO DATA;
Or
CREATE TABLE PROD_DB.D_PRODUCTS AS(
    
SELECT * FROM PROD_DB.D_PRODUCTS)WITH NO DATA;






Teradata temporary tables

Teradata database provides various options in case of a need to use temporary tables. The temporary tables are especially useful when performing complicated calculations, they usually make multiple, complex SQL query simpler and increase overall SQL query performance.
Temporary tables are especially useful for reporting and performing operations on summarized values.

TERADATA TEMPORARY TABLE TYPES:

Derived temporary tables

  • Derived tables are local to an SQL query.
  • Not included in the DBC data dictionary database, the definition is kept in cache.
  • They are specified on a query level with an AS keyword in an sql statement

Volatile temporary tables

  • Local to a session ( deleted automatically when the session terminates)
  • Not included in the DBC data dictionary database and table definition is stored in cache. However, the volatile tables need to have unique names across the session.
  • Created by the CREATE VOLATILE TABLE sql statement

Global temporary tables


  • Global tables are local to a session and deleted automatically when the session terminates
  • A permanent table definition is stored in the DBC data dictionary database (DBC.Temptables)
  • Defined with the CREATE GLOBAL TEMPORARY TABLE sql



Sunday, December 14, 2014

Teradata Utilities - Basics


Comparison of the Teradata loading utilities

The article contains comparison and main features of the data loading tools provided by Teradata. The tutorial illustrates main features of Teradata Multiload , FastLoad and TPump (Parallel Data Pump) and provides sample real-life uses of those tools.

Scroll down for the sample scripts which illustrate different ways to load a sample fixed-length extract into a Teradata database using FastLoad, MultiLoad and Parallel Data Pump (TPump). 

Teradata Fast Load



  • Main use: to load empty tables at high speed.
  • The target tables must be empty in order to use FastLoad
  • Supports inserts only - it is not possible to perform updates or deletes in FastLoad
  • Although Fastload uses multiple sessions to load the data, only one target table can be processed at a time
  • Teradata Fastload does not support join indexes, foreign key references in target tables and tables with secondary index defined. It is necessary to drop any of the constraints listed before loading and recreate them afterwards.
  • The maximum number of concurrent Teradata Fastload tasks can be adjusted by a system administrator.
  • Fastload runs in two operating modes: Interactive and Batch
  • Duplicate rows will not be loaded

    Teradata Multi Load

  • Main use: Load, update and delete large tables in Teradata in a bulk mode
  • Efficient in loading very large tables
  • Multiple tables can be loaded at a time.
  • Updates data in a database in a block mode (one physical write can update multiple rows)
  • Uses table-level locks
  • Resource consumption: loading at the highest possible throughput
  • Duplicate rows allowed

    TERADATA PARALLEL DATA PUMP (TPUMP)

  • Main use: to load or update a small amount of target table rows
  • Sends data to a database as a statement which is much slower than using bulk mode
  • TPump uses row-level hash locks
  • Resource consumption: loading speed can be adjusted using a built-in resource consumption management utility. The throughput can be turned down in peak periods.
  • TPump does not support MULTI-SET tables.