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

dev: update sql admin syntax #2204

Merged
merged 14 commits into from
Feb 13, 2020
45 changes: 44 additions & 1 deletion dev/reference/sql/statements/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ ADMIN SHOW DDL;
{{< copyable "sql" >}}

```sql
ADMIN SHOW DDL JOBS;
ADMIN SHOW DDL JOBS [NUM] [WHERE where_condition];
```

* `NUM`:查看已经执行完成的 DDL 作业队列中最近 `NUM` 条结果,未指定时,默认值为 10。
* `WHERE`:`WHERE` 子句,可以添加过滤条件。

`ADMIN SHOW DDL JOBS` 用于查看当前 DDL 作业队列中的所有结果(包括正在运行以及等待运行的任务)以及已执行完成的 DDL 作业队列中的最近十条结果。

{{< copyable "sql" >}}
Expand Down Expand Up @@ -55,6 +58,8 @@ ADMIN REPAIR TABLE tbl_name CREATE TABLE STATEMENT;

## 使用示例

查看正在执行的 DDL 任务中最近 10 条已经完成的 DDL 任务。未指定 `NUM` 时,默认只显示最近 10 条已经执行完的 DDL 任务。

{{< copyable "sql" >}}

```sql
Expand All @@ -79,6 +84,44 @@ admin show ddl jobs;
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
```

查看正在执行的 DDL 任务中最近 5 条已经执行完的 DDL 任务。

{{< copyable "sql" >}}

```sql
admin show ddl jobs 5;
```

```
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME | STATE |
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
| 45 | test | t1 | add index | write reorganization | 32 | 37 | 0 | 2019-01-10 12:38:36.501 +0800 CST | running |
| 44 | test | t1 | add index | none | 32 | 37 | 0 | 2019-01-10 12:36:55.18 +0800 CST | rollback done |
| 43 | test | t1 | add index | public | 32 | 37 | 6 | 2019-01-10 12:35:13.66 +0800 CST | synced |
| 42 | test | t1 | drop index | none | 32 | 37 | 0 | 2019-01-10 12:34:35.204 +0800 CST | synced |
| 41 | test | t1 | add index | public | 32 | 37 | 0 | 2019-01-10 12:33:22.62 +0800 CST | synced |
| 40 | test | t1 | drop column | none | 32 | 37 | 0 | 2019-01-10 12:33:08.212 +0800 CST | synced |
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
```

查看 test 数据库中未执行完成的 DDL 任务,包括正在执行中以及最近 5 条已经执行完但是执行失败的 DDL 任务。

{{< copyable "sql" >}}

```sql
admin show ddl jobs 5 where state!='synced' and db_name='test';
```

```
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME | STATE |
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
| 45 | test | t1 | add index | write reorganization | 32 | 37 | 0 | 2019-01-10 12:38:36.501 +0800 CST | running |
| 44 | test | t1 | add index | none | 32 | 37 | 0 | 2019-01-10 12:36:55.18 +0800 CST | rollback done |
+--------+---------+------------+---------------+----------------------+-----------+----------+-----------+-----------------------------------+---------------+
```

* `JOB_ID`:每个 DDL 操作对应一个 DDL 作业,`JOB_ID` 全局唯一。
* `DB_NAME`:执行 DDL 操作的数据库的名称。
* `TABLE_NAME`:执行 DDL 操作的表的名称。
Expand Down