Concurrency management

Data consistency and concurrency concepts

  • Data Consistency applies to situations when readers want to access data currently being modified by writers.
  • Concurrent Data Access applies to situations when several writers are accessing the same data for modification.
  • Locking Granularity defines the amount of data concerned when a lock is set (for example, row, page, table).

Informix®

Informix uses a locking mechanism to handle data consistency and concurrency. When a process changes database information with UPDATE, INSERT or DELETE, an exclusive lock is set on the touched rows. The lock remains active until the end of the transaction. Statements performed outside a transaction are treated as a transaction containing a single operation and therefore release the locks immediately after execution. SELECT statements can set shared locks, depending on isolation level. In case of locking conflicts (for example, when two processes want to acquire an exclusive lock on the same row for modification, or when a writer is trying to modify data protected by a shared lock), the behavior of a process can be changed by setting the lock wait mode.

Control:

  • Lock wait mode: SET LOCK MODE TO ...
  • Isolation level: SET ISOLATION TO ...
  • Locking granularity: CREATE TABLE ... LOCK MODE {PAGE|ROW}
  • Explicit exclusive lock: SELECT ... FOR UPDATE

Defaults:

  • The default isolation level is READ COMMITTED.
  • The default lock wait mode is NOT WAIT.
  • The default locking granularity is PAGE.

SAP ASE

As in Informix, SAP® ASE uses locks to manage data consistency and concurrency. The database manager sets exclusive locks on the modified rows and shared locks when data is read, based on the isolation level. The locks are held until the end of the transaction. When multiple processes want to access the same data, the latest processes must wait until the first finishes its transaction or the lock timeout occurred. The lock granularity is at the row, page or table level. For more details, see SAP ASE's Documentation.

Control:

  • The lock wait mode can be controlled with: SET LOCK {WAIT seconds | NOWAIT}
  • Isolation level: Can be set with: SET TRANSACTION ISOLATION LEVEL = {0|1|2|3}
  • Locking granularity: Row, page or table level (controlled by locking schemes).
  • Explicit locking: SELECT ... FOR UPDATE

Defaults:

  • The default isolation level is Read Committed ( readers cannot see uncommitted data; no shared lock is set when reading data ).

Solution

The SET ISOLATION TO ... Informix syntax is replaced by SET TRANSACTION ISOLATION LEVEL ... in SAP ASE. The following table shows the isolation level mappings done by the SAP ASE database driver:

Table 1. Isolation level mappings done by the SAP ASE database driver
SET ISOLATION instruction in program Native SQL command
SET ISOLATION TO DIRTY READ SET TRANSACTION ISOLATION LEVEL = 0

SET ISOLATION TO COMMITTED READ [READ COMMITTED] [RETAIN UPDATE LOCKS]

SET TRANSACTION ISOLATION LEVEL = 1
SET ISOLATION TO CURSOR STABILITY SET TRANSACTION ISOLATION LEVEL = 2
SET ISOLATION TO REPEATABLE READ SET TRANSACTION ISOLATION LEVEL = 3

For portability, it is recommended that you work with Informix in the read committed isolation level, to make processes wait for each other (lock mode wait) and to create tables with the "lock mode row" option.

The SET LOCK MODE TO ... Informix syntax is replaced by SET LOCK ... in SAP ASE. If SET LOCK MODE TO WAIT is used in programs (i.e. wait forever), the driver will simulate this with a SET LOCK WAIT 5000 in SAP ASE:

Table 2. SET LOCK MODE instruction for SAP ASE
SET LOCK MODE instruction in program Native SQL command
SET LOCK MODE TO NOT WAIT SET LOCK NOWAIT
SET LOCK MODE TO WAIT n SET LOCK WAIT n
SET LOCK MODE TO WAIT SET LOCK WAIT 5000

See the Informix and SAP ASE documentation for more details about data consistency, concurrency and locking mechanisms.