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..

Kent Milligan
Kent Milligan is a Senior Db2 for i Consultant in the IBM Lab Services Power Systems Delivery Practice.  Kent has over 25 years of experience as a Db2 for IBM i consultant and developer working out of the IBM Rochester lab. Prior to re-joining the DB2 for i Lab Services practice in 2020, Kent spent 5 years working on healthcare solutions powered by IBM Watson technologies. Kent is a sought-after speaker and author on Db2 for i & SQL topics.
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: