SHOW PLACEMENT FOR

SHOW PLACEMENT FOR 用于汇总所有放置策略 (placement policy),并用统一的形式呈现特定表、数据库或分区的信息。

本语句返回结果中的 Scheduling_State 列标识了 Placement Driver (PD) 在当前对象上的调度进度,有以下可能的结果:

  • PENDING: PD 没有进行调度。可能的原因之一是放置规则虽然语法上正确,但集群拓扑并不满足。比如指定 FOLLOWERS=4 但只有 3 个可用作 follower 的 TiKV 实例。
  • INPROGRESS: PD 正在进行调度。
  • SCHEDULED: PD 调度完成。

语法图

ShowStmt

SHOW PLACEMENT FOR - 图1

ShowPlacementTarget

SHOW PLACEMENT FOR - 图2

  1. ShowStmt ::=
  2. "PLACEMENT" "FOR" ShowPlacementTarget
  3. ShowPlacementTarget ::=
  4. DatabaseSym DBName
  5. | "TABLE" TableName
  6. | "TABLE" TableName "PARTITION" Identifier

示例

  1. CREATE PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1" FOLLOWERS=4;
  2. use test;
  3. ALTER DATABASE test PLACEMENT POLICY=p1;
  4. CREATE TABLE t1 (a INT);
  5. SHOW PLACEMENT FOR DATABASE test;
  6. SHOW PLACEMENT FOR TABLE t1;
  7. SHOW CREATE TABLE t1\G
  8. CREATE TABLE t3 (a INT) PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES LESS THAN (20));
  9. SHOW PLACEMENT FOR TABLE t3 PARTITION p1\G
  1. Query OK, 0 rows affected (0.02 sec)
  2. Query OK, 0 rows affected (0.00 sec)
  3. Query OK, 0 rows affected (0.01 sec)
  4. +---------------+----------------------------------------------------------------------+------------------+
  5. | Target | Placement | Scheduling_State |
  6. +---------------+----------------------------------------------------------------------+------------------+
  7. | DATABASE test | PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1" FOLLOWERS=4 | INPROGRESS |
  8. +---------------+----------------------------------------------------------------------+------------------+
  9. 1 row in set (0.00 sec)
  10. +---------------+-------------+------------------+
  11. | Target | Placement | Scheduling_State |
  12. +---------------+-------------+------------------+
  13. | TABLE test.t1 | FOLLOWERS=4 | INPROGRESS |
  14. +---------------+-------------+------------------+
  15. 1 row in set (0.00 sec)
  16. ***************************[ 1. row ]***************************
  17. Table | t1
  18. Create Table | CREATE TABLE `t1` (
  19. `a` int(11) DEFAULT NULL
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![placement] PLACEMENT POLICY=`p1` */
  21. 1 row in set (0.00 sec)
  22. ***************************[ 1. row ]***************************
  23. Target | TABLE test.t3 PARTITION p1
  24. Placement | PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1" FOLLOWERS=4
  25. Scheduling_State | PENDING
  26. 1 row in set (0.00 sec)

MySQL 兼容性

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

另请参阅