TechTip: Speed Up SQL Procedures with Service Program Support PDF Print E-mail
Tips & Techniques - SQL
Written by Kent Milligan   
Thursday, 07 August 2008 19:00

Support MC Press - Visit Our Sponsors

 

Forums Sponsor

 

 Popular Forums

POPULAR FORUMS

Forums

 

Search Sponsor
  
 

 Popular Searches

POPULAR SEARCHES

Search

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.


Kent Milligan
About the Author:

Kent Milligan is a senior DB2 consultant on the DB2 for i Center of Excellence team within the IBM Lab Services Power Systems Delivery Practice.  His primary responsibility is helping software developers use the latest DB2 technologies and port applications from other databases to DB2 for i. After graduating from the University of Iowa in 1989, Kent spent the first eight years of his IBM career as a member of the DB2 development team in Rochester. He speaks and writes regularly on various DB2 for i relational database topics.

Read More >>
Last Updated on Tuesday, 19 May 2009 10:35
 
User Rating: / 0
PoorBest 
   MC-STORE.COM