SHOW STATS_LOCKED

SHOW STATS_LOCKED shows the tables whose statistics are locked.

SHOW STATS_LOCKED - 图1

Warning

Locking statistics is an experimental feature for the current version. It is not recommended to use it in the production environment.

Synopsis

ShowStatsLockedStmt

SHOW STATS_LOCKED - 图2

ShowLikeOrWhereOpt

SHOW STATS_LOCKED - 图3

  1. ShowStatsLockedStmt ::= 'SHOW' 'STATS_LOCKED' ShowLikeOrWhereOpt
  2. ShowLikeOrWhereOpt ::= 'LIKE' SimpleExpr | 'WHERE' Expression

Examples

Create table t, and insert data into it. When the statistics of table t are not locked, the ANALYZE statement can be successfully executed.

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

Lock the statistics of table t and execute ANALYZE. From the output of SHOW STATS_LOCKED, you can see that the statistics of table t have been locked. The warning message shows that the ANALYZE statement has skipped table t.

  1. mysql> lock stats t;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> show stats_locked;
  4. +---------+------------+----------------+--------+
  5. | Db_name | Table_name | Partition_name | Status |
  6. +---------+------------+----------------+--------+
  7. | test | t | | locked |
  8. +---------+------------+----------------+--------+
  9. 1 row in set (0.01 sec)
  10. mysql> analyze table t;
  11. Query OK, 0 rows affected, 2 warnings (0.00 sec)
  12. mysql> show warnings;
  13. +---------+------+-----------------------------------------------------------------+
  14. | Level | Code | Message |
  15. +---------+------+-----------------------------------------------------------------+
  16. | Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t |
  17. | Warning | 1105 | skip analyze locked table: t |
  18. +---------+------+-----------------------------------------------------------------+
  19. 2 rows in set (0.00 sec)

Unlock the statistics of table t and ANALYZE can be successfully executed again.

  1. mysql> unlock stats t;
  2. Query OK, 0 rows affected (0.01 sec)
  3. mysql> analyze table t;
  4. Query OK, 0 rows affected, 1 warning (0.03 sec)
  5. mysql> show warnings;
  6. +-------+------+-----------------------------------------------------------------+
  7. | Level | Code | Message |
  8. +-------+------+-----------------------------------------------------------------+
  9. | Note | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t |
  10. +-------+------+-----------------------------------------------------------------+
  11. 1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also