Vous êtes sur la page 1sur 12

http://teradata.uark.edu/research/mehta/query.html 1. Which of the following Teradata utilities have you used?

Fastload Multiload TPump BTEQ Import Ans : above all except tpump Can you provide an example of when you would use each one? Fastload : to load the data from flat file to a table\ Mload : daily update of staging target tables Bteq :for transformations Bteq import/tpump : it is used in my current project to reduce the no of fast loads.. so we used bteq import/tpump for files containing few thousands of records ..

What do you understand by the term SESSIONS?

2. The following data-load process is reported to be running extremely slowly. Given the table definition of the target table, and the SQL process itself, can you make some recommendations as to how to speed up the load process? TABLES DEFINITIONS CREATE TABLE mytable ( Sort_Code INTEGER NOT NULL, Account_Number INTEGER NOT NULL, Customer_Identifier DECIMAL(10,0), Product_Identifier SMALLINT NOT NULL, Telephone_Home DECIMAL(11,0), Telephone_Mobile DECIMAL(10,0), . . Balance DECIMAL(15,2) NOT NULL, Overdraft_Limit DECIMAL(5,0) ) PRIMARY INDEX (Sort_Code,Account_Number) INDEX (Customer_Identifier) INDEX (Product_Identifier) INDEX (Telephone_Home) INDEX (Telephone_Mobile) ; Collect stats on primary index columns; Not necessary of sec.indexes as we are directly inserting the data without any where clause or join conditions. We can use multiset instead of set table as set table will do a duplicate row check ,so this can be avoided if we use multiset table. SLOW PROCESS DELETE FROM mytable ALL; INSERT INTO mytable SELECT .. FROM source_table_1 ; INSERT INTO mytable SELECT .. FROM source_table_2 ;

3. Given the following tables and SQL process, write down the key steps of the query plan (i.e. the results of an EXPLAIN) that you would expect Teradata to produce for the query.
CREATE TABLE mytable_1 ( Customer_Identifier DECIMAL(10,0) NOT NULL, Customer_Name VARCHAR(50) NOT NULL, County_Code CHAR(3) NOT NULL, . . Customer_Type_Code CHAR(1) NOT NULL COMPRESS (N,O,P) ) UNIQUE PRIMARY INDEX (Customer_Identifier) ; Data Volume: 18 million rows CREATE TABLE mytable_2 ( Country_Code CHAR(3) NOT NULL, Country_Name VARCHAR(35) NOT NULL ) UNIQUE PRIMARY INDEX (Country_Code) ;

Data Volume: 220 rows

; Additionally, how would you ensure the query runs as expected?


Explain CREATE TABLE mytable_1 ( Customer_Identifier DECIMAL(10,0) NOT NULL, Customer_Name VARCHAR(50) NOT NULL, County_Code CHAR(3) NOT NULL, Customer_Type_Code CHAR(1) NOT NULL COMPRESS ('n','o','p') ) UNIQUE PRIMARY INDEX (Customer_Identifier); 1) First, we lock venkat.mytable_1 for exclusive use. 2) Next, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for read on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, and we lock a distinct DBC."pseudo table" for read on a RowHash for deadlock prevention. 3) We lock DBC.DBase for read on a RowHash, we lock DBC.Indexes for write on a RowHash, we lock DBC.TVFields for write on a RowHash, we lock DBC.TVM for write on a RowHash, we lock DBC.ArchiveLoggingObjsTbl for read on a RowHash, and we lock DBC.AccessRights for write on a RowHash. 4) We execute the following steps in parallel. 1) We do a single-AMP ABORT test from DBC.ArchiveLoggingObjsTbl by way of the primary index. 2) We do a single-AMP ABORT test from DBC.DBase by way of the

unique primary index. 3) We do a single-AMP ABORT test from DBC.TVM by way of the unique primary index. 4) We do an INSERT into DBC.Indexes (no lock required). 5) We do an INSERT into DBC.TVFields (no lock required). 6) We do an INSERT into DBC.TVFields (no lock required). 7) We do an INSERT into DBC.TVFields (no lock required). 8) We do an INSERT into DBC.TVFields (no lock required). 9) We do an INSERT into DBC.TVM (no lock required). 10) We INSERT default rights to DBC.AccessRights for venkat.mytable_1. 5) We create the table header. 6) Finally, we send out an END TRANSACTION step to all AMPs involved in processing the request. -> No rows are returned to the user as the result of statement 1.

