Transaction Processing in ANSI SQL

Outline

Dirty read phenomenon

  • A transaction reads uncommitted data created by a transaction that fails later on
      
        Transaction 1                 Transaction 2
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      2000
      UPDATE DEPARTMENT
      SET BUDGET = BUDGET + 1000
      WHERE NAME = 'Sales';              
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      3000
        ROLLBACK;                        
                                      ???
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Reading only committed data

    • 
        Transaction 1                 Transaction 2
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      2000
      UPDATE DEPARTMENT
      SET BUDGET = BUDGET + 1000
      WHERE NAME = 'Sales';              
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      2000
        ROLLBACK;                        
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Non-repeatable read phenomenon

  • A transaction reads the same data item few times and sometimes a data item has a different value
      
        Transaction 1                 Transaction 2
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      2000
      UPDATE DEPARTMENT
      SET BUDGET = BUDGET + 1000
      WHERE NAME = 'Sales';              
      COMMIT;                    
                                      SELECT budget
                                      FROM DEPARTMENT
                                      WHERE name = 'SALES';
                                      3000
                                      ???
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Phantom phenomenon

  • A transaction counts several times the total number of rows in the same table and sometimes the total number of rows is different
      
        Transaction 1                 Transaction 2
                                      SELECT count(*)
                                      FROM DEPARTMENT
                                      20
      DELETE DEPARTMENT
      WHERE NAME = 'Sales';              
      COMMIT;                    
                                      SELECT count(*)
                                      FROM DEPARTMENT
                                      19
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

No phantoms

    • 
        Transaction 1                 Transaction 2
                                      SELECT count(*)
                                      FROM DEPARTMENT
                                      20
      DELETE DEPARTMENT
      WHERE NAME = 'Sales';              
      COMMIT;                    
                                      SELECT count(*)
                                      FROM DEPARTMENT
                                      20
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Isolation levels

  • SQL provides four levels of isolation for database transactions
  • Isolation levels are equivalent to correctness levels
  • Isolation levels are defined in terms of several possible phenomena, or weird hard-to-explain occurrences of operations
  • The following isolation levels are defined in ANSI SQL
    • READ UNCOMMITTED
    • READ COMMITTED
    • REPEATABLE READ
    • SERIALIZABLE
  • Isolation levels are defined in the terms of so called phenomena
  • The following phenomena are considered
    • Dirty read phenomenon
    • Non-repeatable read phenomenon
    • Phantom phenomenon
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Phenomena

  • Dirty read phenomenon
    • Read operations may access dirty data, i.e. data written by uncommitted transactions
  • Non-repeatable read phenomenon
    • Different reads by a single transaction to the same data will not be repeatable, i.e. they may return different values
  • Phantom phenomenon
    • A set of rows that transaction reads once might be a different set of rows if the transaction attempts to read them again
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Isolation levels versus phenomena

  • At READ UNCOMMITED isolation level a transaction may exhibit:
    • dirty read phenomenon,
    • non-repeatable read phenomenon,
    • phantom phenomenon
  • At READ COMMITED isolation level a transaction may exhibit:
    • non-repeatable read phenomenon,
    • phantom phenomenon
  • At REPEATABLE READ isolation level a transaction may exhibit:
    • phantom phenomenon
  • At SERIALIZABLE isolation level a transaction may exhibit:
    • none of the phenomena
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Isolation levels versus phenomena

    • 	      
      Level               Dirty Read          Nonrepeatable Read          Phantom
      --------------------------------------------------------------------------------	      
      READ UNCOMMITTED    Possible            Possible                    Possible
      
      READ COMMITTED      not possible        Possible                    Possible
      
      REPEATABLE READ     not possible        not possible                Possible
      
      SERIALIZABLE        not possible        not possible                not possible
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

Transaction Processing in ANSI SQL

Outline

Setting isolation levels in ANSI SQL

    • SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
      SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
      SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
      SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

References

  • Elmasri R. and Navathe S. B., Fundamentals of Database Systems, Chapter 20.6 Transaction Support in SQL, 7th ed., The Pearson Education Ltd, 2017
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026