title | summary |
---|---|
ALTER PLACEMENT POLICY |
TiDB 数据库中 ALTER PLACEMENT POLICY 的使用概况。 |
ALTER PLACEMENT POLICY
用于修改已创建的放置策略。此修改会自动更新至所有使用这些放置策略的表和分区。
ALTER PLACEMENT POLICY
会完全替换之前定义的规则,而不会和之前的规则合并,比如在下面的例子中,FOLLOWERS=4
就被 ALTER PLACEMENT POLICY
语句覆盖了:
CREATE PLACEMENT POLICY p1 FOLLOWERS=4;
ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";
AlterPolicyStmt ::=
"ALTER" "PLACEMENT" "POLICY" IfExists PolicyName PlacementOptionList
PolicyName ::=
Identifier
PlacementOptionList ::=
PlacementOption
| PlacementOptionList PlacementOption
| PlacementOptionList ',' PlacementOption
PlacementOption ::=
CommonPlacementOption
| SugarPlacementOption
| AdvancedPlacementOption
CommonPlacementOption ::=
"FOLLOWERS" EqOpt LengthNum
SugarPlacementOption ::=
"PRIMARY_REGION" EqOpt stringLit
| "REGIONS" EqOpt stringLit
| "SCHEDULE" EqOpt stringLit
AdvancedPlacementOption ::=
"LEARNERS" EqOpt LengthNum
| "CONSTRAINTS" EqOpt stringLit
| "LEADER_CONSTRAINTS" EqOpt stringLit
| "FOLLOWER_CONSTRAINTS" EqOpt stringLit
| "LEARNER_CONSTRAINTS" EqOpt stringLit
注意:
如要查看所在集群中可用的区域,见
SHOW PLACEMENT LABELS
。如果未看到任何可用的区域,此 TiKV 集群在部署时可能未正确设置标签 (label)。
{{< copyable "sql" >}}
CREATE PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";
CREATE TABLE t1 (i INT) PLACEMENT POLICY=p1; -- 绑定放置策略 p1 到表 t1。
ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4; -- t1 上的放置规则会自动更新。
SHOW CREATE PLACEMENT POLICY p1\G;
Query OK, 0 rows affected (0.08 sec)
Query OK, 0 rows affected (0.10 sec)
***************************[ 1. row ]***************************
Policy | p1
Create Policy | CREATE PLACEMENT POLICY `p1` PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4
1 row in set (0.00 sec)
该语句是 TiDB 对 MySQL 语法的扩展。