Explain CREATE TABLE mytable_2 ( Country_Code CHAR(3) NOT NULL, Country_Name VARCHAR(35) NOT NULL ) UNIQUE PRIMARY INDEX (Country_Code) ; 1) First, we lock venkat.mytable_2 for exclusive use. 2) Next, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for write on a RowHash for deadlock prevention, we lock a distinct DBC."pseudo table" for read on a RowHash for deadlock prevention, and we lock a distinct DBC."pseudo table" for read on a RowHash for deadlock prevention. 3) We lock DBC.DBase for read on a RowHash, we lock DBC.Indexes for write on a RowHash, we lock DBC.TVFields for write on a RowHash, we lock DBC.TVM for write on a RowHash, we lock DBC.ArchiveLoggingObjsTbl for read on a RowHash, and we lock DBC.AccessRights for write on a RowHash. 4) We execute the following steps in parallel. 1) We do a single-AMP ABORT test from DBC.ArchiveLoggingObjsTbl by way of the primary index. 2) We do a single-AMP ABORT test from DBC.DBase by way of the unique primary index. 3) We do a single-AMP ABORT test from DBC.TVM by way of the unique primary index. 4) We do an INSERT into DBC.Indexes (no lock required). 5) We do an INSERT into DBC.TVFields (no lock required). 6) We do an INSERT into DBC.TVFields (no lock required). 7) We do an INSERT into DBC.TVM (no lock required). 8) We INSERT default rights to DBC.AccessRights for venkat.mytable_2. 5) We create the table header. 6) Finally, we send out an END TRANSACTION step to all AMPs involved in processing the request. -> No rows are returned to the user as the result of statement 1.

4. The following data-items are to be held in a Teradata table. Using any financial system knowledge you have, propose appropriate data-types for each of these, and also define any other column attributes that you believe would be appropriate. Justify your reasons for your answers. Can Contain NULLS (Y/N) Can Be Compressed (Y/N) Compress Values

Data-Item Credit-Debit-AccountCode Mortgage_Held_Indicator

Data-Type CHAR(6) CHAR(1)

Justification For Answer

Monthly_Debit_Count Monthly_Debit_Balance Account_Opened_Date

SMALLIN T DECIMAL (15,2) DATE

Account_Closed_Date DATE Customer_Surname Customer_Initials CHAR(1) VARCHA R(15)

5. Given the following data-definition and sample data, can you please write a piece of SQL that will determine the balance of an account at the end of January 2006 and the end of February 2006, and output the data in the following format: Account-Number ---------------------12345678 87654321 January-2006-Balance ----------------------------99.00 0.00 February-2006-Balance ------------------------------103.00 50.00

CREATE TABLE mytable_3 ( Account_Number INTEGER Balance_Amount DECIMAL(15,2) Balance_Start_Date DATE Balance_End_Date DATE ) PRIMARY INDEX (Account_Number); Sample-Data Account_ Number -----------12345678 12345678 12345678 12345678 Etc. Balance_ Amount -----------123.00 132.00 99.00 103.00 Balance_ Start_ Date ------------21-12-2005 18-01-2006 23-01-2006 20-02-2006

NOT NULL, NOT NULL, NOT NULL, NOT NULL

Balance_ End_ Date ------------17-01-2006 22-01-2006 19-02-2006 01-03-2006

6. Given the DDL below, and the following statements, choose what you believe to be the best Primary Index for the table, and state why you have chosen this. CREATE TABLE mytable_4 ( Customer_Identifier DECIMAL(10,0) Summary_Date DATE Product_Identifier SMALLINT Average_Credit_Balance DECIMAL(15,2) Average_Debit_Balance DECIMAL(15,2) Net_Interest_Revenue DECIMAL(9,2) ) ; The primary key of the table is Customer_Identifier, Summary_Date and Product_Identifier. Many queries that use this table will be looking to calculate the total balance and net-interest-revenue for each customer per month. Many users will look to use the data above with additional customer attributes from other customer tables that will be indexed on Customer-Identifier.

NOT NULL, NOT NULL, NOT NULL, NOT NULL, NOT NULL, NOT NULL

