-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update documents of lock view for sprint 4 #6824
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b6aea65
Update documents of lock view for sprint 4
MyonKeminta b9c20fb
Add notation about privilege requirements of the tables
MyonKeminta 753f5a9
fix lint
MyonKeminta 001d6a5
Fix the explaination about partition_handle fields
MyonKeminta adf310b
address comments
MyonKeminta f2cd34c
address comments
MyonKeminta a7c6bfa
update doc of deadlocks
MyonKeminta 46254ce
Try to avoid unnecessary English terms
MyonKeminta 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
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 |
---|---|---|
|
@@ -7,10 +7,6 @@ summary: 了解 information_schema 表 `DATA_LOCK_WAITS`。 | |
|
||
`DATA_LOCK_WAITS` 表展示了集群中所有 TiKV 节点上当前正在发生的悲观锁等锁的情况。 | ||
|
||
> **警告:** | ||
> | ||
> 该功能目前为实验性功能,表结构的定义和行为在未来版本中可能有较大改动。 | ||
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. 这张系统表在 v5.1 中仍为实验功能吗? |
||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
|
@@ -22,24 +18,55 @@ DESC data_lock_waits; | |
+------------------------+---------------------+------+------+---------+-------+ | ||
| Field | Type | Null | Key | Default | Extra | | ||
+------------------------+---------------------+------+------+---------+-------+ | ||
| KEY | varchar(64) | NO | | NULL | | | ||
| KEY | text | NO | | NULL | | | ||
| KEY_INFO | text | YES | | NULL | | | ||
| TRX_ID | bigint(21) unsigned | NO | | NULL | | | ||
| CURRENT_HOLDING_TRX_ID | bigint(21) unsigned | NO | | NULL | | | ||
| SQL_DIGEST | varchar(64) | YES | | NULL | | | ||
| SQL_DIGEST_TEXT | text | YES | | NULL | | | ||
+------------------------+---------------------+------+------+---------+-------+ | ||
``` | ||
|
||
`DATA_LOCK_WAITS` 表中各列的字段含义如下: | ||
|
||
* `KEY`:正在发生等锁的 KEY,以十六进制编码的形式显示。 | ||
* `KEY`:正在发生等锁的 key,以十六进制编码的形式显示。 | ||
* `KEY_INFO`:对 `KEY` 进行解读得出的一些详细信息,见 [KEY_INFO](#key_info)。 | ||
* `TRX_ID`:正在等锁的事务 ID,即 `start_ts`。 | ||
* `CURRENT_HOLDING_TRX_ID`:当前持有锁的事务 ID,即 `start_ts`。 | ||
* `SQL_DIGEST`:当前正在等锁的事务中被阻塞的 SQL 语句的 Digest。 | ||
* `SQL_DIGEST_TEXT`:当前正在等锁的事务中被阻塞的 SQL 语句的归一化形式,即去除了参数和格式的 SQL 语句。与 `SQL_DIGEST` 对应。 | ||
|
||
> **警告:** | ||
> | ||
> * 该表中的信息是在查询时,从所有 TiKV 节点实时获取的。目前,即使加上了 `WHERE` 查询条件,也无法避免对所有 TiKV 节点都进行信息收集。如果集群规模很大、负载很高,查询该表有造成性能抖动的潜在风险,因此请根据实际情况使用。 | ||
> * 来自不同 TiKV 节点的信息不一定是同一时间点的快照。 | ||
> * 仅拥有 [PROCESS](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_process) 权限的用户可以查询该表。 | ||
> * `DATA_LOCK_WAITS` 表中的信息是在查询时,从所有 TiKV 节点实时获取的。目前,即使加上了 `WHERE` 查询条件,也无法避免对所有 TiKV 节点都进行信息收集。如果集群规模很大、负载很高,查询该表有造成性能抖动的潜在风险,因此请根据实际情况使用。 | ||
> * 来自不同 TiKV 节点的信息不能保证是同一时间点的快照。 | ||
> * `SQL_DIGEST` 列中的信息(SQL Digest)为 SQL 语句进行归一化后计算得到的哈希值。`SQL_DIGEST_TEXT` 列中的信息为内部从 Statements Summary 系列表中查询得到,因而存在内部查询不到对应语句的可能性。关于 SQL Digest 和 Statements Summary 相关表的详细说明,请参阅[Statement Summary Tables](/statement-summary-tables.md)。 | ||
|
||
## `KEY_INFO` | ||
|
||
`KEY_INFO` 列中展示了对 `KEY` 列中所给出的 key 的详细信息,以 JSON 格式给出。其包含的信息如下: | ||
|
||
* `"db_id"`:该 key 所属的数据库(schema)的 ID。 | ||
* `"db_name"`:该 key 所属的数据库(schema)的名称。 | ||
* `"table_id"`:该 key 所属的表的 ID。 | ||
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. May need to explain if it's a partitioned table, if it's the partition table id or the real physical table id |
||
* `"table_name"`:该 key 所属的表的名称。 | ||
* `"partition_id"`:该 key 所在的分区(partition)的 ID。 | ||
* `"partition_name"`:该 key 所在的分区(partition)的名称。 | ||
* `"handle_type"`:该 row key (即储存一行数据的 key)的 handle 类型,其可能的值有: | ||
* `"int"`:handle 为 int 类型,即 handle 为 row ID | ||
* `"common"`:非 int64 类型的 handle,在启用 clustered index 时非 int 类型的主键会显示为此类型 | ||
* `"unknown"`:当前暂不支持的 handle 类型 | ||
* `"handle_value"`:handle 的值。 | ||
* `"index_id"`:该 index key (即储存索引的 key)所属的 index ID。 | ||
* `"index_name"`:该 index key 所属的 index 名称。 | ||
* `"index_values"`:该 index key 中的 index value。 | ||
|
||
其中,不适用或当前无法查询到的信息会被省略。比如,row key 的信息中不会包含 `index_id`、`index_name` 和 `index_values`;index key 不会包含 `handle_type` 和 `handle_value`;非分区表不会显示 `partition_id` 和 `partition_name`;已经被删除掉的表中的 key 的信息无法获取 `table_name`、`db_id`、`db_name`、`index_name` 等 schema 信息,且无法区分是否为分区表。 | ||
|
||
> **注意:** | ||
> | ||
> 如果一个 key 来自一张启用了分区的表,而在查询时,由于某些原因(例如,其所属的表已经被删除)导致无法查询其所属的 schema 信息,则其所属的分区的 ID 可能会出现在 `table_id` 字段中。这是因为,TiDB 对不同分区的 key 的编码方式与对几张独立的表的 key 的编码方式一致,因而在缺失 schema 信息时无法确认该 key 属于一张未分区的表还是某张表的一个分区。 | ||
|
||
## 示例 | ||
|
||
|
@@ -51,36 +78,13 @@ select * from information_schema.data_lock_waits\G | |
|
||
```sql | ||
*************************** 1. row *************************** | ||
KEY: 7480000000000000355f728000000000000002 | ||
TRX_ID: 425405024158875649 | ||
CURRENT_HOLDING_TRX_ID: 425405016242126849 | ||
SQL_DIGEST: f7530877a35ae65300c42250abd8bc731bbaf0a7cabc05dab843565230611bb22 | ||
2 rows in set (0.01 sec) | ||
``` | ||
|
||
以上查询结果显示,ID 为 `425405024158875649` 的事务在执行 Digest 为 `"f7530877a35ae65300c42250abd8bc731bbaf0a7cabc05dab843565230611bb22"` 的语句的过程中,试图在 `"7480000000000000355f728000000000000002"` 这个 key 上获取悲观锁,但是该 key 上的锁目前被 ID 为 `425405016242126849` 的事务持有。 | ||
|
||
## SQL Digest | ||
|
||
`DATA_LOCK_WAITS` 表中会记录 SQL Digest,并不记录 SQL 原文。 | ||
|
||
SQL Digest 是 SQL 归一化之后的哈希值。如需查找 SQL Digest 对应的 SQL 原文,请进行以下操作之一: | ||
|
||
- 对于当前 TiDB 节点在最近一段时间内执行过的语句,你可以从 `STATEMENTS_SUMMARY` 或 `STATEMENTS_SUMMARY_HISTORY` 中根据 SQL Digest 查找到对应的 SQL 原文。 | ||
- 对于整个集群所有 TiDB 节点在最近一段时间内执行过的语句,你可以从 `CLUSTER_STATEMENTS_SUMMARY` 或`CLUSTER_STATEMENTS_SUMMARY_HISTORY` 中根据 SQL Digest 查找到对应的 SQL 原文。 | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
select digest, digest_text from information_schema.statements_summary where digest = "f7530877a35ae65300c42250abd8bc731bbaf0a7cabc05dab843565230611bb2"; | ||
``` | ||
|
||
```sql | ||
+------------------------------------------------------------------+---------------------------------------+ | ||
| digest | digest_text | | ||
+------------------------------------------------------------------+---------------------------------------+ | ||
| f7530877a35ae65300c42250abd8bc731bbaf0a7cabc05dab843565230611bb2 | update `t` set `v` = ? where `id` = ? | | ||
+------------------------------------------------------------------+---------------------------------------+ | ||
KEY: 7480000000000000355F728000000000000001 | ||
KEY_INFO: {"db_id":1,"db_name":"test","table_id":53,"table_name":"t","handle_type":"int","handle_value":"1"} | ||
TRX_ID: 426790594290122753 | ||
CURRENT_HOLDING_TRX_ID: 426790590082449409 | ||
SQL_DIGEST: 38b03afa5debbdf0326a014dbe5012a62c51957f1982b3093e748460f8b00821 | ||
SQL_DIGEST_TEXT: update `t` set `v` = `v` + ? where `id` = ? | ||
1 row in set (0.01 sec) | ||
``` | ||
|
||
关于 SQL Digest 和 `STATEMENTS_SUMMARY`、`STATEMENTS_SUMMARY_HISTORY` 、`CLUSTER_STATEMENTS_SUMMARY`、`CLUSTER_STATEMENTS_SUMMARY_HISTORY` 表的详细说明,请参阅 [Statement Summary Tables](/statement-summary-tables.md)。 | ||
以上查询结果显示,ID 为 `425405024158875649` 的事务在执行 Digest 为 `"f7530877a35ae65300c42250abd8bc731bbaf0a7cabc05dab843565230611bb22"`、形如 ``update `t` set `v` = `v` + ? where `id` = ?`` 的语句的过程中,试图在 `"7480000000000000355f728000000000000002"` 这个 key 上获取悲观锁,但是该 key 上的锁目前被 ID 为 `425405016242126849` 的事务持有。 |
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.
Uh oh!
There was an error while loading. Please reload this page.