innodb_locks_unsafe_for_binlog参数解析
2017-08-28 21:56
459 查看
前段时间我在研究mysql数据库锁,阅读了几天的mysql官方文档,对mysql的锁产生了浓厚的研究兴趣。我在之前做mysql中record lock导致dead lock的场景研究中,发现mysql不稳定,今天终于找到原因了。
Consider the following example, beginning with this table:
In this case, table has no indexes, so searches and index scans use the hidden clustered index for record locking (seeSection 14.8.2.1,
“Clustered and Secondary Indexes”).
Suppose that one client performs an
these statements:
Suppose also that a second client performs an
executing these statements following those of the first client:
As
it first acquires an exclusive lock for each row, and then determines whether to modify it. If
not modify the row and
enabled, it releases the lock. Otherwise,
the lock until the end of the transaction. This affects transaction processing as follows.
If
disabled, the first
x-locks and does not release any of them:
The second
as soon as it tries to acquire any locks (because the first update has retained locks on all rows), and does not proceed until the first
or rolls back:
If
enabled, the first
x-locks and releases those for rows that it does not modify:
For the second
a “semi-consistent” read,
returning the latest committed version of each row to MySQL so that MySQL can determine whether the row matches the
of the
Deprecated | 5.6.3 | |
Command-Line Format | --innodb-locks-unsafe-for-binlog | |
System Variable | Name | innodb_locks_unsafe_for_binlog |
Variable Scope | Global | |
Dynamic Variable | No | |
Permitted Values | Type | boolean |
Default | OFF |
CREATE TABLE t (a INT NOT NULL, b INT) ENGINE = InnoDB; INSERT INTO t VALUES (1,2),(2,3),(3,2),(4,3),(5,2); COMMIT;
In this case, table has no indexes, so searches and index scans use the hidden clustered index for record locking (seeSection 14.8.2.1,
“Clustered and Secondary Indexes”).
Suppose that one client performs an
UPDATEusing
these statements:
SET autocommit = 0; UPDATE t SET b = 5 WHERE b = 3;
Suppose also that a second client performs an
UPDATEby
executing these statements following those of the first client:
SET autocommit = 0; UPDATE t SET b = 4 WHERE b = 2;
As
InnoDBexecutes each
UPDATE,
it first acquires an exclusive lock for each row, and then determines whether to modify it. If
InnoDBdoes
not modify the row and
innodb_locks_unsafe_for_binlogis
enabled, it releases the lock. Otherwise,
InnoDBretains
the lock until the end of the transaction. This affects transaction processing as follows.
If
innodb_locks_unsafe_for_binlogis
disabled, the first
UPDATEacquires
x-locks and does not release any of them:
x-lock(1,2); retain x-lock x-lock(2,3); update(2,3) to (2,5); retain x-lock x-lock(3,2); retain x-lock x-lock(4,3); update(4,3) to (4,5); retain x-lock x-lock(5,2); retain x-lock
The second
UPDATEblocks
as soon as it tries to acquire any locks (because the first update has retained locks on all rows), and does not proceed until the first
UPDATEcommits
or rolls back:
x-lock(1,2); block and wait for first UPDATE to commit or roll back
If
innodb_locks_unsafe_for_binlogis
enabled, the first
UPDATEacquires
x-locks and releases those for rows that it does not modify:
x-lock(1,2); unlock(1,2) x-lock(2,3); update(2,3) to (2,5); retain x-lock x-lock(3,2); unlock(3,2) x-lock(4,3); update(4,3) to (4,5); retain x-lock x-lock(5,2); unlock(5,2)
For the second
UPDATE,
InnoDBdoes
a “semi-consistent” read,
returning the latest committed version of each row to MySQL so that MySQL can determine whether the row matches the
WHEREcondition
of the
UPDATE:
x-lock(1,2); update(1,2) to (1,4); retain x-lock x-lock(2,3); unlock(2,3) x-lock(3,2); update(3,2) to (3,4); retain x-lock x-lock(4,3); unlock(4,3) x-lock(5,2); update(5,2) to (5,4); retain x-lock
相关文章推荐
- innodb_locks_unsafe_for_binlog && transaction isolation level
- innodb_locks_unsafe_for_binlog
- innodb_locks_unsafe_for_binlog
- MySQL参数:innodb_flush_log_at_trx_commit 和 sync_binlog
- innodb_flush_log_at_trx_commit和sync_binlog 参数说明
- mysql之 binlog维护详细解析(开启、binlog相关参数作用、mysqlbinlog解读、binlog删除)
- innodb部分常用参数解析
- mysql之 binlog维护详细解析(开启、binlog相关参数作用、mysqlbinlog解读、binlog删除)
- 解析innodb status各项参数
- MYSQL:Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'
- innodb_flusn_log_at_trx_commit和rsync_binlog参数详解
- Jira的 Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'错误的解决 原创 2
- innodb_flush_method参数解析
- Jira的 Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'错误的解决
- Innodb Read IO 相关参数源代码解析
- mysql之sync_binlog和innodb_flush_log_at_trx_commit参数浅析
- [MySQL] 参数: innodb_flush_log_at_trx_commit和sync_binlog
- MySQL 重要参数 innodb_flush_log_at_trx_commit 和 sync_binlog
- MySQL HA架构下innodb_flush_log_at_trx_commit及sync_binlog参数
- 参数 sync_binlog、innodb_support_xa、innodb_flush_log_at_trx_commit