Skip to content

Commit 1b740f6

Browse files
authored
Extend DDL/MDL info (#20329) (#20705)
1 parent b145fb7 commit 1b740f6

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

Diff for: TOC-tidb-cloud.md

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@
622622
- System Tables
623623
- `mysql` Schema
624624
- [Overview](/mysql-schema/mysql-schema.md)
625+
- [`tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md)
625626
- [`user`](/mysql-schema/mysql-schema-user.md)
626627
- INFORMATION_SCHEMA
627628
- [Overview](/information-schema/information-schema.md)

Diff for: TOC.md

+1
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@
960960
- System Tables
961961
- `mysql` Schema
962962
- [Overview](/mysql-schema/mysql-schema.md)
963+
- [`tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md)
963964
- [`user`](/mysql-schema/mysql-schema-user.md)
964965
- INFORMATION_SCHEMA
965966
- [Overview](/information-schema/information-schema.md)

Diff for: ddl-introduction.md

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ When TiDB is adding an index, the phase of backfilling data will cause read and
184184

185185
You can only resume a paused DDL task. Otherwise, the `Job 3 can't be resumed` error is shown in the `RESULT` column.
186186

187+
## DDL-related tables
188+
189+
- [`information_schema.DDL_JOBS`](/information-schema/information-schema-ddl-jobs.md): Information about currently running and finished DDL jobs.
190+
- [`mysql.tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md): Information about [metadata lock](/metadata-lock.md) views. It can help identify what query is blocking the DDL from making progress.
191+
187192
## Common questions
188193

189194
For common questions about DDL execution, see [SQL FAQ - DDL execution](https://docs.pingcap.com/tidb/stable/sql-faq).

Diff for: metadata-lock.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,33 @@ TiDB v6.3.0 introduces the `mysql.tidb_mdl_view` view to help you obtain the inf
7777
The following takes adding an index for table `t` as an example. Assume that there is a DDL statement `ALTER TABLE t ADD INDEX idx(a)`:
7878

7979
```sql
80-
SELECT * FROM mysql.tidb_mdl_view\G
80+
TABLE mysql.tidb_mdl_view\G
81+
```
82+
83+
```
8184
*************************** 1. row ***************************
82-
JOB_ID: 141
83-
DB_NAME: test
84-
TABLE_NAME: t
85-
QUERY: ALTER TABLE t ADD INDEX idx(a)
86-
SESSION ID: 2199023255957
87-
TxnStart: 08-30 16:35:41.313(435643624013955072)
85+
job_id: 118
86+
db_name: test
87+
table_name: t
88+
query: ALTER TABLE t ADD COLUMN c INT
89+
session_id: 1547698182
90+
start_time: 2025-03-19 09:52:36.509000
8891
SQL_DIGESTS: ["begin","select * from `t`"]
89-
1 row in set (0.02 sec)
92+
1 row in set (0.00 sec)
93+
9094
```
9195

92-
From the preceding output, you can see that the transaction whose `SESSION ID` is `2199023255957` blocks the `ADD INDEX` DDL. `SQL_DIGEST` shows the SQL statements executed by this transaction, which is ``["begin","select * from `t`"]``. To make the blocked DDL continue to execute, you can use the following global `KILL` statement to kill the `2199023255957` transaction:
96+
From the preceding output, you can see that the transaction whose `SESSION ID` is `1547698182` blocks the `ADD COLUMN` DDL. `SQL_DIGEST` shows the SQL statements executed by this transaction, which is ``["begin","select * from `t`"]``. To make the blocked DDL continue to execute, you can use the following global `KILL` statement to kill the `1547698182` transaction:
9397

9498
```sql
95-
mysql> KILL 2199023255957;
99+
mysql> KILL 1547698182;
96100
Query OK, 0 rows affected (0.00 sec)
97101
```
98102

99103
After killing the transaction, you can select the `mysql.tidb_mdl_view` view again. At this time, the preceding transaction is not shown in the output, which means the DDL is not blocked.
100104

101105
```sql
102-
SELECT * FROM mysql.tidb_mdl_view\G
106+
TABLE mysql.tidb_mdl_view\G
103107
Empty set (0.01 sec)
104108
```
105109

Diff for: mysql-schema/mysql-schema-tidb-mdl-view.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: mysql.tidb_mdl_view
3+
summary: Learn about the `tidb_mdl_view` table in the `mysql` schema.
4+
---
5+
6+
# `mysql.tidb_mdl_view`
7+
8+
This table shows the information about the [metadata lock](/metadata-lock.md) views.
9+
10+
```sql
11+
DESC mysql.tidb_mdl_view;
12+
```
13+
14+
The output is as follows:
15+
16+
```
17+
+-------------+-----------------+------+------+---------+-------+
18+
| Field | Type | Null | Key | Default | Extra |
19+
+-------------+-----------------+------+------+---------+-------+
20+
| job_id | bigint | NO | PRI | NULL | |
21+
| db_name | longtext | YES | | NULL | |
22+
| table_name | longtext | YES | | NULL | |
23+
| query | longtext | YES | | NULL | |
24+
| session_id | bigint unsigned | YES | | NULL | |
25+
| start_time | timestamp(6) | YES | | NULL | |
26+
| SQL_DIGESTS | varchar(5) | YES | | NULL | |
27+
+-------------+-----------------+------+------+---------+-------+
28+
7 rows in set (0.00 sec)
29+
```
30+
31+
## Fields
32+
33+
* `job_id`: The identifier of the job.
34+
* `db_name`: The database name.
35+
* `table_name`: The table name.
36+
* `query`: The query.
37+
* `session_id`: The identifier of the session.
38+
* `start_time`: The start time. This column was called `TxnStart` in earlier versions.
39+
* `SQL_DIGESTS`: The digests of the SQL statements.

Diff for: mysql-schema/mysql-schema.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Currently, the `help_topic` is NULL.
9191

9292
## System tables related to metadata locks
9393

94-
* `tidb_mdl_view`: a view of metadata locks. You can use it to view information about the currently blocked DDL statements. See also [Metadata Lock](/metadata-lock.md).
94+
* [`tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md): a view of metadata locks. You can use it to view the information about the currently blocked DDL statements. See also [Metadata Lock](/metadata-lock.md).
9595
* `tidb_mdl_info`: used internally by TiDB to synchronize metadata locks across nodes.
9696

9797
## System tables related to DDL statements

0 commit comments

Comments
 (0)