Database Transactions, Requests, and Statements | Teradata Vantage - Database Transactions - Analytics Database - Teradata Vantage

SQL Request and Transaction Processing

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
zfm1628111633230.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
evd1472255317510
lifecycle
latest
Product Category
Teradata Vantageā„¢

Processing in Vantage is transaction-based. The principal purpose of transaction management is to optimize concurrency: to maximize the number of sessions that can access the information in the database concurrently without compromising the consistency or integrity of the data.

Definition of a Database Transaction

A transaction is a sequence of n actions that are treated both as a unit of work and as a unit of recovery, though for the purposes of this discussion, a transaction is viewed primarily as a unit of work.
  • As a unit of work, a transaction defines a set of SQL operations to be performed on a database. All these operations must be performed or none can be performed. This is called the atomic property of transactions.
  • As a unit of recovery, a transaction defines a set of rollback operations to be performed on a database in order to change its state back to an earlier consistent state in the event that the transaction cannot successfully complete.

Beside its common definitions as a unit of work and a unit of recovery, a transaction can also be a unit of consistency, taking the database from one consistent state to another consistent state. In the course of a sequence of update operations, a database object may become transiently inconsistent while undergoing a change to a new consistent state. Transactions are devised to provide consistency in the face of potential transient inconsistency.

All transient inconsistencies may be isolated within the transaction and never seen by other users. In other words, any two operations that relate to the same database object must appear to run in a serial order. See Serializability Defined.

Definitions of Requests and Statements in Teradata SQL

Request is a Teradata-specific term used to describe a minimal unit of work that is transmitted from a client system to the database in a single message. Among the components of the message are the following.
  • Request-level API options
  • Zero or more SQL statements
  • Request-related metadata
  • Request-related data

ANSI SQL does not use the request concept and refers only to SQL statements, which do not define units of work.

Any SQL statement can be a single-statement request, but not every request is a single SQL statement.

The following topics describe the differences between statements and requests in the database in more detail.

Definitions of a Transaction in Teradata SQL

The definition of a transaction in Teradata SQL depends in part on session mode.

In Teradata session mode, a transaction can either be implicit or explicit. In ANSI session mode, there are only ANSI transactions.

Definition of an Implicit Transaction

Each request submitted in Teradata session mode is implicit unless preceded by a BEGIN TRANSACTION statement, in which case the transaction is explicit.

In Teradata session mode, because an implicit transaction is taken as a single request, the Optimizer can determine what kinds of locks are required by the entire transaction at the time the request is parsed. Before processing begins, the Optimizer can arrange any table locks in an ordered fashion to minimize deadlocks.

ANSI session mode does not have implicit transactions.

Definition of an Explicit Transaction

You can also define transactions explicitly in Teradata session mode by using the BEGIN TRANSACTION statement.

Teradata session mode explicit transactions are completed by one of the following:
  • An END TRANSACTION statement.
  • An ABORT or ROLLBACK statement.
  • A failure response for a request.
  • The session is logged off, which aborts the transaction.
  • The system restarts.

You cannot submit BEGIN TRANSACTION and END TRANSACTION statements in ANSI session mode. If you attempt to do so, the database aborts the request and returns an error or a failure response to the requestor.

Upon receiving a BEGIN TRANSACTION statement, the Parser immediately looks for an SQL statement keyword in the SQL text that follows. Keep this in mind when determining the placement of request modifiers such as EXPLAIN, LOCKING, NONTEMPORAL, and USING.

For example, if the first request in an explicit transaction is associated with a USING request modifier, that USING request modifier must precede, not follow, the BEGIN TRANSACTION request. In other words, the USING request modifier must be specified outside the BEGIN TRANSACTION boundary.

Definition of ANSI Transactions

In ANSI session mode, a transaction begins when a request is submitted and there is not an uncompleted transaction. ANSI mode transactions are completed by one of the following:
  • A COMMIT statement.
  • An ABORT or ROLLBACK statement.
  • A failure response for a request.
  • The session is logged off, which aborts the transaction.
  • The system restarts.

You cannot submit COMMIT requests in Teradata session mode. If you attempt to do so, the database aborts the request and returns an error to the requestor.

Locking for Explicit and ANSI Transactions

When multiple requests are submitted as an explicit or ANSI transaction, the requests are processed one at a time. This means that the Optimizer has no way of determining what locks are needed by the transaction as a whole.

Therefore, locks are placed as each request is received. Locks are held until one of the following events completes, depending on the session mode, but regardless of when the user receives the data. (For example, a spool may exist beyond the end of the transaction.)
  • The outermost END TRANSACTION statement in Teradata session mode.
  • Submission of a COMMIT or ROLLBACK statement in ANSI session mode.

    In ANSI session mode, transactions continue to run until explicitly committed or rolled back.

  • The system restarts.

Errors and Failures

The following table briefly describes the conditions under which the system rolls back a transaction.

Response Code Type Session Mode Action Taken
Error ANSI Rolls back the error-generating request only.

Does not release locks placed on behalf of the rolled back request.

Teradata Not applicable.

The system does not return error codes in Teradata session mode; a failure code is returned instead.

Failure ANSI Rolls back the entire transaction that contains the error-generating request.
Teradata
To make sure your transactions are handled as intended, code your applications with logic to handle situations that roll back only an error-generating request, rather than the transaction that includes it.

The system does not release any locks placed for a request that is rolled back because of an error-generating request. All such locks remain in effect until the transaction either commits or rolls back.

Errors do not complete ANSI session mode transactions, but failures do.

ACID Properties of Transactions

The general concept of transaction processing is encapsulated by their so-called ACID properties. ACID is an acronym for the following set of properties that characterize a transaction:
  • Atomicity
  • Consistency
  • Isolation
  • Durability

The specific meanings of these expressions in terms of transactions are defined in the following table.

Term Definition
Atomicity A transaction either occurs or does not. All SQL operations specified within the boundaries of a transaction must complete successfully and commit or all must fail and rollback.

ANSI transaction semantics do not necessarily satisfy this property.

Consistency A transaction transforms one consistent database state into another. Intermediate inconsistencies in the database are not permitted.
Isolation The operations of any transaction are concealed from all other transactions until that transaction commits. In practice, a transaction may not necessarily adhere to this property.

See Levels of Isolation Defined.

Durability After a commit is made, the new consistent state of the database survives even if the underlying system fails.

Durability is a synonym for persistence.

These four factors are not rectangular. Their degree of shared variance varies. Atomicity and Consistency are close to being subtle restatements of one another, and neither is possible without Isolation.

The importance of the ACID guarantees depends on whether a transaction is read-only or also performs write operations. For a read-only transaction, Atomicity and Durability are irrelevant, but Isolation remains critically important for the reasons this is true.

Transactions are not always atomic in ANSI session mode, because when a request within a transaction fails with an Error response, only that request, and not the entire transaction, is rolled back. The remaining requests in the transaction continue until the transaction commits or rolls back.

Using the Transient Journal to Roll Back Transactions

Because transactions can fail and must be rolled back to a previous state, a mechanism must exist for preserving the before-change row set of a transaction. The before-change row images for a transaction are saved in the Transient Journal.

When a transaction fails, the system rolls back its updates using the before-change copies of any rows touched by the failed transaction. The system does this by writing the appropriate Transient Journal before-change rows over the updated after-change rows.