日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 5.6 read-committed隔离级别下并发插入唯一索引导致死锁一例

發(fā)布時(shí)間:2025/3/17 数据库 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 5.6 read-committed隔离级别下并发插入唯一索引导致死锁一例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

今天,某個(gè)環(huán)境又發(fā)生了死鎖,如下:

*** (1) TRANSACTION:
TRANSACTION 735307073, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1184, 3 row lock(s), undo log entries 1
MySQL thread id 2754, OS thread handle 0x7f29cd89a700, query id 751744317 127.0.0.1 osm update
insert into tb_trd_secu_command(
machine_date, company_no, product_id,
product_code, product_name, unit_id, unit_code,
unit_name, asset_account, stock_account, command_operator,
command_executor, command_date, command_time, command_id,
batch_no, exchange_no, asset_type, stock_type,
stock_code, stock_name, currency_type, command_dir,
limit_price, command_qty, command_amt, order_qty,
cancel_qty, command_status, execution_status, execution_amt,
execution_qty, frozen_amt)
value(
v_machine_date, v_company_no, v_product_id,
v_product_code, v_product_name, v_unit_id, v_unit_code,
v_unit_name, v_asset_account, v_stock_account, v_command_operator,
v_command_executor, v_command_date, v_command_time, v_command_id,
v_batch_no, v_exchange_no, v_asset_type, v_stock_type,
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307073 lock_mode X locks gap before rec insert intention waiting
*** (2) TRANSACTION:
TRANSACTION 735307149, ACTIVE 0 sec inserting, thread declared inside InnoDB 1
mysql tables in use 1, locked 1
4 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 1
MySQL thread id 2744, OS thread handle 0x7f29cd8db700, query id 751750715 127.0.0.1 osm update
insert into tb_trd_secu_command(
machine_date, company_no, product_id,
product_code, product_name, unit_id, unit_code,
unit_name, asset_account, stock_account, command_operator,
command_executor, command_date, command_time, command_id,
batch_no, exchange_no, asset_type, stock_type,
stock_code, stock_name, currency_type, command_dir,
limit_price, command_qty, command_amt, order_qty,
cancel_qty, command_status, execution_status, execution_amt,
execution_qty, frozen_amt)
value(
v_machine_date, v_company_no, v_product_id,
v_product_code, v_product_name, v_unit_id, v_unit_code,
v_unit_name, v_asset_account, v_stock_account, v_command_operator,
v_command_executor, v_command_date, v_command_time, v_command_id,
v_batch_no, v_exchange_no, v_asset_type, v_stock_type,
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307149 lock mode S locks gap before rec
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 10538 page no 4 n bits 296 index `idx_tb_trd_secu_command_1` of table `db_trd`.`tb_trd_secu_command` trx id 735307149 lock_mode X locks gap before rec insert intention waiting
*** WE ROLL BACK TRANSACTION (2)

其中idx_tb_trd_secu_command_1是唯一索引。

看了下參數(shù),當(dāng)前隔離級(jí)別是read-committed,不過參數(shù)innodb_locks_unsafe_for_binlog是默認(rèn)值OFF。

又仔細(xì)看了下官方文檔,?innodb_locks_unsafe_for_binlog和read-committed一方面是一樣的,啟用后,可以使得InnoDB?gap鎖最小化,但是在兩種場(chǎng)景(外鍵約束和唯一索引)中,仍然不可避免的存在gap鎖。

不管事務(wù)管理級(jí)別如何設(shè)置,只要存在唯一性約束并且可能insert/delete/update同一key值的記錄,死鎖都將無法100%的避免,只能是概率降低。

總結(jié)

以上是生活随笔為你收集整理的mysql 5.6 read-committed隔离级别下并发插入唯一索引导致死锁一例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。