Multisession Programming With Embedded SQL - Advanced SQL Engine - Teradata Database

SQL Stored Procedures and Embedded SQL

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
xqq1557098602407.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantage™

You can program an embedded SQL application to perform parallel request processing using more than one Teradata session. Such an application can transmit several requests simultaneously, one per each session.

A multisession application is more complicated to implement, debug, and maintain than a single session application, so before you implement multisession programming, you should determine whether multistatement requests on a single session satisfy your throughput and response time requirements.

If you decide the situation calls for multisession programming, then the preprocessor provides facilities to implement multisession applications.

How Multiple Sessions Work

USE this statement … TO …
CONNECT or LOGON with an AS session_id clause uniquely name each of the Teradata sessions. This action differentiates the multiple sessions.

When more than one session is to be used, the application must name each one explicitly.

SET CONNECTION switch between each of the named sessions using the unique session identifier specified in the CONNECT or LOGON statements.
LOGOFF session_id disconnect an application from a specific named session.
LOGOFF ALL disconnect an application from all sessions.

How Asynchronous Requests Work

WHEN you … THEN the session …
add an ASYNC clause to the executable SQL request initiates a uniquely named request.

The session returns control to the application without waiting for the completion of the asynchronous request.

use the WAIT statement waits for the completion of ANY, ALL, or a list of asynchronous requests.
use the TEST statement tests for the completion of the asynchronous request and returns the results of the request after it has completed.

ASYNC Statement Modifier

Each asynchronous request can be identified to the preprocessor by using the unique asynchronous request identifier specified in the ASYNC statement modifier preceding the executable SQL request.

When the ASYNC modifier is added to the executable SQL request, the request is initiated on the current session and returns control back to the application without waiting for the completion of the asynchronous request.

WAIT Statement

An application program can have requests pending on several sessions simultaneously.

Use the WAIT statement to wait for the completion of ANY, ALL, or a list of asynchronous requests, as described below:
  • An application can call an asynchronous wait using the WAIT ANY syntax.

    The wait ends when any outstanding asynchronous request completes, and returns the session identifier and the asynchronous request identifier.

  • An application can wait for all asynchronous requests to complete using the WAIT ALL syntax.

    The wait ends when all outstanding asynchronous requests complete.

  • An application can call a synchronous wait using the WAIT asynchronous_request_id_list syntax, specifying the asynchronous request identifier of any active asynchronous requests.

    The wait ends when all specified requests complete.

TEST Statement

The TEST statement tests for the completion of an asynchronous request. Once an asynchronous request has completed, TEST is used to retrieve the status of the execution of the asynchronous request.

TEST can also be used to asynchronously test whether an outstanding asynchronous request has completed without having to wait for the request to complete. If the request has not completed, TEST returns an SQL ‘not yet complete’ message.

TEST can be executed only once against the asynchronous request, and only after the request has completed.

SET CONNECTION Statement

The SET CONNECTION statement permits an application to switch among multiple sessions.

Status Variables and Data Structures for Embedded SQL Applications

Embedded SQL applications use several standardized status variables and data structures to communicate between the application and the Teradata Database.

The following standard host variables that receive completion and exception status codes are described in Result Code Variables:
  • SQLSTATE
  • SQLCODE

    The activity count, an enumeration of the number of rows returned by a query, is also useful for many applications. The activity count is reported in the third word in the SQLERRD array for embedded SQL applications and in the status variable declared as ACTIVITY_CODE for stored procedures.

Related Topics

For more information about: