Rule Definition
While FOR UPDATE forces a certain access path, FOR FETCH ONLY provides more opportunities to the optimizer to choose the most efficient access path.
Remediation
Add one of the three clause : "FOR UPDATE" or "FOR READ ONLY" or FORFETCH ONLY". If you specify FOR FETCH ONLY, then DB2 does not need to know the current position of
your cursor on the base table, because you are not going to update qualifying rows.
Therefore, a more efficient access path for read-only cursors may be available to the optimizer. In order to get the benefit of lock avoidance, it is important to code cursors unambiguously.
This is especially true for dynamic SQL. Coding a cursor unambiguously means explicitly specifying either FOR FETCH ONLY for read-only cursors or FOR UPDATE for cursors whose data will be used to perform subsequent updates.
Violation Code Sample
DCL SYSPRINT FILE STREAM OUTPUT PRINT;
DCL FTEST1 FILE RECORD INPUT;
DCL FTEST2 FILE RECORD INPUT;
DCL FTEST3 FILE RECORD OUTPUT;
ON ENDF (FTEST1) EOF_FTEST1 = ON;
Fixed Code Sample
DCL SYSPRINT FILE STREAM OUTPUT PRINT;
DCL FTEST1 FILE RECORD INPUT;
DCL FTEST2 FILE RECORD INPUT;
DCL FTEST3 FILE RECORD OUTPUT;
ON ENDF (FTEST1) EOF_FTEST1 = ON;
ON ENDF (FTEST2) EOF_FTEST2 = ON;
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.