Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do changes made within one transaction "see" each other?

Suppose I do the following set of SQL queries (pseudocode) in a table with only one column CITY:

BEGIN TRANSACTION;
INSERT INTO MyTable VALUES( 'COOLCITY' );
SELECT * FROM MyTable WHERE ALL;
COMMIT TRANSACTION;

is the SELECT guaranteed to return COOLCITY?

like image 206
sharptooth Avatar asked Mar 24 '11 08:03

sharptooth


1 Answers

Yes.

The INSERT operation would take an X lock out on at least the newly added row. This won't get released until the end of the transaction thus preventing a concurrent transaction from deleting or updating this row.

A transaction is not blocked by its own locks so the SELECT would return COOLCITY.

like image 108
Martin Smith Avatar answered Sep 29 '22 16:09

Martin Smith