-
Notifications
You must be signed in to change notification settings - Fork 1.2k
master: document tidb_foreign_key_check_in_shared_lock
#21359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
you06
wants to merge
4
commits into
pingcap:master
Choose a base branch
from
you06:docs-shared-lock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -177,9 +177,11 @@ TiDB 支持是否开启外键约束检查,由系统变量 [`foreign_key_checks | |||||
|
|
||||||
| ## 锁 | ||||||
|
|
||||||
| 在 `INSERT` 或者 `UPDATE` 子表时,外键约束会检查父表中是否存在对应的外键值,并对父表中的该行数据上锁,避免该外键值被其他操作删除,导致破坏外键约束。这里的上锁行为等同于对父表中外键值所在行做 `SELECT FOR UPDATE` 操作。 | ||||||
| 在 `INSERT` 或者 `UPDATE` 子表时,外键约束会检查父表中是否存在对应的外键值,并对父表中的该行数据上锁,避免该外键值被其他操作删除,导致破坏外键约束。 | ||||||
|
|
||||||
| 因为 TiDB 目前暂不支持 `LOCK IN SHARE MODE`,所以,在并发写入子表场景,如果引用的外键值大部分都一样,可能会有比较严重的锁冲突。建议在大批量写入子表数据时,关闭 [`foreign_key_checks`](/system-variables.md#foreign_key_checks)。 | ||||||
| 默认情况下,外键检查对父表的上锁行为等同于对父表中外键值所在行做 `SELECT FOR UPDATE` 操作(即排他锁),在并发写入子表场景中,如果引用的外键值大部分都一样,可能会有比较严重的锁冲突。 | ||||||
|
|
||||||
| 你可以通过开启系统变量 [`tidb_foreign_key_check_in_shared_lock`](/system-variables.md#tidb_foreign_key_check_in_shared_lock-从-v856-和-v900-版本开始引入) 来让外键检查使用共享锁。共享锁允许多个事务同时持有同一行的锁,从而减少锁冲突,提升并发写入子表的性能。 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ## 外键的定义和元信息 | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2716,6 +2716,15 @@ v5.0 后,用户仍可以单独修改以上系统变量(会有废弃警告) | |||||
| > | ||||||
| > TiDB 从 v6.6.0 版本开始支持[使用资源管控 (Resource Control) 实现资源组限制和流控](/tidb-resource-control-ru-groups.md)功能。该功能可以将不同优先级的语句放在不同的资源组中执行,并为这些资源组分配不同的配额和优先级,可以达到更好的资源管控效果。在开启资源管控功能后,语句的调度主要受资源组的控制,`PRIORITY` 将不再生效。建议在支持资源管控的版本优先使用资源管控功能。 | ||||||
|
|
||||||
| ### `tidb_foreign_key_check_in_shared_lock` <span class="version-mark">从 v8.5.6 和 v9.0.0 版本开始引入</span> | ||||||
|
|
||||||
| - 作用域:SESSION | GLOBAL | ||||||
| - 是否持久化到集群:是 | ||||||
| - 是否受 Hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value) 控制:否 | ||||||
| - 类型:布尔型 | ||||||
| - 默认值:`OFF` | ||||||
| - 这个变量用于控制在悲观事务中,外键约束检查是否使用共享锁(而非排他锁)。开启后,外键检查对父表行加共享锁,允许多个并发事务同时检查同一父表行而不互相阻塞,从而提升并发写入子表的性能。 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ### `tidb_gc_concurrency` <span class="version-mark">从 v5.0 版本开始引入</span> | ||||||
|
|
||||||
| - 作用域:GLOBAL | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.