Joined: 05 Jun 2009 Posts: 185 Location: Planet Earth
We are in the process of trying to reduce the run time of long running batch jobs. We used APA to profile the long running steps. The APA reports shows a high CPU and Wait time on FETCH statement of a dynamic cursor. The corresponding OPEN statement consumption is <10% of the total consumption of FETCH statement.
I am trying to understand the difference between the time spent on the OPEN and FETCH. Does this mean that the cursor was resolved faster (as the OPEN only took 10% of the time) ? Will this imply that implementing multi row fetch (which might reduce the total number of database calls) improve the performance of this fetch statements ? Or will I still have to go ahead with fine tuning the query to improve its access path ?
Please advice/guide me on which would be the best approach.
If the query involves an intermediate resultset, then it is resolved at OPEN . If not then each FETCH is taking CPU.
If all qualifying rows are being searched (and sorted) before the first row can be returned, it will be the OPEN that takes time.
If rows can be returned to the program as soon as DB2 finds them, then the FETCH will take the time.
Note that not all ORDER BY/GROUP BY cause an intermediate resultset, some/most are resolved by using the correct indexes.
Not using an order by or group by does not mean there will be no intermediate rseultset. it all depends on the accesspath.