ロック統計

LOCK STATSは、1 つまたは複数のテーブルの統計をロックするために使用されます。

あらすじ

LockStatsStmt
LOCKSTATSTableNameList
TableNameList
TableName,
TableName
Identifier.Identifier

テーブルtを作成し、そこにデータを挿入します。テーブルtの統計がロックされていない場合、 ANALYZEステートメントを正常に実行できます。

mysql> create table t(a int, b int); Query OK, 0 rows affected (0.03 sec) mysql> insert into t values (1,2), (3,4), (5,6), (7,8); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> analyze table t; Query OK, 0 rows affected, 1 warning (0.02 sec) mysql> show warnings; +-------+------+-----------------------------------------------------------------+ | Level | Code | Message | +-------+------+-----------------------------------------------------------------+ | Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t | +-------+------+-----------------------------------------------------------------+ 1 row in set (0.00 sec)

テーブルtの統計をロックし、 ANALYZEを実行します。 SHOW STATS_LOCKEDの出力から、表tの統計がロックされていることがわかります。警告メッセージは、 ANALYZEステートメントがテーブルtをスキップしたことを示しています。

mysql> lock stats t; Query OK, 0 rows affected (0.00 sec) mysql> show stats_locked; +---------+------------+----------------+--------+ | Db_name | Table_name | Partition_name | Status | +---------+------------+----------------+--------+ | test | t | | locked | +---------+------------+----------------+--------+ 1 row in set (0.01 sec) mysql> analyze table t; Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> show warnings; +---------+------+-----------------------------------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------------------------------+ | Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t | | Warning | 1105 | skip analyze locked table: t | +---------+------+-----------------------------------------------------------------+ 2 rows in set (0.00 sec)

テーブルtANALYZEの統計のロックを解除すると、再び正常に実行できます。

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 | +-------+------+-----------------------------------------------------------------+ 1 row in set (0.00 sec)

MySQL の互換性

このステートメントは、MySQL 構文に対する TiDB 拡張です。

こちらもご覧ください

このページは役に立ちましたか?

Playground
登録なしで TiDB の機能をワンストップでインタラクティブに体験できます。
製品
TiDB Dedicated
TiDB Serverless
TiDB
価格
PoC お問い合わせ
エコシステム
TiKV
TiFlash
OSS Insight
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.