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

docs: add documentation for ADMIN ALTER DDL JOBS command #19085

Merged
merged 22 commits into from
Dec 2, 2024
Merged
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8b32418
docs: add documentation for ADMIN ALTER DDL JOBS command
tangenta Nov 15, 2024
db58424
Update sql-statement-admin-alter-ddl.md
hfxsd Nov 15, 2024
8ba0b7e
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 15, 2024
ee66331
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 15, 2024
3187695
docs: clarify parameter value range consistency with system variables…
tangenta Nov 15, 2024
c91a9da
Update sql-statements/sql-statement-admin-alter-ddl.md
hfxsd Nov 18, 2024
540be02
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 20, 2024
32ad9c1
update admin show ddl jobs doc
tangenta Nov 22, 2024
6d99637
Update TOC.md
hfxsd Nov 22, 2024
42d1e05
address comments
tangenta Nov 25, 2024
c0f548f
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 25, 2024
24e3cff
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 25, 2024
875b4a5
Apply suggestions from code review
hfxsd Nov 28, 2024
e92d519
Update sql-statements/sql-statement-admin-alter-ddl.md
hfxsd Nov 28, 2024
33d722b
Apply suggestions from code review
hfxsd Nov 29, 2024
81762e9
Update sql-statements/sql-statement-admin-show-ddl.md
tangenta Nov 30, 2024
004e915
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 30, 2024
7d1ba51
Apply suggestions from code review
hfxsd Dec 2, 2024
3aecf54
Apply suggestions from code review
hfxsd Dec 2, 2024
ecc162e
Apply suggestions from code review
lilin90 Dec 2, 2024
899c438
Update format
lilin90 Dec 2, 2024
546eaed
Update sql-statements/sql-statement-admin-alter-ddl.md
hfxsd Dec 2, 2024
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
80 changes: 80 additions & 0 deletions sql-statements/sql-statement-admin-alter-ddl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: ADMIN ALTER DDL JOBS
summary: TiDB 数据库中 `ADMIN ALTER DDL JOBS` 的使用概况。
---

# ADMIN ALTER DDL JOBS

`ADMIN ALTER DDL JOBS` 语句可用于修改单个正在运行的 DDL 作业相关的参数。例如:
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

```sql
ADMIN ALTER DDL JOBS 101 THREAD = 8;
```

其中 `101` 表示 DDL 作业的 ID,该 ID 可以通过查询 [`ADMIN SHOW DDL JOBS`](/sql-statements/sql-statement-admin-show-ddl.md) 获得。`THREAD` 表示当前 DDL 作业的并发度,其初始值由系统变量 [`tidb_ddl_reorg_worker_cnt`](/system-variables.md#tidb_ddl_reorg_worker_cnt) 设置。
tangenta marked this conversation as resolved.
Show resolved Hide resolved

目前支持 `ADMIN ALTER DDL JOBS` 的 DDL 作业类型包括:`ADD INDEX`、`MODIFY COLUMN` 和 `REORGANIZE PARTITION`。对于其他 DDL 作业类型,执行 `ADMIN ALTER DDL JOBS` 会报 `unsupported DDL operation` 的错误。

tangenta marked this conversation as resolved.
Show resolved Hide resolved
以下是不同 DDL 作业类型支持的各项参数,以及它们对应的系统变量:
tangenta marked this conversation as resolved.
Show resolved Hide resolved
tangenta marked this conversation as resolved.
Show resolved Hide resolved
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

- `ADD INDEX`:
- `THREAD`: 并发度,初始值由系统变量 `tidb_ddl_reorg_worker_cnt` 设置。
- `BATCH_SIZE`: 批大小,初始值由系统变量 [`tidb_ddl_reorg_batch_size`](/system-variables.md#tidb_ddl_reorg_batch_size) 设置。
- `MAX_WRITE_SPEED`: 向每个 TiKV 导入索引记录时的最大带宽限制,初始值由系统变量 [`tidb_ddl_reorg_max_write_speed`](/system-variables.md#tidb_ddl_reorg_max_write_speed-从-v850-版本开始引入) 设置。
Copy link
Collaborator

@hfxsd hfxsd Nov 18, 2024

Choose a reason for hiding this comment

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

For reviewer: 变量 tidb_ddl_reorg_max_write_speed 在这个 PR 中:pingcap/docs#19445

tangenta marked this conversation as resolved.
Show resolved Hide resolved
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

tangenta marked this conversation as resolved.
Show resolved Hide resolved
- `MODIFY COLUMN`:
- `THREAD`: 并发度,初始值由系统变量 `tidb_ddl_reorg_worker_cnt` 设置。
- `BATCH_SIZE`: 批大小,初始值由系统变量 `tidb_ddl_reorg_batch_size` 设置。

- `REORGANIZE PARTITION`:
- `THREAD`: 并发度,初始值由系统变量 `tidb_ddl_reorg_worker_cnt` 设置。
- `BATCH_SIZE`: 批大小,初始值由系统变量 `tidb_ddl_reorg_batch_size` 设置。
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

参数的取值范围和系统变量的保持一致。
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

`ADMIN ALTER DDL JOBS` 仅对正在运行的 DDL 作业生效。如果 DDL 作业不存在或者已经结束,执行该语句会报 `ddl job ? is not running` 的错误。
tangenta marked this conversation as resolved.
Show resolved Hide resolved

以下是部分语句示例:

```sql
ADMIN ALTER DDL JOBS 101 THREAD = 8;
ADMIN ALTER DDL JOBS 101 BATCH_SIZE = 256;
ADMIN ALTER DDL JOBS 101 MAX_WRITE_SPEED = '200MiB';
ADMIN ALTER DDL JOBS 101 THREAD = 8, BATCH_SIZE = 256;
```

要查看某个 DDL 作业当前的参数值,可以执行 `ADMIN SHOW DDL JOBS`,结果显示在 `COMMENTS` 列:

```sql
mysql> admin show ddl jobs 1;
+--------+---------+------------+-----------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+-----------------------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | CREATE_TIME | START_TIME | END_TIME | STATE | COMMENTS |
+--------+---------+------------+-----------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+-----------------------+
| 124 | test | t | add index | public | 2 | 122 | 3 | 2024-11-15 11:17:06.213000 | 2024-11-15 11:17:06.213000 | 2024-11-15 11:17:08.363000 | synced | ingest, DXF, thread=8 |
+--------+---------+------------+-----------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+-----------------------+
1 row in set (0.01 sec)
```

## 语法图

```ebnf+diagram
AdminPauseDDLStmt ::=
tangenta marked this conversation as resolved.
Show resolved Hide resolved
'ADMIN' 'ALTER' 'DDL' 'JOBS' Int64Num AlterJobOptionList

AlterJobOptionList ::=
AlterJobOption ( ',' AlterJobOption )*

AlterJobOption ::=
identifier "=" SignedLiteral
```

## MySQL 兼容性

`ADMIN ALTER DDL JOBS` 语句是 TiDB 对 MySQL 语法的扩展。

## 另请参阅

* [`ADMIN SHOW DDL [JOBS|QUERIES]`](/sql-statements/sql-statement-admin-show-ddl.md)
* [`ADMIN CANCEL DDL`](/sql-statements/sql-statement-admin-cancel-ddl.md)
* [`ADMIN PAUSE DDL`](/sql-statements/sql-statement-admin-pause-ddl.md)
* [`ADMIN RESUME DDL`](/sql-statements/sql-statement-admin-resume-ddl.md)
Loading