PingKai Logo下载

UNLOCK STATS

UNLOCK STATS 用于解锁一个或多个表的统计信息。

语法概要

UnlockStatsStmt
UNLOCK STATS TableNameList TableName PARTITION PartitionNameList
TableNameList
TableName ,
TableName
Identifier . Identifier
PartitionNameList
Identifier ,

示例

参考 LOCK STATS 中的示例,创建一个表 t 并锁定其统计信息。

解锁表 t 的统计信息后,可以成功执行 ANALYZE。

mysql> UNLOCK STATS t;
Query OK, 0 rows affected (0.01 sec)

mysql> ANALYZE TABLE t;
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> SHOW WARNINGS;
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                                                 |
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Note  | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "use min(1, 110000/8) as the sample-rate=1" |
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

参考 LOCK STATS 中的示例,创建一个表 t 并锁定其分区 p1 的统计信息。

解锁分区 p1 的统计信息后,可以成功执行 ANALYZE。

mysql> UNLOCK STATS t PARTITION p1;
Query OK, 0 rows affected (0.00 sec)

mysql> ANALYZE TABLE t PARTITION p1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> SHOW WARNINGS;
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                                                                              |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Note  | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1" |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL 兼容性

该语句为 TiDB 对 MySQL 语法的扩展。

相关链接