This topic presents case studies concerning Teradata session mode transaction semantics. Also see ANSI Session Mode Transaction Processing Case Studies).
Failed Teradata Session Mode Transaction Example
Request | Explanation |
---|---|
BTEQ -- Enter your DBC/SQL request or BTEQ command: BEGIN TRANSACTION; Result: *** Begin transaction accepted. |
Beginning of an explicit transaction. |
BTEQ -- Enter your DBC/SQL request or BTEQ command: INSERT INTO employee SELECT * FROM customer_service.employee; Result: *** Insert completed. 26 rows added. |
Single request. WRITE locks held. |
BTEQ -- Enter your DBC/SQL request or BTEQ command: SELECT * FRM employee WHERE empnum = 401; Result: *** Failure 3706 Syntax error; SELECT * must have a FROM clause. |
Invalid syntax is a failure. Transaction rolled back. All previous requests in the transaction are also rolled back. All locks released. |
BTEQ -- Enter your DBC/SQL request or BTEQ command: SELECT * FROM employee; Result: *** Query completed. No rows found. |
Single request. Implicit transaction. |
BTEQ -- Enter your DBC/SQL request or BTEQ command: END TRANSACTION; Result: *** Failure 3510 Too many END TRANSACTION statements. |
Request to end the transaction causes a failure response because the transaction begun with the BEGIN TRANSACTION request had already rolled back. |
Teradata Session Mode Requests
Request | Explanation |
---|---|
DELETE FROM table_1 WHERE PI_col=2; INSERT INTO table_1 VALUES (2,3,4); UPDATE table_1 SET col_3=4; |
These 3 statements are separate requests and implicit transactions. The implications of this are as follows:
|
BEGIN TRANSACTION; DELETE FROM table_1 WHERE PI_col=2; INSERT INTO table_1 VALUES (2,3,4); UPDATE table_1 SET col_3=4; END TRANSACTION; |
These 5 statements are separate requests within a single explicit transaction. The implications of this are as follows.
|
DELETE FROM table_1 WHERE PI_col=2 ;INSERT INTO table_1 VALUES (2,3,4) ;UPDATE table_1 SET col_3=4; |
These 3 statements form a single multistatement request and are implicitly a single transaction. The implications of this are as follows:
|
CREATE MACRO mac_1 AS ( DELETE FROM table_1 WHERE PI_col=2; INSERT INTO table_1 VALUES (2,3,4); UPDATE table_1 SET col_3=4; ); |
This macro contains 3 separate requests. The requests are contained within the same macro, and therefore behave identically to a multistatement request that contains the same three requests in the same order. |
EXEC mac_1; |
The result of executing the macro is atomic in exactly the same way its equivalent multistatement request is atomic. |
EXPLAIN EXEC mac_1 EXPLAIN DELETE FROM table_1 WHERE PI_col=2 ;INSERT INTO table_1 VALUES (2,3,4) ;UPDATE table_1 SET col_3=4; |
The EXPLAIN reports generated for these 2 requests are identical. |
Mixing DDL and DML Statements within a Multistatement Request
You cannot mix DDL and DML statements within the same macro or multistatement request in Teradata session mode. An attempt to perform such a request results in a failure response.
For example, the following multistatement request mixes DML (2 SELECT requests) with DDL (a CREATE TABLE request) and therefore, fails:
SELECT * FROM table_1 ;SELECT * FROM table_1 ;CREATE TABLE table_33 ( col_1 INTEGER);
Result:
*** Failure 3576 Data definition not valid unless solitary. Statement#1, Info =0
The equivalent macro text results in the same failure at the time that you attempt to create the macro.
CREATE MACRO mac_1 AS ( SELECT * FROM table_1; SELECT * FROM table_1; CREATE TABLE table_33 ( col_1 INTEGER); );
Result:
*** Failure 3576 Data definition not valid unless solitary. Statement#1, Info =0
A DDL statement within a Teradata session mode transaction must be the last action statement in the transaction. Otherwise, the transaction fails and all its work is rolled back. For example:
BEGIN TRANSACTION;
Result:
*** Begin transaction accepted. BTEQ -- Enter your DBC/SQL request or BTEQ command: CREATE TABLE table_19 ( col_1 INTEGER); *** Table has been created. BTEQ -- Enter your DBC/SQL request or BTEQ command: INSERT INTO table_3 VALUES (1); *** Failure 3932 Only an ET or null statement is legal after a DDL statement. BTEQ -- Enter your DBC/SQL request or BTEQ command: SHOW TABLE table_19; *** Failure 3807 Table/view/trigger/procedure ‘table_19’ does not exist.
Teradata Session Mode DELETE Performance for Different Transaction Structures
Depending on its structure, a transaction that contains a DELETE request can create a Transient Journal entry for each row deleted from a table or create only one Transient Journal entry for the entire transaction.
The following DELETE request is a single implicit transaction, which does not write a Transient Journal entry for each deleted row, and therefore its performance is good.
DELETE FROM table_1;
The following explicit transaction contains only BEGIN TRANSACTION and END TRANSACTION requests in addition to the DELETE request. Because of its structure, the transaction writes a Transient Journal entry for each deleted row and performs poorly, especially for large tables.
BEGIN TRANSACTION; DELETE FROM table_1; END TRANSACTION;
The following multistatement request contains the same three requests as the previous transaction, but the requests are packaged as a multistatement request and are therefore treated as an implicit transaction. Vantage does not write a Transient Journal entry for each row deleted from the table, and its performance is identical to that of the single-statement implicit transaction version.
BEGIN TRANSACTION ;DELETE FROM table_1 ;END TRANSACTION;
In the first case, the system knows what the next request is and prepares to roll back the transaction. In the second case, the system sees that the delete is to be committed.