Improving SQL procedure performance
Abstract ..................................................................................................................................... 2
Introduction .............................................................................................................................. 2
SQL PL implementation methods ........................................................................................... 3
Pre-V5R4 implementation methods ....................................................................................................... 3
Expression Evaluator addition to V5R4 implementation methods ......................................................... 4
Expression Evaluator feedback and analysis .................................................................... 6
Measuring performance improvements ........................................................................... 10
Enabling Expression Evaluator ....................................................................................... 11
Tableless Query addition to IBM i 7.1 implementation methods .......................................................... 12
Tableless Query implementation details ......................................................................... 12
Tableless Query analysis ................................................................................................ 13
Performance tips for procedures, triggers and functions ................................................... 14
Avoid single-statement stored procedures ........................................................................................... 14
Utilize service program objects ............................................................................................................ 15
Minimize calls to other SQL stored procedures ................................................................................... 15
Move handlers for specific conditions and statements into nested compound statements ................. 15
Combine sequences of complex SET statements into one statement ................................................ 16
Avoid using temporary variables .......................................................................................................... 17
Use Integer data type instead of Character for simple flags ................................................................ 18
Use Integer data types instead of Decimal with zero scale ................................................................. 19
Utilize the Character data type over Variable-Length Character type ................................................. 20
Deconstruct complex IF statements ..................................................................................................... 21
Replace COALESCE functions invocations with IF statements........................................................... 22
Specify CCSID 65535 for character variables when using IBM i Access Client Solutions Runs SQL
Scripts................................................................................................................................................... 23
Recreate SQL procedural objects after a new release or Database Group PTF................................. 24
Summary ................................................................................................................................. 25
Appendix A: Expression Evaluator Performance Tests ...................................................... 26
Performance Benchmark Tests ............................................................................................................ 26
Scenario 1: Loop with assignments ................................................................................. 26
Scenario 2.a: Loop with conditions and assignments ..................................................... 28
Scenario 2.b: Loop with conditions and assignments ..................................................... 28
Scenario 3: Multiple stand-alone statements .................................................................. 31
Scenario 4: UDF implementation .................................................................................... 32
Appendix B: C code generation conditions .......................................................................... 34
Declarations and assignment statements ............................................................................................ 34
Comparison statements ....................................................................................................................... 36
Resources ............................................................................................................................... 38
About the Authors .................................................................................................................. 39
Acknowledgements ................................................................................................................ 39
Trademarks and special notices ........................................................................................... 40