我们长期使用以下选择查询。但是今天我们收到了很多数据库锁。
请帮助我如何解决由于选择查询而导致的锁定。
表大小非常小 300kb。
我们优化了表格,但没有运气
从下面查询信息和表结构。
Req-SQL:[select max(fullname) from prod_sets where name='view_v01' for update]
Req-Time: 5 sec
Blocker-SQL:[]
Blocker-Command:[Sleep]
Blocker-Time: 73 sec
Req-SQL:[select max(fullname) from prod_sets where name='view_v01' for update]
Req-Time: 22 sec
Blocker-SQL:[]
Blocker-Command:[Sleep]
Blocker-Time: 73 sec
CREATE TABLE `prod_sets` (
`modified` datetime DEFAULT NULL,
`create` datetime DEFAULT NULL,
`name` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`fullname` decimal(12,0) DEFAULT NULL,
UNIQUE KEY `idx_n` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
解释计划:
mysql> explain select max(fullname) from prod_sets where name='view_v01' for update;
+----+-------------+---------------+-------+---------------+----------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+-------+---------------+----------+---------+-------+------+-------+
| 1 | SIMPLE | prod_sets | const | idx_name | idx_name | 53 | const | 1 | |
+----+-------------+---------------+-------+---------------+----------+---------+-------+------+-------+
1 row in set (0.01 sec)