MySQL がストアド プロシージャ内でのテーブル ロックを許可しないのはなぜでしょうか。
ストアド プロシージャ内に次の SQL ステートメントがあります。
-- Total amount of money for comments
start transaction;
select @num_comments := count(*)
from `comment` c
where
c.user_id = user_id and
c.payment_rejection = 'NO' and
c.is_recorded = 0;
update `user` u set account_balance += u.comment_price * @num_comments where u.user_id = user_id;
update `comment` c set is_recorded = 1 where c.user_id = user_id and c.payment_rejection = 'NO' and c.is_recorded = 0;
commit;
comment
そのため、最初の SQL ステートメントで選択された行数が実際に更新された行数と異なる可能性があるため、テーブルへの書き込みを防ぐためにテーブルをロックする必要があります。