if I have a request:
INSERT INTO table (col1,col2,col3) VALUES ('col1_value_1', 'col2_value_1', 'col3_value_1'), ('col1_value_2', 'col2_value_2', 'col3_value_2'), ('col1_value_3', 'col2_value_3', 'col3_value_3');
Suppose I have a table where the last id value of PRIMARY_KEY AUTO_INCREMENT is 56 , then this insert request always creates 3 records with identifiers 57, 58, 59 . Is this operation an atom?
Or, if another query is written to the same table, can ids not always increase by 1?
Thank you for attention!
EDIT . Please read the following, because perhaps I was not so clear.
Of course AUTO_INCREMENT incremented by one safely, I know that.
Point:
Let's say I have the following table called table :
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | |____________________________________|
If I know, run a query:
INSERT INTO table (col1,col2) VALUES ('some val', 'some other val'), ('some val', 'some other val'), ('some val', 'some other val')
I will summarize the following table:
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | | 7 | "some val" | "some other val" | | 8 | "some val" | "some other val" | | 9 | "some val" | "some other val" | |____________________________________|
Nothing to say here. But if I and another guy run the same query at the same time, are these queries atomic ?, which means we will always end:
1)
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | | 7 | "some val" | "some other val" |<-- My 1st inserted record | 8 | "some val" | "some other val" |<-- My 2nd inserted record | 9 | "some val" | "some other val" |<-- My 3rd inserted record | 10 | "some val" | "some other val" |<-- Another guy 1st inserted record | 11 | "some val" | "some other val" |<-- Another guy 2nd inserted record | 12 | "some val" | "some other val" |<-- Another guy 3rd inserted record |____________________________________|
Or with:
2)
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | | 7 | "some val" | "some other val" |<-- Another guy 1st inserted record | 8 | "some val" | "some other val" |<-- Another guy 2nd inserted record | 9 | "some val" | "some other val" |<-- Another guy 3rd inserted record | 10 | "some val" | "some other val" |<-- My 1st inserted record | 11 | "some val" | "some other val" |<-- My 2nd inserted record | 12 | "some val" | "some other val" |<-- My 3rd inserted record |____________________________________|
Depending on which query of the two MySQL charts first.
Or can the following anomalies occur ?:
3)
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | | 7 | "some val" | "some other val" |<-- My 1st inserted record | 8 | "some val" | "some other val" |<-- My 2nd inserted record | 9 | "some val" | "some other val" |<-- Another guy 1st inserted record - WTF??? | 10 | "some val" | "some other val" |<-- My 3rd inserted record | 11 | "some val" | "some other val" |<-- Another guy 2nd inserted record | 12 | "some val" | "some other val" |<-- Another guy 3rd inserted record |____________________________________|
Or something like this:
4)
___________________________________ | id | col1 | col2 | ------------------------------------- | 1 | "some val" | "some other val" | | 2 | "some val" | "some other val" | | 3 | "some val" | "some other val" | | 4 | "some val" | "some other val" | | 5 | "some val" | "some other val" | | 6 | "some val" | "some other val" | | 7 | "some val" | "some other val" |<-- Another guy 1st inserted record | 8 | "some val" | "some other val" |<-- My 1st inserted record - WTF??? | 9 | "some val" | "some other val" |<-- Another guy 2nd inserted record | 10 | "some val" | "some other val" |<-- My 2nd inserted record - WTF^2??? | 11 | "some val" | "some other val" |<-- Another guy 3rd inserted record | 12 | "some val" | "some other val" |<-- My 3rd inserted record - WTF^3??? |____________________________________|
Or any other combination! = 3) and 4) ?
I consider 1) and 2) as atomic. Is it always guaranteed that I always end 1) or 2) and never ever 3) or 4) or any other combination? And if so (I will always have 1) or 2) ), for both MyISAM and InnoDB ?
If I do SELECT LAST_INSERT_ID(); and for example, I get 7 , does this automatically mean that lines with id 8 and 9 were also inserted by my request , and not by the request of another guy?