Senior
There is a long query, while it is running, another session updates and commits changes. Will the first query see the changes?
sobes.tech AI
Answer from AI
The question depends on the transaction isolation level and the database management system used. Usually, if the first query is executed within a transaction with the READ COMMITTED isolation level (the default level in most DBMS), it will see changes that have been committed by another session before the data is read.
If the first query has already started reading before another session commits, it will not see those changes within the current transaction.
Example:
- Session 1 starts a transaction and performs a long query.
- Session 2 updates data and commits.
- If session 1 reads the data again after session 2 commits, it will see the changes (with READ COMMITTED).
- If session 1 uses an isolation level of REPEATABLE READ or higher, it will not see changes made after its transaction started.
Thus, the answer depends on the transaction isolation settings and the timing of data reading.