With a recent V6R1 PTF, SQL stored procedures can now benefit from the improved performance offered by IBM i service program objects.
The usage of SQL stored procedures by IBM i applications and programs continues to rise. For quite awhile, applications have had the ability to leverage the performance benefits offered by IBM i service program objects.
With a recent V6R1 PTF, SQL stored procedures can now benefit from the improved performance offered by IBM i service program objects. When an SQL stored procedure is created, DB2 for i generates and creates an ILE C program object to implement the business logic specified by the programmer. For example, when the following procedure is created, it will result in DB2 generating an ILE C program object (*PGM) named ADD_PGM in the QGPL library. Whenever an application invokes the ADD_PGM, DB2 will transparently call the generated C program object.
CREATE PROCEDURE QGPL/ADD_PGM (IN p1 INT, IN n INT, OUT o1 INT)
LANGUAGE SQL
BEGIN
DECLARE v1 INT;
SET v1=ABSVAL(n);
SET o1= p1+v1;
END;
With the V6R1 Database Group PTF #5 released in July 2008, programmers can now have DB2 generate ILE C service program objects instead. This capability is controlled with the new PROGRAM TYPE clause as shown in the following example. The PROGRAM TYPE SUB clause causes DB2 to generate an ILE C service program object (*SRVPGM) named ADD_SRVPGM in the QGPL library. If this clause is not specified, the default value is PROGRAM TYPE MAIN, which results in DB2 generating an ILE C program object.
CREATE PROCEDURE QGPL/ADD_SRVPGM (IN p1 INT, IN n INT, OUT o1 INT)
LANGUAGE SQL
PROGRAM TYPE SUB
BEGIN
DECLARE v1 INT;
SET v1=ABSVAL(n);
SET o1= p1+v1;
END;
The usage of a service program object will provide a small performance boost when the SQL stored procedure is called. No changes are needed to the applications that invoke the SQL stored procedure. The SQL stored procedure just needs to be re-created after the PROGRAM TYPE SUB clause is added.
You can find more information on the CREATE PROCEDURE statement syntax in the DB2 for i SQL Reference.
LATEST COMMENTS
MC Press Online