Transactional Systems
Transactional Systems
COURSE 4: Databases
Transactional systems
• All operations are finalized with success or none is saved in the db.
Statement 3
Statement 4
Statement 5
commit -- end transaction 2
• Database constraints
• PRIMARY KEY key constraint, UNIQUE, NOT NULL, FOREIGN KEY referential integrity,
CHECK
• Business constrains
active
failed aborted
failed aborted
Final statement
executed
active
failed aborted
Final statement
executed
Log → hardware failure →
→ System restart
→ recover updates Log
active DURABILITY
failed aborted
Successful
completion
active
failed aborted
active
Normal execution
cannot proceed
failed aborted
active
failure → recover initial state LOG
CONSISTENCY
Normal execution
cannot proceed
failed aborted
active
Rollbacked, initial
stat resolved
failed aborted
read (B)
B := B + temp
write (B)
commit
2. View serializability
2. View serializability
➢ Precedence graph — a direct graph where the vertices are the transactions (names).
➢ We draw an arc from Ti to Tj if the 2 transaction conflict, and Ti accessed the data item on which
the conflict arose earlier.
➢ If precedence graph is acyclic, the serializability order can be obtained by a topological sorting of
the graph.
➢ The problem of checking if a schedule is view serializable falls in the class of NP-complete
problems. Thus, existence of an efficient algorithm is extremely unlikely.
➢ Practical algorithms that just check some sufficient conditions for view serializability can still
be used.
update stock
set qte = :nS - 1
where n_prod = 100
if nS < 10
insert into restock(n_prod, qte)
values(100, 15)
T1 T2
select MAX(qte)
into :max
from orders
where n_prod =
100
phantom-read insert into orders(n_prod,qte)
anomaly values(100, 789455)
AVG > MAX! commit
select AVG(qte)
new lignes inserted into :avarage
from orders
where n_prod =
100
Databases C4: Transactional systems
T1 T2
select qte into :nS
Transactions errors from stock
where n_prod = 100
--nS = 13
update stock
set qte = :nS - 1
where n_prod = 100
select qte into :nS
from stock
where n_prod = 100
--nS = 12
dirty-write anomaly update stock
final stock 11! In the set qte = :nS - 1
first transaction, the where n_prod = 100
stock returns to 13. --nS = 11
Only one update
should decrease the abort
number of products. insert …
commit
READ
UNCOMMITTED
READ
COMMITTED
REPEATABLE
READ
SERIALIZABLE
REPEATABLE
READ
READ
COMMITTED
READ
UNCOMMITTED
• Locking
• Timestamp
• A transaction waits until all incompatible locks held by other transactions are released.
• https://oracle-base.com/articles/misc/deadlocks
• https://docs.oracle.com/cd/B19306_01/server.102/b14220/consist.htm
Databases C4: Transactional systems
Snapshot isolation
• Snapshot of the database at the beginning of each transaction.