title | summary | aliases | ||
---|---|---|---|---|
ADMIN | TiDB SQL Statement Reference |
An overview of the usage of ADMIN for the TiDB database. |
|
This statement is a TiDB extension syntax, used to view the status of TiDB and check the data of tables in TiDB. This document introduces the following ADMIN
related statements:
Statement | Description |
---|---|
ADMIN CANCEL DDL JOBS |
Cancels the currently running DDL jobs. |
ADMIN PAUSE DDL JOBS |
Pauses the currently running DDL jobs. |
ADMIN RESUME DDL JOBS |
Resumes the paused DDL jobs. |
ADMIN CHECKSUM TABLE |
Calculates the CRC64 of all rows + indexes of a table. |
ADMIN CHECK [TABLE|INDEX] |
Checks for consistency of a table or index. |
ADMIN SHOW DDL [JOBS|QUERIES] |
Shows details about currently running or recently completed DDL jobs. |
Statement | Description |
---|---|
ADMIN CANCEL DDL JOBS |
Cancels a currently running DDL jobs. |
ADMIN CHECKSUM TABLE |
Calculates the CRC64 of all rows + indexes of a table. |
ADMIN CHECK [TABLE|INDEX] |
Checks for consistency of a table or index. |
ADMIN SHOW DDL [JOBS|QUERIES] |
Shows details about currently running or recently completed DDL jobs. |
ADMIN SHOW TELEMETRY |
Shows information that will be reported back to PingCAP as part of the telemetry feature. |
{{< copyable "sql" >}}
ADMIN RELOAD expr_pushdown_blacklist;
The above statement is used to reload the blocklist pushed down by the expression.
{{< copyable "sql" >}}
ADMIN RELOAD opt_rule_blacklist;
The above statement is used to reload the blocklist of logic optimization rules.
Note:
This feature is not available on TiDB Serverless clusters.
ADMIN PLUGINS ENABLE plugin_name [, plugin_name] ...;
The above statement is used to enable the plugin_name
plugin.
ADMIN PLUGINS DISABLE plugin_name [, plugin_name] ...;
The above statement is used to disable the plugin_name
plugin.
{{< copyable "sql" >}}
ADMIN FLUSH BINDINGS;
The above statement is used to persist SQL Plan binding information.
{{< copyable "sql" >}}
ADMIN CAPTURE BINDINGS;
The above statement can generate the binding of SQL Plan from the SELECT
statement that occurs more than once.
{{< copyable "sql" >}}
ADMIN EVOLVE BINDINGS;
After the automatic binding feature is enabled, the evolution of SQL Plan binding information is triggered every bind-info-leave
(the default value is 3s
). The above statement is used to proactively trigger this evolution.
{{< copyable "sql" >}}
ADMIN RELOAD BINDINGS;
The above statement is used to reload SQL Plan binding information.
Note:
This TiDB statement is not applicable to TiDB Cloud.
To overwrite the metadata of the stored table in an untrusted way in extreme cases, use ADMIN REPAIR TABLE
:
{{< copyable "sql" >}}
ADMIN REPAIR TABLE tbl_name CREATE TABLE STATEMENT;
Here "untrusted" means that you need to manually ensure that the metadata of the original table can be covered by the CREATE TABLE STATEMENT
operation. To use this REPAIR
statement, enable the repair-mode
configuration item, and make sure that the tables to be repaired are listed in the repair-table-list
.
ADMIN SHOW t NEXT_ROW_ID;
The above statement is used to view the details of some special columns of a table. The output is the same as SHOW TABLE NEXT_ROW_ID.
Note:
This feature is not available on TiDB Serverless clusters.
ADMIN SHOW SLOW RECENT N;
ADMIN SHOW SLOW TOP [INTERNAL | ALL] N;
For details, refer to ADMIN SHOW SLOW
command.
AdminStmt ::=
'ADMIN' ( 'SHOW' ( 'DDL' ( 'JOBS' Int64Num? WhereClauseOptional | 'JOB' 'QUERIES' NumList )? | TableName 'NEXT_ROW_ID' | 'SLOW' AdminShowSlow ) | 'CHECK' ( 'TABLE' TableNameList | 'INDEX' TableName Identifier ( HandleRange ( ',' HandleRange )* )? ) | 'RECOVER' 'INDEX' TableName Identifier | 'CLEANUP' ( 'INDEX' TableName Identifier | 'TABLE' 'LOCK' TableNameList ) | 'CHECKSUM' 'TABLE' TableNameList | 'CANCEL' 'DDL' 'JOBS' NumList | 'RELOAD' ( 'EXPR_PUSHDOWN_BLACKLIST' | 'OPT_RULE_BLACKLIST' | 'BINDINGS' ) | 'PLUGINS' ( 'ENABLE' | 'DISABLE' ) PluginNameList | 'REPAIR' 'TABLE' TableName CreateTableStmt | ( 'FLUSH' | 'CAPTURE' | 'EVOLVE' ) 'BINDINGS' )
Run the following command to view the last 10 completed DDL jobs in the currently running DDL job queue. When NUM
is not specified, only the last 10 completed DDL jobs is presented by default.
{{< copyable "sql" >}}
ADMIN SHOW DDL JOBS;
+--------+---------+------------+---------------------+----------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+---------------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME | END_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 | 2019-01-10 12:36:55.852 +0800 CST | rollback done |
| 43 | test | t1 | add index | public | 32 | 37 | 6 | 2019-01-10 12:35:13.66 +0800 CST | 2019-01-10 12:35:14.925 +0800 CST | synced |
| 42 | test | t1 | drop index | none | 32 | 37 | 0 | 2019-01-10 12:34:35.204 +0800 CST | 2019-01-10 12:34:36.958 +0800 CST | synced |
| 41 | test | t1 | add index | public | 32 | 37 | 0 | 2019-01-10 12:33:22.62 +0800 CST | 2019-01-10 12:33:24.625 +0800 CST | synced |
| 40 | test | t1 | drop column | none | 32 | 37 | 0 | 2019-01-10 12:33:08.212 +0800 CST | 2019-01-10 12:33:09.78 +0800 CST | synced |
| 39 | test | t1 | add column | public | 32 | 37 | 0 | 2019-01-10 12:32:55.42 +0800 CST | 2019-01-10 12:32:56.24 +0800 CST | synced |
| 38 | test | t1 | create table | public | 32 | 37 | 0 | 2019-01-10 12:32:41.956 +0800 CST | 2019-01-10 12:32:43.956 +0800 CST | synced |
| 36 | test | | drop table | none | 32 | 34 | 0 | 2019-01-10 11:29:59.982 +0800 CST | 2019-01-10 11:30:00.45 +0800 CST | synced |
| 35 | test | | create table | public | 32 | 34 | 0 | 2019-01-10 11:29:40.741 +0800 CST | 2019-01-10 11:29:41.682 +0800 CST | synced |
| 33 | test | | create schema | public | 32 | 0 | 0 | 2019-01-10 11:29:22.813 +0800 CST | 2019-01-10 11:29:23.954 +0800 CST | synced |
+--------+---------+------------+---------------------+----------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+---------------+
Run the following command to view the last 5 completed DDL jobs in the currently running DDL job queue:
{{< copyable "sql" >}}
ADMIN SHOW DDL JOBS 5;
+--------+---------+------------+---------------------+----------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+---------------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME | END_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 | 2019-01-10 12:36:55.852 +0800 CST | rollback done |
| 43 | test | t1 | add index | public | 32 | 37 | 6 | 2019-01-10 12:35:13.66 +0800 CST | 2019-01-10 12:35:14.925 +0800 CST | synced |
| 42 | test | t1 | drop index | none | 32 | 37 | 0 | 2019-01-10 12:34:35.204 +0800 CST | 2019-01-10 12:34:36.958 +0800 CST | synced |
| 41 | test | t1 | add index | public | 32 | 37 | 0 | 2019-01-10 12:33:22.62 +0800 CST | 2019-01-10 12:33:24.625 +0800 CST | synced |
| 40 | test | t1 | drop column | none | 32 | 37 | 0 | 2019-01-10 12:33:08.212 +0800 CST | 2019-01-10 12:33:09.78 +0800 CST | synced |
+--------+---------+------------+---------------------+----------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+---------------+
Run the following command to view the details of some special columns of a table. The output is the same as SHOW TABLE NEXT_ROW_ID.
ADMIN SHOW t NEXT_ROW_ID;
+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE |
+---------+------------+-------------+--------------------+----------------+
| test | t | _tidb_rowid | 101 | _TIDB_ROWID |
| test | t | _tidb_rowid | 1 | AUTO_INCREMENT |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.01 sec)
Run the following command to view the uncompleted DDL jobs in the test database. The results include the DDL jobs that are running and the last 5 DDL jobs that are completed but failed.
{{< copyable "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 | END_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 | 2019-01-10 12:36:55.852 +0800 CST | rollback done |
+--------+---------+------------+---------------------+----------------+-----------+----------+-----------+-----------------------------------+-----------------------------------+---------------+
JOB_ID
: each DDL operation corresponds to one DDL job.JOB_ID
is globally unique.DB_NAME
: the name of the database on which the DDL operations are performed.TABLE_NAME
: the name of the table on which the DDL operations are performed.JOB_TYPE
: the type of the DDL operations.SCHEMA_STATE
: the current state of the schema. If theJOB_TYPE
isadd index
, it is the state of the index; if theJOB_TYPE
isadd column
, it is the state of the column; if theJOB_TYPE
iscreate table
, it is the state of the table. The common states include:none
: it indicates not existing. When thedrop
orcreate
operation fails and rolls back, it usually becomes thenone
state.delete only
,write only
,delete reorganization
,write reorganization
: these four states are intermediate states. These states are not visible in common operations, because the conversion from the intermediate states is so quick. You can see thewrite reorganization
state only inadd index
operations, which means that the index data is being added.public
: it indicates existing and usable. When operations likecreate table
andadd index/column
are finished, it usually becomes thepublic
state, which means that the created table/column/index can be normally read and written now.
SCHEMA_ID
: the ID of the database on which the DDL operations are performed.TABLE_ID
: the ID of the table on which the DDL operations are performed.ROW_COUNT
: the number of the data rows that have been added when running theadd index
operation.START_TIME
: the start time of the DDL operations.END_TIME
: the end time of the DDL operations.STATE
: the state of the DDL operations. The common states include:none
: it indicates that the operation task has been put in the DDL job queue but has not been performed yet, because it is waiting for the previous tasks to complete. Another reason might be that it becomes thenone
state after running the drop operation, but it will soon be updated to thesynced
state, which means that all TiDB instances have been synced to this state.running
: it indicates that the operation is being performed.synced
: it indicates that the operation has been performed successfully and all TiDB instances have been synced to this state.rollback done
: it indicates that the operation has failed and has finished rolling back.rollingback
: it indicates that the operation has failed and is rolling back.cancelling
: it indicates that the operation is being cancelled. This state only occurs when you cancel DDL jobs using theADMIN CANCEL DDL JOBS
command.paused
: it indicates that the operation has been paused. This state only appears when you use theADMIN PAUSED DDL JOBS
command to pause the DDL job. You can use theADMIN RESUME DDL JOBS
command to resume the DDL job.
This statement is a TiDB extension to MySQL syntax.