As in does it take the table's current state and insert rows in it, or just straight up inserts the row into the table not caring about the state of the table?
I'm asking this because I'm not sure as to what happens when concurrent insert rows happen at the same time.
The scenario that is playing in my head is that each insert row takes the initial state of the table and inserts a row into the table, and because they happen at the same time, race condition occurs and the row that gets inserted last overwrites the insertion of the other row, and I don't want that to happen.
Is this a correct understanding of what happens?
For more context I'm using MySQL, and picture that the rows do not conflict with each other due to unique constraints or whatsoever, they are successful inserts.
For example: I have this empty table
CREATE TABLE IF NOT EXISTS test_table (
testOne INT,
testTwo VARCHAR(255),
PRIMARY KEY (testOne)
);
and these 2 insert statements happen at the same time,
INSERT IGNORE INTO test_table (testOne, testTwo)
VALUES (1, "two");
INSERT IGNORE INTO test_table (testOne, testTwo)
VALUES (2, "three");
will the table only have 1 row inserted? Since the initial state which each insert statement got the table was an empty one, and depending on which insert statement finishes last will overwrite the other insert statement, resulting in only 1 row inserted
I've tried opening up 4 terminals and just started inserting rows of data which don't conflict with each other into the same table at the same time. After that I got the number of rows inserted which is 9688, the data for each of the 4 terminals have the same number of rows of : 2422 so that means the race condition did not occur and all insertions were successful in this test. I tested it out 3 times and got the same result so I'm assuming the scenario that is playing in my head should be false, but you can never be too sure so I am seeking experienced advice on this because I'm not too familiar with SQL