19.06.2013 Views

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

application has decidedly higher Class 1 CPU and elapsed times as reported in <strong>DB2</strong><br />

Per<strong>for</strong>mance Expert.<br />

Static read cursors<br />

By manipulating the number of fetches from 50k to 10, but keeping the result set size the<br />

same (1 million rows) you can see that the per<strong>for</strong>mance does not improve significantly (just<br />

over 4% improvement). This is because the overhead <strong>for</strong> opening and <strong>for</strong>matting the<br />

temporary table (class 3 suspend time) is essentially the same <strong>for</strong> both cases (4.29 vs. 4.40)<br />

and populating it with 1 million rows to build the result set in both cases consumes the<br />

majority of CPU cycles.<br />

However, in the third case, you can see a dramatic reduction of class 2 elapsed and CPU time<br />

when the qualified rows are changed from 1 million to 100k. In the static cursor case there are<br />

data movement I/Os from the base table to the temporary table, so in this case class 2<br />

elapsed and CPU time are dependent on the size of the temporary table to populate. Class 3<br />

time also decreases as the temporary table size decreases.<br />

As a conclusion, per<strong>for</strong>mance improvement <strong>for</strong> static scrollable cursors can be achieved, to a<br />

certain extent, by writing SQL statements that limit the result set read into the temporary table<br />

to only those rows that are essential.<br />

Dynamic read cursors<br />

See Table 3-4 again <strong>for</strong> the result trace record of the dynamic cursor case. Response times in<br />

all three cases are dramatically improved when compared against the static cursor. The<br />

elimination of <strong>for</strong>matting and building a result set into a temporary table when using the<br />

dynamic cursor model accounts <strong>for</strong> this dramatic per<strong>for</strong>mance improvement. Thus, comparing<br />

the static vs. dynamic cursor models, the <strong>DB2</strong> class 2 elapsed times are:<br />

► Fetch 50k / Result Set 1 M – 17.21 vs. 0.849 <strong>for</strong> 95% per<strong>for</strong>mance improvement<br />

► Fetch 10 / Result Set 1 M – 16.75 vs. 0.069 <strong>for</strong> 99% per<strong>for</strong>mance improvement<br />

► Fetch 50k / Result Set 100k – 5.61 vs. 0.849 <strong>for</strong> 85% per<strong>for</strong>mance improvement<br />

The important thing here is that the amount of FETCHes becomes the deciding factor <strong>for</strong> the<br />

dynamic cursor’s per<strong>for</strong>mance, whereas the number of qualifying rows was a deciding factor<br />

in the static cursor model. When the number of FETCHes is changed from 50k to 10, the CPU<br />

time is reduced from 0.849 to 0.069 <strong>for</strong> a 92% improvement. But the difference is not as large<br />

as in the case of static cursor, when the number of qualified rows is changed.<br />

Test scenario 2: Update cursor - Static vs. dynamic<br />

This case tests positioned updates and deletes. The intent is to compare sensitive cursors <strong>for</strong><br />

static and dynamic.<br />

As the sample program shows in Example 3-16, a static scrollable cursor is declared as<br />

SENSITIVE STATIC and specified as FOR UPDATE. It means that the cursor works as a<br />

cursor <strong>for</strong> a query to be used in positioned updates of the table. FETCH SENSITIVE is used<br />

in the program, so in each FETCH, <strong>DB2</strong> re-references the base table to pick up any<br />

committed updates or deletes.<br />

Example 3-16 Update program of static cursor<br />

DECLARE C1 SENSITIVE STATIC SCROLL CURSOR WITH HOLD<br />

FOR SELECT<br />

COL1, COL2, COL3, COL4,<br />

COL5,COL6 FROM TABLE<br />

WHERE COL2 < ‘ROWNNNNNNNNN’<br />

FOR UPDATE OF COL6;<br />

100 <strong>DB2</strong> <strong>UDB</strong> <strong>for</strong> z/<strong>OS</strong> <strong>Version</strong> 8 Per<strong>for</strong>mance <strong>Topics</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!