stp02

Upload: anu-alagendran

Post on 10-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 STP02

    1/2

    Stored Procedure Architecture

    Figure 1 shows the processing flow of an SQL CALL statement in a DB2 data base. The flowsequence is as follows:

    1. A thread must be created for each application that needs DB2 services. If the application is local,

    the thread is created when the first SQL statement is executed. If the request comes from a remoteclient, the thread is created when the client application issues the SQL CONNECT statement. After thethread is created, SQL statements can be executed.

    2. When a client application issues an SQL CALL statement, the stored procedure name and the I/Oparameters are passed to DB2.

    3. When DB2 receives the SQL CALL statement, it searches in the SYSIBM.SYSPROCEDUREScatalog table for a row associated with the stored procedure name. From this table, DB2 obtains theload module associated with the stored procedure and related information.

    4. Stored procedures are executed in address spaces. For DB2 Version 4, only one address space isavailable, called the DB2-established address space. For DB2 Version 5, in addition to the DB2-

    established stored procedures address space, you can have several work load manager (WLM)established address spaces. For DB2-established or WLM-established address spaces you canspecify a number of task control blocks (TCBs) in this address space available for stored procedures.Each stored procedure is executed under one TCB. After searching the SYSIBM.SYSPROCEDUREStable, DB2 searches for an available TCB to be used by the stored procedure and notifies the storedprocedure address space to execute the stored procedure.

    5. When DB2 notifies the stored procedures address space to execute a stored procedure, the threadthat was created for the client application is reused for an execution. This has the followingimplications:

    CPU cost is low because DB2 does not create a new thread.

    Accounting is on behalf of the client application.

    For static SQL, the OWNER of the client program must have execute privilege on the storedprocedure package. For dynamic SQL issued by the stored procedure, security is checked againstthe user of the client program, unless the DYNAMICRULES(BIND) option was specified whenbinding the package for the stored procedure. No sign-on or connection processing is required.

    Any processing done by the stored procedure is considered a logical continuation of the clientapplication's unit of work. Thus, locks acquired by the stored procedure are released when theclient application commits or rolls back.

    6. The stored procedures address space uses the LE/370 product libraries to load and execute the

    stored procedure. Through the SYSIBM.SYSPROCEDURES, you can pass run-time information forLE/370 when the stored procedure is executed.

    7. Control is passed to the stored procedure along with the input and output parameters. The storedprocedure can issue most SQL statements. It also has access to non-DB2 resources.

    8. Before terminating, the stored procedure assigns values to the output parameters and returnscontrol to DB2.

    9. DB2 copies the output parameters received from the stored procedure to the client applicationparameter area and returns control to the client application.

    10. The calling program receives the output parameters and continues the same unit of work.

    11. The client application implicitly or explicitly issues the COMMIT statement. With DB2 Version 5, theclient application can implicitly commit as soon as the stored procedure returns control to the client

  • 8/8/2019 STP02

    2/2

    application. If the client application and the stored procedures used during this execution update atdifferent sites, the two-phase commit protocol is used.

    Figure 1. DB2 Stored Procedure Flow

    Although stored procedures are supported from DRDA remote clients, they are also supported locally.If a local application issues the SQL CALL statement, the distributed data facility (DDF) is not involvedand need not be started.