Skip to content
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

Extend DDL/MDL info (#20329) #20705

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@
- System Tables
- `mysql` Schema
- [Overview](/mysql-schema/mysql-schema.md)
- [`tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md)
- [`user`](/mysql-schema/mysql-schema-user.md)
- INFORMATION_SCHEMA
- [Overview](/information-schema/information-schema.md)
Expand Down
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@
- System Tables
- `mysql` Schema
- [Overview](/mysql-schema/mysql-schema.md)
- [`tidb_mdl_view`](/mysql-schema/mysql-schema-tidb-mdl-view.md)
- [`user`](/mysql-schema/mysql-schema-user.md)
- INFORMATION_SCHEMA
- [Overview](/information-schema/information-schema.md)
Expand Down
5 changes: 5 additions & 0 deletions ddl-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ When TiDB is adding an index, the phase of backfilling data will cause read and

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

## DDL-related tables

- [`information_schema.DDL_JOBS`](/information-schema/information-schema-ddl-jobs.md): Information about currently running and finished DDL jobs.
- [`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.

## Common questions

For common questions about DDL execution, see [SQL FAQ - DDL execution](https://docs.pingcap.com/tidb/stable/sql-faq).
26 changes: 15 additions & 11 deletions metadata-lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,33 @@ TiDB v6.3.0 introduces the `mysql.tidb_mdl_view` view to help you obtain the inf
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)`:

```sql
SELECT * FROM mysql.tidb_mdl_view\G
TABLE mysql.tidb_mdl_view\G
```

```
*************************** 1. row ***************************
JOB_ID: 141
DB_NAME: test
TABLE_NAME: t
QUERY: ALTER TABLE t ADD INDEX idx(a)
SESSION ID: 2199023255957
TxnStart: 08-30 16:35:41.313(435643624013955072)
job_id: 118
db_name: test
table_name: t
query: ALTER TABLE t ADD COLUMN c INT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The query shown here is ALTER TABLE t ADD COLUMN c INT, but the surrounding text refers to adding an index (ALTER TABLE t ADD INDEX idx(a)). This is inconsistent and might confuse users. Should this be updated to match the surrounding text, or vice versa?

Suggested change
query: ALTER TABLE t ADD COLUMN c INT
query: ALTER TABLE t ADD INDEX idx(a)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a correct comment that needs addressing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session_id: 1547698182
start_time: 2025-03-19 09:52:36.509000
SQL_DIGESTS: ["begin","select * from `t`"]
1 row in set (0.02 sec)
1 row in set (0.00 sec)

```

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:
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:

```sql
mysql> KILL 2199023255957;
mysql> KILL 1547698182;
Query OK, 0 rows affected (0.00 sec)
```

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.

```sql
SELECT * FROM mysql.tidb_mdl_view\G
TABLE mysql.tidb_mdl_view\G
Empty set (0.01 sec)
```

Expand Down
39 changes: 39 additions & 0 deletions mysql-schema/mysql-schema-tidb-mdl-view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: mysql.tidb_mdl_view
summary: Learn about the `tidb_mdl_view` table in the `mysql` schema.
---

# `mysql.tidb_mdl_view`

This table shows the information about the [metadata lock](/metadata-lock.md) views.

```sql
DESC mysql.tidb_mdl_view;
```

The output is as follows:

```
+-------------+-----------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------+------+------+---------+-------+
| job_id | bigint | NO | PRI | NULL | |
| db_name | longtext | YES | | NULL | |
| table_name | longtext | YES | | NULL | |
| query | longtext | YES | | NULL | |
| session_id | bigint unsigned | YES | | NULL | |
| start_time | timestamp(6) | YES | | NULL | |
| SQL_DIGESTS | varchar(5) | YES | | NULL | |
+-------------+-----------------+------+------+---------+-------+
7 rows in set (0.00 sec)
```

## Fields

* `job_id`: The identifier of the job.
* `db_name`: The database name.
* `table_name`: The table name.
* `query`: The query.
* `session_id`: The identifier of the session.
* `start_time`: The start time. This column was called `TxnStart` in earlier versions.
* `SQL_DIGESTS`: The digests of the SQL statements.
2 changes: 1 addition & 1 deletion mysql-schema/mysql-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Currently, the `help_topic` is NULL.

## System tables related to metadata locks

* `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).
* [`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).
* `tidb_mdl_info`: used internally by TiDB to synchronize metadata locks across nodes.

## System tables related to DDL statements
Expand Down