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) #19185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9f6808a
docs: add documentation for ADMIN ALTER DDL JOBS command
tangenta Nov 15, 2024
467c683
Update sql-statement-admin-alter-ddl.md
hfxsd Nov 15, 2024
8b0a66e
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 15, 2024
25d36f5
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 15, 2024
3f48950
docs: clarify parameter value range consistency with system variables…
tangenta Nov 15, 2024
6075869
Update sql-statements/sql-statement-admin-alter-ddl.md
hfxsd Nov 18, 2024
f131a6c
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 20, 2024
7fc9c1e
update admin show ddl jobs doc
tangenta Nov 22, 2024
76c7e6b
Update TOC.md
hfxsd Nov 22, 2024
ffc2021
address comments
tangenta Nov 25, 2024
b61bace
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 25, 2024
9ad4034
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 25, 2024
75174f0
Apply suggestions from code review
hfxsd Nov 28, 2024
56e4da7
Update sql-statements/sql-statement-admin-alter-ddl.md
hfxsd Nov 28, 2024
5ca29fa
Apply suggestions from code review
hfxsd Nov 29, 2024
b15a9ad
Update sql-statements/sql-statement-admin-show-ddl.md
tangenta Nov 30, 2024
e0c5505
Update sql-statements/sql-statement-admin-alter-ddl.md
tangenta Nov 30, 2024
627be13
Apply suggestions from code review
hfxsd Dec 2, 2024
e33976c
Apply suggestions from code review
hfxsd Dec 2, 2024
a507f34
Apply suggestions from code review
lilin90 Dec 2, 2024
b219a94
Update format
lilin90 Dec 2, 2024
2a16975
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
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@
- SQL 语句
- [概览](/sql-statements/sql-statement-overview.md)
- [`ADMIN`](/sql-statements/sql-statement-admin.md)
- [`ADMIN ALTER DDL JOBS`](/sql-statements/sql-statement-admin-alter-ddl.md)
- [`ADMIN CANCEL DDL`](/sql-statements/sql-statement-admin-cancel-ddl.md)
- [`ADMIN CHECKSUM TABLE`](/sql-statements/sql-statement-admin-checksum-table.md)
- [`ADMIN CHECK [TABLE|INDEX]`](/sql-statements/sql-statement-admin-check-table-index.md)
Expand Down
90 changes: 90 additions & 0 deletions sql-statements/sql-statement-admin-alter-ddl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: ADMIN ALTER DDL JOBS
summary: TiDB 数据库中 `ADMIN ALTER DDL JOBS` 的使用概况。
---

# ADMIN ALTER DDL JOBS

`ADMIN ALTER DDL JOBS` 语句用于修改单个正在运行的 DDL 作业的相关参数。例如:

```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) 设置。

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

目前在一条 `ADMIN ALTER DDL JOBS` 中仅支持对单个 DDL 作业的参数进行调整,不支持同时调整多个 ID 对应的参数。

以下是不同 DDL 作业类型支持的各项参数,及其对应的系统变量:

- `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-版本开始引入) 设置。

以上设置,当前仅对关闭 [`tidb_enable_dist_task`](/system-variables.md#tidb_enable_dist_task-从-v710-版本开始引入) 后,提交并运行中的 `ADD INDEX` 的作业生效。

- `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` 设置。

参数的取值范围和对应系统变量的取值范围保持一致。

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

以下是部分语句示例:

```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
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
AdminAlterDDLStmt ::=
'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