1. What is the difference between read skew and non-repeatable read?
We have two data - let x and y, and there is a relation between them.(e.g parent/child)
Transaction T1 reads x, and then a second transaction T2 updates x and y to new values and commits. If now T1 reads y, it may see an inconsistent state, and therefore produce an inconsistent state as output.
Acceptable consistent states:
x and y
*x and *y
Note: * denotes the updated value of the variable
When x and y are the same data, meaning to read them, need to execute the same query.
I guess, it leads to the problem of non-repeatable.
IMHO, even if we may call read skew is a generalization form of a non-repeatable problem.
2. Can read skew and non-repeatable read be both prevented by REPEATABLE READ or SERIALIZABLE?
Serializable isolation level permits transactions to run concurrently, it creates the effect that transactions are running in serial order: read skew/non-repeatable prevented
Repeatable read isolation level guarantees that each transaction will return the same row regardless of how many times executed.
From the definition, it seems read-skew may not be prevented.
Without knowing how it is implemented, it is hard to claim anything.
Today, DBMS engines use different approaches-concurrency control strategies to implement REPEATABLE Isolation level.
e.g Postgres use database snapshot(consistent view) to implement REPEATABLE READ Isolation level: it will prevent read skew
Other engines may use lock-based concurrency control mechanisms to implement it. - may not prevent read skew.