資料庫名稱: Aurora mySQL
資料庫版本:
內容/問題描述:
我有一個表格 Schema
CREATE TABLE `credit` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`company_id` int(10) unsigned NOT NULL,
`agent_id` int(10) unsigned NOT NULL,
`balance_before` decimal(15,5) NOT NULL,
`amount` decimal(15,5) NOT NULL,
`balance_after` decimal(15,5) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `agent_amount` (`agent_id`,`amount`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
我在做交易的時候下了
SELECT * FROM credit Where agent_id = "{agent_id}" FOR UPDATE
UPDATE credit set amount = "amount" WHERE agent_id = "{agent_id}"
在高併發的情境下,很容易發生 DeadLock
請問如果我的索引是用複合索引,是否不會是行鎖而是表鎖
謝謝回覆