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.

Specification<br />

on DECLARE<br />

Specification<br />

on FETCH<br />

Type of<br />

Cursor<br />

Comments<br />

Sensitive Sensitive Updatable Aware of own updates and deletes within the<br />

cursor.<br />

Changes by another agent are visible to the<br />

cursor after commit.<br />

Any inserts are not recognized.<br />

<strong>DB2</strong> uses the predefined TEMP database and<br />

segmented table space to create your DTT and<br />

move in the results at execution time.<br />

The following is the description of the DECLARE CURSOR and FETCH options which were<br />

introduced in V7. The DECLARE CURSOR statement specifies that the cursor is scrollable by<br />

the SCROLL keyword. If SCROLL is specified, then you need to specify either INSENSITIVE<br />

or SENSITIVE STATIC. Any inserts are not visible in static scrollable cursors in every option,<br />

because <strong>for</strong> static scrollable cursors, inserts are not considered cursor operations and the<br />

result table is considered fixed after open cursor.<br />

► If you specify INSENSITIVE in DECLARE CURSOR, the scrollable cursor is strictly<br />

read-only. In a FETCH statement you can only specify INSENSITIVE. FETCH<br />

INSENSITIVE retrieves the row from the result table. The cursor is not sensitive to<br />

updates, inserts, and deletes made to the base table. So the application cannot see the<br />

changes made through the cursor, using positioned update and delete, nor the changes<br />

made outside the cursor.<br />

► If you specify SENSITIVE in DECLARE CURSOR, the scrollable cursor is updatable. In a<br />

FETCH statement you can specify INSENSITIVE or SENSITIVE to determine whether or<br />

not changes to the rows outside the cursor can be seen by the FETCH.<br />

– INSENSITIVE in a FETCH statement<br />

Applications can see the changes they have made themselves, using positioned<br />

updates or deletes through the cursor. In this case <strong>DB2</strong> updates both the base table<br />

and result table. However, updates and deletes to the base table made outside of the<br />

cursor are not visible to the application. The reason is that a FETCH INSENSITIVE<br />

cursor only accesses the result table, so the changes to the base table made outside<br />

the cursor are not visible.<br />

– SENSITIVE in a FETCH statement<br />

Applications can see the committed updates and deletes made by other applications<br />

outside the cursor, as well as changes they have made themselves using positioned<br />

and searched updates and delete through the cursor. A FETCH SENSITIVE first<br />

refreshes the rows in the DTT to pick up any committed updates and deletes from the<br />

base table, while a FETCH INSENSITIVE just returns the appropriate row from the<br />

DTT.<br />

Optimistic locking<br />

The static cursor model introduces the concept of optimistic locking. A specification of<br />

Isolation Level Cursor Stability (CS) can be used with Lock Size Row such that locks are held<br />

<strong>for</strong> the minimum duration because locking is optimistic in that no positioned update or delete<br />

occurs (lock/unlock the row), and even if it does, a new lock is acquired to compare the values<br />

between the base table and temporary table. In short, optimistic locking holds locks <strong>for</strong> the<br />

minimum duration, thereby increasing concurrency <strong>for</strong> that table. In addition, <strong>for</strong> applications<br />

that compare by value, it frees these applications from coding the comparison by moving this<br />

logic to the DBMS <strong>for</strong> better per<strong>for</strong>mance and less application code.<br />

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

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

Saved successfully!

Ooh no, something went wrong!