7. Using data from the tables below, write a piece of SQL that will work out for every account in the ACCOUNTS_TABLE the number of credit and debit transactions per account during September 2006. CREATE TABLE accounts_table ( Account_Number INTEGER NOT NULL, Sort_Code INTEGER NOT NULL, Summary_Date DATE NOT NULL, Average_Credit_Balance DECIMAL(15,2) NOT NULL, Average_Debit_Balance DECIMAL(15,2) NOT NULL ) PRIMARY INDEX (Account_Number,Sort_Code); Sample-data: Account Number --------12345678 23456789 34567890 Sort Code -----404775 404775 404775 Average Average Summary Credit Debit Date Balance Balance ---------------------------------2006-09-30 123.30 0.00 2006-09-30 0.00 -5.47 2006-09-30 20.00 0.00

CREATE TABLE credit_trans ( Account_Number INTEGER NOT NULL, Sort_Code INTEGER NOT NULL, Transaction_Date DATE NOT NULL, Transaction_Type BYTEINT NOT NULL, Transaction_Amount DECIMAL(9,2) NOT NULL ) PRIMARY INDEX (Account_Number,Sort_Code); Sample Data: Account Number --------12345678 12345678 Sort Code Transaction Transaction Transaction Date Type Amount -------------------- -------------- -------------404775 2006-09-16 C17 23.00 404775 2006-09-22 C19 1046.18

CREATE TABLE debit_trans ( Account_Number INTEGER NOT NULL, Sort_Code INTEGER NOT NULL, Transaction_Date DATE NOT NULL, Transaction_Type BYTEINT NOT NULL, Transaction_Amount DECIMAL(9,2) NOT NULL ) PRIMARY INDEX (Account_Number,Sort_Code); Sample Data: Account Number --------12345678 12345678 12345678 23456789 23456789 23456789 23456789 Sort Code Transaction Transaction Transaction Date Type Amount -------------------- -------------- -------------404775 2006-09-16 D06 -44.00 404775 2006-09-24 D22 -232.17 404775 2006-09-29 D23 -32.05 404775 2006-09-02 D06 -44.00 404775 2006-09-09 D22 -22.17 404775 2006-09-11 D23 -2.05 404775 2006-09-18 D23 -30.00

Output required: Account_ Number -----------12345678 23456789 34567890 Sort_ Code ------404775 404775 404775 Number_Credit_ Transactions --------------------2 0 0 Number_Debit_ Transactions -------------------3 4 0

8. Give some examples of when you have or would use: Volatile tables Global temporary tables Permanent tables

9. Given the following data definition: CREATE TABLE my_stats_table ( Customer_Identifier DECIMAL(10,0) NOT NULL, Branch_Identifier INTEGER NOT NULL, Total_VAPM_Value DECIMAL(9,2) NOT NULL ) UNIQUE PRIMARY INDEX (Customer_Identifier) ; Sample Data: Customer Identifier -----------1002 1004 1008 Branch Identifier -----------204505 204505 204511 Total_VAPM Value ----------------11.11 -65.14 123.45

Write a piece of SQL to split the customers into Total_VAPM_Value decile bands. Write a second piece of SQL to determine the top-10 customers, in Total_VAPM_Value terms, at each branch.

10. Users have been complaining about the negative performance impacts when using the following table the DDL is provided below: CREATE MULTISET TABLE mytable_5 ( Customer_Identifier DECIMAL(10,0) NOT NULL, Summary_Date DATE NOT NULL, Main_Sort_Code INTEGER NOT NULL, Main_Account_Number INTEGER NOT NULL, Barclays_Risk_Grade CHAR(2) NOT NULL, Customer_Name CHAR(100) NOT NULL, Date_Of_Birth DATE NOT NULL, Date_Became_Customer DATE NOT NULL, Relationship_Manager_Id INTEGER NOT NULL, Relationship_Manager_Name CHAR(100) NOT NULL, Relationship_Manager_Team CHAR(100) NOT NULL, Relationship_Manager_Area CHAR(100) NOT NULL, Relationship_Manager_Region CHAR(100) NOT NULL, ) UNIQUE PRIMARY INDEX (Customer_Identifier,Summary_Date) ; Here are some facts about the table: There are 10 million customer records per month. The table stores 36 months worth of data. Less than 2% of customers join the bank per month. Less than 1% of customers leave the bank per month. Less than 3% of customers details change on a regular basis. Users join this table to other customer-level tables.

Please make some recommendations about how the performance of queries against the table could be improved. What other considerations would need to be made?

Vous aimerez peut-être aussi