If multiple DML statements are executed in one transaction, will Innodb execute them sequentially? Or will it be reordered?
update t_x ... where id = 1;
update t_x ... where id = 2;
update t_x ... where id = 3;
...
update t_x where id = n;
If multiple DML statements are executed in one transaction, will Innodb execute them sequentially? Or will it be reordered?
update t_x ... where id = 1;
update t_x ... where id = 2;
update t_x ... where id = 3;
...
update t_x where id = n;
SQL statements are executed sequentially. They are not reordered.
See this example:
mysql> create table mytable (i int);
mysql> begin;
mysql> insert into mytable values (10);
mysql> update mytable set i = i + 10;
mysql> update mytable set i = i * 10;
mysql> commit;
mysql> select * from mytable;
+------+
| i |
+------+
| 200 |
+------+
In this example, the order of statements is important to get a deterministic result. If the statements were reordered, the result might come back as 110 instead of 200.