16.10.2015 Views

Getting Started with DB2 Express-C

Create successful ePaper yourself

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

Chapter 13 – Concurrency and Locking 225<br />

Statement isolation level can be set using the WITH {isolation level} clause. For example:<br />

SELECT ... WITH {UR | CS | RS | RR}<br />

Example scenario:<br />

An application needs to get a "rough" count of how many rows are in a table. Performance<br />

is of utmost importance. Cursor stability isolation level is required <strong>with</strong> the exception of one<br />

SQL statement:<br />

SELECT COUNT(*) FROM tab1 WITH UR<br />

For embedded SQL, the level is set at bind time, for dynamic SQL, the level is set at run<br />

time.<br />

Choosing which isolation level to use depends on your application. If your application does<br />

not need exact counts as in the above example, choose UR isolation. If your application<br />

requires very tight control on the data it works <strong>with</strong>, choose RR isolation.<br />

To use currently committed semantics at bind time or prepare time, use this syntax:<br />

BIND:<br />

>--+-------------------------------------------------------------+--><br />

'--CONCURRENTACCESSRESOLUTION--+--USE CURRENTLY COMMITTED--+--'<br />

'--WAIT FOR OUTCOME---------'<br />

PREPARE:<br />

concurrent-access-resolution:<br />

|-+-USE CURRENTLY COMMITTED-+--------------------------|<br />

'-WAIT FOR OUTCOME--------'<br />

On a JDBC application using the IBM Data Server Driver for JDBC and SQLJ, you can use<br />

the concurrentAccessResolution property to enable currently committed.<br />

13.5 Lock escalation<br />

Every lock made by <strong>DB2</strong> consumes some memory. When the optimizer thinks it is better to<br />

have one lock on the entire table, rather than multiple row locks, lock escalation occurs.<br />

Figure 13.9 illustrates this.

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

Saved successfully!

Ooh no, something went wrong!