TechTip: Optimize Your SQL Procedures, Triggers, and Functions

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

When an SQL procedure, trigger, or function is created, DB2 UDB for iSeries generates a C program object with embedded SQL to implement the business logic described in the procedural SQL object. This C program implementation is transparent to the programmer because DB2 UDB takes care of the program creation and compilation.

Recently, a defect was discovered in V5R2 and V5R3 in which DB2 UDB for iSeries in certain cases was not using the optimization level parameter during compilation of the generated C program objects. Thus, these program objects could be missing out on compiler optimizations that could provide a small performance boost to SQL procedures, triggers, and functions.

To determine if any of your SQL procedural objects fall into this category, you can use the DSPPGM or DSPSRVPGM CL command to review the optimization level setting on the module-level detail screen. If the optimization level is set to *NONE, then your SQL procedural objects are affected by this defect.

There are two options available for remedying this situation. If you have the source code for the SQL procedure, trigger, or function, you can apply the following PTFs to your server.

  • V5R2 PTF 5722SS1 SI18369
  • V5R3 PTF 5722SS1 SI18358

After applying the PTFs, you can force the re-creations of the associated C program objects by dropping and re-creating your SQL procedure, trigger, or function.

If the source code is not available or you would prefer to change the optimization on an entire library of SQL procedural objects, then follow these steps to just change the optimization level.

1. Place this CL source in QGPL/QCLSRC.

CHGPGM:     PGM (&LIB)                   
            DCL &LIB TYPE(*CHAR) LEN(10)     
            QSYS/CHGPGM      PGM(&LIB/*ALL)  OPTIMIZE(40)  
            QSYS/CHGSRVPGM   SRVPGM(&LIB/*ALL)  OPTIMIZE(40) 
ENDCHGPGM:  ENDPGM            


2. Create the CL program.

CRTCLPGM QGPL/CHGPGM QGPL/QCLSRC


3. Invoke the CL program, passing the name of a library containing SQL procedure, trigger, or function.

CALL CHGPGM(‘MYPROCLIB’)


Kent Milligan is a DB2 UDB Technology Specialist on IBM's eServer Solutions Enablement team. He spent the first seven years at IBM as a member of the DB2 development team in Rochester. He can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$