mysql是否从子查询原子插入?

时间:2015-11-25 11:19:21

标签: mysql concurrency atomic atomicity insert-select

如果我查询

insert into sometable b + 10 from select b from (select b from sometable order by id desc limit 1)

此操作是原子的吗?也就是说,插入到sometable中是否有可能更改b的值已经被查询,但是在插入完成之前,导致插入得到错误的值?

1 个答案:

答案 0 :(得分:-1)

我的猜测是不是。你可以锁定它以确保它不会改变:

INSERT INTO sometable (b)
SELECT b+10
FROM sometable
ORDER BY id DESC
LIMIT 1
LOCK IN SHARE MODE