私はこのテーブルを持っている:なぜこれらの2つのSQL文がデッドロック・エラーを引き起こしましたか?
CREATE TABLE `notify` (
`id` int(11) NOT NULL auto_increment,
`notify_type` char(1) NOT NULL,
`notify_id` int(10) unsigned NOT NULL,
`create_time` timestamp NOT NULL default '0000-00-00 00:00:00',
`user` int(10) unsigned NOT NULL,
`update_time` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `notify_id` (`notify_id`,`notify_type`,`user`),
KEY `Index_time` (`create_time`),
KEY `user_update` (`user`,`update_time`)
)
と2つのSQLクエリ連続して実行し、それはしばしば
OperationalError: (1213, 'Deadlock found when trying to get lock; try restarting transaction')
が生じ一緒
if user_id:
insert into notify (notify_type,notify_id,user,create_time)
values (%s,%s,%s,CURRENT_TIMESTAMP)
ON DUPLICATE KEY UPDATE update_time=update_time, (type, id, user_id)
update notify set update_time=NOW() where notify_type = %s
and notify_id =%s and user!=%s,(type, id, user_id)
else:
update reply_notify set update_time=NOW() where notify_type = %s
and notify_id =%s, (type, id)
commit()
を犯したが誰も私がなぜ把握助けることができるだろうそれは?私はMySQLのドキュメントを調べましたが、ON DUPLICATE KEY UPDATE
節に関連するものはないのですが、それでもわかりません。
他のコードがelseブランチに実行されている間に、それらの2つのトランザクションがデッドロックされていることがありますか?
"2つのSQL文" – Will
はいを投稿してください。私はテーブルの下に投稿しました – alexband
update_timeをupdate_timeカラムの既存の値に割り当てるので、 'ON DUPLICATE KEY'節は何もしません。これとは別に、なぜ1つのトランザクションで同じ行を更新する2つのクエリを送信しようとしていますか? –