Cursor Stability

download Cursor Stability

of 4

Transcript of Cursor Stability

  • 7/31/2019 Cursor Stability

    1/4

    The isolation level is used only within a transaction.

    The behavior of updates on locked data depends on the value of the LOCKTIMEOUT variable

    of DB2. If this variable is set to -1, then the update waits until the lock is released. If

    LOCKTIMEOUT is set to 0, the update fails immediately; and if it is set to a number greater than

    0, the update waits for the specified seconds before failing.

    An isolation level determines how data is locked or isolated from other processes while that data

    is being accessed.these can be specified in 4 ways-

    1)RR(Repeatable read)

    2)RS(Read stability)

    3)UR(uncommited read)

    4)cs(cursor stability)

    1. Cursor Stability : lock is retained when untill the cursor moves from one record in one page to the next

    record in another page. Provides WRITE Integrity.

    Isolation Level Type of Read Prevented

    Serializable Dirty Read, Nonrepeatable Read, Phantom Read

    Repeatable read or Cursor Stability Dirty Read, Nonrepeatable Read

    Read Committed Dirty Read

    Read Uncommitted None

  • 7/31/2019 Cursor Stability

    2/4

    Table 1. Summary of isolation levels

    Isolation Level Access to

    uncommitted

    data

    Nonrepeatable

    reads

    Phantom read

    phenomenon

    Repeatable Read (RR) Not possible Not possible Not possible

    Read Stability (RS) Not possible Not possible Possible

    Cursor Stability (CS) Not possible Possible Possible

    Uncommitted Read (UR) Possible Possible Possible

    Table 2. Guidelines for choosing an isolation level

    Application Type High data stability required High data stability not

    required

    Read-write transactions RS CS

    Read-only transactions RR or RS UR

    Cursor stability does not just apply to when you open a cursor. If there are multiple rows

    that DB2 needs to read to get the answer set, all those rows are in the internal cursor andDB2 needs to obtain a Share (read) lock on each row. Using cursor stability means that

    when doing a select, DB2 will only hold a Share lock on the row being read, and notmaintain that lock until the next commit (or other event that would cause all locks to be

    released). Maybe the same as Serializable, but I am not sure.__________________

    You can specify an isolation level for the following SQL statements:

    o SELECTo SELECT INTOo Searched DELETEo INSERTo Searched UPDATE

  • 7/31/2019 Cursor Stability

    3/4

    o DECLARE CURSOR

    Static SQL:

    If an isolation clause is specified in the statement, then the value of that clause is used.

    If no isolation clause is specifed in the statement, then the isolation level used is the one specifiedfor the package at the time when the package was bound to the database.

    Dynamic SQL:

    If an isolation clause is specified in the statement, then the value of that clause is used.

    If no isolation clause is specifed in the statement, and a SET CURRENT ISOLATION statementhas been issued within the current session, then the value of the CURRENT ISOLATION specialregister is used.

    If no isolation clause is specifed in the statement, and no SET CURRENT ISOLATION statement

    has been issued within the current session, then the isolation level used is the one specified for thepackage at the time when the package was bound to the database.

    Comparison of isolation levels

    NC UR CS RS RR

    Can the application see uncommitted changes

    made by other application processes?Yes Yes No No No

    Can the application update uncommitted changes

    made by other application processes?No No No No No

    Can the re-execution of a statement be affected by

    other application processes? See phenomenon P3

    (phantom) below.

    Yes Yes Yes Yes No

    Can updated rows be updated by other

    application processes?Yes No No No No

    Can updated rows be read by other application

    processes that are running at an isolation level

    other than UR and NC?

    Yes No No No No

    Can updated rows be read by other application

    processes that are running at the UR or NC

    isolation level?

    Yes Yes Yes Yes Yes

    Can accessed rows be updated by other Yes Yes Yes No No

    http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/db2/rbafzmst02.htm#ToC_53http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/db2/rbafzmst02.htm#ToC_53http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/db2/rbafzmst02.htm#ToC_53
  • 7/31/2019 Cursor Stability

    4/4

    NC UR CS RS RR

    application processes?

    For RS, accessed rows typically means rows

    selected. For RR, see the product-specific

    documentation. See phenomenon P2

    (nonrepeatable read) below.

    Can accessed rows be read by other application

    processes?Yes Yes Yes Yes Yes

    Can current row be updated or deleted by other

    application processes? See phenomenon P1 (dirty-

    read) below.

    See Note

    below

    See Note

    below

    See Note

    belowNo No

    Note:

    This depends on whether the cursor that is positioned on the current row is updatable:

    If the cursor is updatable, the current row cannot be updated or deleted by other application

    processes

    If the cursor is not updatable,

    o For UR or NC, the current row can be updated or deleted by other application processes.

    o For CS, the current row may be updatable in some circumstances.

    Examples of Phenomena:

    P1

    Dirty Read. Unit of work UW1 modifies a row. Unit of work UW2 reads that row before UW1

    performs a COMMIT. UW1 then performs a ROLLBACK. UW2 has read a nonexistent row.P2

    Nonrepeatable Read. Unit of work UW1 reads a row. Unit of work UW2 modifies that row and

    performs a COMMIT. UW1 then re-reads the row and obtains the modified data value.

    P3

    Phantom. Unit of work UW1 reads the set ofn rows that satisfies some search condition. Unit of

    work UW2 then INSERTs one or more rows that satisfies the search condition. UW1 then repeats

    the initial read with the same search condition and obtains the original rows plus the inserted

    rows.