是否在INSERT / UPDATE查询中存在多个MySQL子查询?
技术问答
229 人阅读
|
0 人回复
|
2023-09-12
|
我打算写以下查询:; G* U! {. ^, y& a
INSERT INTO summary (user_id,total_points,count_operations)SELECT 15 AS user_id, (SELECT SUM(points) FROM operations WHERE user_id = 15) AS total_points, (SELECT COUNT(*) FROM operations WHERE user_id = 15) AS count_operationsON DUPLICATE KEY UPDATEtotal_points = VALUES(total_points),count_operations = VALUES(count_operations);整个陈述是原子吗?也就是说,MySQL(带有MyISAM内部锁定引擎)operations表吗?9 F! A* c8 s+ m$ F: s
MySQL在某些情况下(如果在这个时间范围内添加新的操作),是否有可能执行两个子查询顺序?total_points和count_operations不一致?
% o. D" m- D" T; r# S ; }* d. n$ t" i& L( o: l
解决方案: |
|
|
|
|
|