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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

manage the number of qualifying rows and columns whenever possible. You should write<br />

SQL statements that limit the range of rows that are read into the temporary table.<br />

Although from a per<strong>for</strong>mance point of view dynamic scrollable cursors always outper<strong>for</strong>m the<br />

static cursor model, we do not recommend that the dynamic cursor model should always be<br />

used over the static cursor model. As mentioned previously, some customers appreciate the<br />

concept of optimistic locking (static cursor model only) since it contributes to concurrency.<br />

The static cursor model should be considered if you have a requirement <strong>for</strong> an application<br />

that must scroll back to a prior screen and retain and display the same values as be<strong>for</strong>e. Also,<br />

<strong>for</strong> gathering certain reports, such as average outstanding balance in a certain zip code,<br />

where the application programmer is not concerned about the minute-by-minute updates to<br />

the outstanding balance or the newly inserted or deleted accounts, the static cursor model<br />

with fetch insensitive can build these rows in a temporary table and permit the application to<br />

manipulate the rows as necessary, allowing concurrency to the base table.<br />

Besides per<strong>for</strong>mance, dynamic scrollable cursors are preferred when it is important <strong>for</strong> the<br />

application to see/access updated as well as newly inserted rows. Maximum concurrency can<br />

be achieved with isolation cursor stability.<br />

The summary of the recommendations <strong>for</strong> static and dynamic cursors is:<br />

► Static scrollable cursors can be the better solution if:<br />

– You need to scroll backwards to obtain initial values<br />

– You do not care about constant changes (such as business intelligence or<br />

representative samples).<br />

► Dynamic scrollable cursors can be preferable in situations where:<br />

– It is important <strong>for</strong> the application to access/see updated/inserted rows<br />

– Per<strong>for</strong>mance is important<br />

► Use multi-row operations whenever possible, particularly <strong>for</strong> the dynamic cursor model.<br />

3.13 Backward index scan<br />

With the enhancements introduced to support dynamic scrollable cursors, <strong>DB2</strong> also provides<br />

the capability <strong>for</strong> backward index scans. This allows <strong>DB2</strong> to avoid a sort and it can eliminate<br />

the need <strong>for</strong> an index. With this enhancement, available in CM, it is no longer necessary to<br />

create both an ascending and descending index on the same table columns.<br />

To be able to use the backward index scan, you must have an index on the same columns as<br />

the ORDER BY and the ordering must be exactly opposite of what is requested in the<br />

ORDER BY.<br />

For example, if you have created the index<br />

CREATE UNIQUE INDEX ON (A DESC, B ASC)<br />

then <strong>DB2</strong> V8 can do a <strong>for</strong>ward index scan <strong>for</strong> a<br />

SELECT ... FROM ... ORDER BY A DESC, B ASC<br />

and a backward index scan <strong>for</strong><br />

SELECT ... FROM ... ORDER BY A ASC, B DESC<br />

Chapter 3. SQL per<strong>for</strong>mance 107

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

Saved successfully!

Ooh no, something went wrong!