MySQL のトランザクション 消化ステータス確認
KILLED のプロセスが transaction 掴んで焦った話。KILLED を消すためにmysqldを強制終了すると、dead lock が発生するのでやめたほうがいい。
以下のメッセージが出て追加deleteができなかった。。
transaction mysql Lock wait timeout exceeded; try restarting transaction
mysql> SHOW PROCESSLIST; 14654233 --> プロセス確認 mysql> SHOW ENGINE INNODB STATUS\G ---TRANSACTION 3747011, ACTIVE 1231 sec fetching rows, thread declared inside InnoDB 1887 mysql tables in use 1, locked 1 78241 lock struct(s), heap size 7594192, 6806394 row lock(s), undo log entries 6727648 MySQL thread id 14654233, OS thread handle 140280497481472, query id 478855377 localhost root updating delete from `goods` where modified_dt = '2018-10-01'
14654233 --> MySQL thread id(sql process id) select count(1) from `goods` where modified_dt = '2018-10-01'--> 10000000(delete 対象行) 6806394 --> lock rows(ロック行) 6727648 --> undo log entries(更新未完了行)
In [35]: 6806394 / 10000000 Out[35]: 0.6806394 (ロック完了割合) In [36]: 6727648 / 6806394 Out[36]: 0.9884305845356587 (delete 未完了割合)