In MYSQL if a conditional insert is performed with autocommit ON, ie.
set autocommit true;
insert into blah (x,y,z) values (1,2,3) where not exists (.....);
Would the above statement be executed atomically and committed at the same time? Or is it possible that there can be a delay between executing the insert and doing the commit?
EDIT: Updated the insert statement to reflect more accurate query:
set autocommit true;
insert into foo (x,y,z) select 1,2,3 from dual where not exists (select 1 from bar where a = 1);
I want to insert only if a row in another table does not exist. What I want to confirm is that in the below scenario there will be a failure:
SESSION1: insert into foo ..... where not exists (select 1 from bar where a = 1);
SESSION2: insert into bar (a) values (1);
SESSION2: commit;
SESSION1: commit; // should fail here.