Assume that I have set the isolation level to serializable and a transaction like this:
- A new transaction is opened.
- All tuples having a specific condition are retrieved.
- If no such row exists perform the next step, otherwise go to step 5.
- Set a flag in my codes (a non-database operation) that prevents new such tuples to be inserted into the database.
- The transaction is commited.
is executed. My question is that considering that what is done is steps 3 and 4 are not database operations and the last database operation performed (except commit) is in step 2, can I still be sure that the flag is set only if there aren't such tuples already in the table? In other words, is it possible that after step 3 is performed and the condition is satisfied and before step 4 is performed (which prevents adding new such tuples) another thread inserts one such tuple into the database and result in a set flag while one such tuple is in the database?