SHOW TABLE STATUS

SHOW TABLE STATUS 语句用于显示 TiDB 中表的各种统计信息。如果显示统计信息过期,建议运行 ANALYZE TABLE

语法图

ShowStmt:

ShowStmt

ShowTargetFilterable:

ShowTargetFilterable

ShowDatabaseNameOpt:

ShowDatabaseNameOpt

示例

  1. mysql> CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, c1 INT NOT NULL);
  2. Query OK, 0 rows affected (0.11 sec)
  3. mysql> INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5);
  4. Query OK, 5 rows affected (0.02 sec)
  5. Records: 5 Duplicates: 0 Warnings: 0
  6. mysql> SHOW TABLE STATUS LIKE 't1'\G
  7. *************************** 1. row ***************************
  8. Name: t1
  9. Engine: InnoDB
  10. Version: 10
  11. Row_format: Compact
  12. Rows: 0
  13. Avg_row_length: 0
  14. Data_length: 0
  15. Max_data_length: 0
  16. Index_length: 0
  17. Data_free: 0
  18. Auto_increment: 30001
  19. Create_time: 2019-04-19 08:32:06
  20. Update_time: NULL
  21. Check_time: NULL
  22. Collation: utf8mb4_bin
  23. Checksum:
  24. Create_options:
  25. Comment:
  26. 1 row in set (0.00 sec)
  27. mysql> analyze table t1;
  28. Query OK, 0 rows affected (0.12 sec)
  29. mysql> SHOW TABLE STATUS LIKE 't1'\G
  30. *************************** 1. row ***************************
  31. Name: t1
  32. Engine: InnoDB
  33. Version: 10
  34. Row_format: Compact
  35. Rows: 5
  36. Avg_row_length: 16
  37. Data_length: 80
  38. Max_data_length: 0
  39. Index_length: 0
  40. Data_free: 0
  41. Auto_increment: 30001
  42. Create_time: 2019-04-19 08:32:06
  43. Update_time: NULL
  44. Check_time: NULL
  45. Collation: utf8mb4_bin
  46. Checksum:
  47. Create_options:
  48. Comment:
  49. 1 row in set (0.00 sec)

MySQL 兼容性

SHOW TABLE STATUS 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue

另请参阅