是否在INSERT / UPDATE查询中存在多个MySQL子查询?
技术问答
312 人阅读
|
0 人回复
|
2023-09-12
|
我打算写以下查询:0 L9 Y# x. x8 p* Z3 ~5 J; l
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表吗?* F% l: _9 i7 ~; t% P& V- H( n
MySQL在某些情况下(如果在这个时间范围内添加新的操作),是否有可能执行两个子查询顺序?total_points和count_operations不一致?
; @8 J4 M* j" a. o0 Y3 P - u0 G& ]) n' n. X! @
解决方案: |
|
|
|
|
|