次のシナリオでトランザクション/ロックが本当に必要かどうか疑問に思っています。任意の数で同時に実行できる 3 つの操作を実行できます (つまり、2 つのタスク 1 を実行し、3 つのタスク 2 を実行できます)。
タスク1:
select distinct count(some_id) as my_counter from table_1;
update table_2 set counter = my_counter;
タスク 2:
insert into table_1 ...;
update table_2 set counter = counter + 1;
タスク 3:
delete from table_1 where id = ...;
update table_2 set counter = counter - 1;
table_2 のフィールドを決して破損しないことを確認するには、上記をどのように実装すればよいcounterですか?
どうもありがとうございました!