ADMIN CHECKSUM TABLE
ADMIN CHECKSUM TABLE
语句用于计算表中所有行和索引的 CRC64 校验和。在 TiDB Lightning 等程序中,可通过此语句来确保导入操作成功。
语法图
- AdminStmt
- TableNameList
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' )
TableNameList ::=
TableName ( ',' TableName )*
示例
创建表 t1
:
CREATE TABLE t1(id INT PRIMARY KEY);
插入一些数据:
INSERT INTO t1 VALUES (1),(2),(3);
计算表 t1
的校验和:
ADMIN CHECKSUM TABLE t1;
输出结果示例如下:
+---------+------------+----------------------+-----------+-------------+
| Db_name | Table_name | Checksum_crc64_xor | Total_kvs | Total_bytes |
+---------+------------+----------------------+-----------+-------------+
| test | t1 | 10909174369497628533 | 3 | 75 |
+---------+------------+----------------------+-----------+-------------+
1 row in set (0.00 sec)
MySQL 兼容性
ADMIN CHECKSUM TABLE
语句是 TiDB 对 MySQL 语法的扩展。