Sobes.tech
Senior

Task #3 What will be the result in Session #1? Connecting to the database with table t with the line INSERT INTO t(id,val) VALUES (3,'c'); COMMIT; Session #1 ------------------------ psql> BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; -- T1 ------------------------ Session #2 ------------------------ psql(T2)> UPDATE t SET val='c2' WHERE id=3; COMMIT; ------------------------ Session #1 ------------------------ psql(T1)> SELECT id,val FROM t WHERE id=3 ------------------------

sobes.tech AI

Answer from AI

In REPEATABLE READ isolation mode, transaction T1 sees a snapshot of the data at the start of the transaction and does not see changes made by other transactions after it began.

Scenario:

  • In Session #1 (T1), a transaction with REPEATABLE READ level begins.
  • In Session #2 (T2), a row with id=3 is updated and committed.
  • In Session #1, a SELECT is performed for id=3.

The SELECT result in T1 will be the same as the row was at the start of T1, i.e., val='c'. The update made in T2 after T1 started will not be visible in T1 until a commit or a new transaction.

Thus, in Session #1, the data will be:

id | val
---+-----
3  | c

This behavior ensures repeatable reads and prevents phantom reads and non-repeatable reads within a single transaction.