The point is while reviewing SQL coded program first you need to look at these three points to avoid any performance issues later on. Why I am stressing this point is if your SQL shows more performance indirectly you can save server costs.
For every AVG, MIN, MAX, or SUM statement, make sure the SQL is coded to handle a null value. This will eliminate any -305 SQL abends.
Note: Handle Null values diligently
Order By statements
Just take a look you really need Order by statements. Check all Order By statements. Are they needed? Is there a supporting index for what is being ordered? Sometimes an Order By can be efficient if it matches an index.
Note: Make sure present only index columns in Order By
Check all Distinct statements. Can there definitely be duplicates? Can such a statement be coded with a Group By or rewritten as a correlated or non-correlated subquery?
In V9, the Distinct works just like the Group By statement in that DB2 will look for sort avoidance by checking for appropriate indexes.
Note: Avoid possible duplicate retrieval areas
- DB2 sql logic fetch multi rows using Cursor
- Mainframe : DB2 Built-in Functions
- SQL- Functions and Return Code +100