ALTER PLACEMENT POLICY

ALTER PLACEMENT POLICY is used to modify existing placement policies that have previously been created. All the tables and partitions which use the placement policy will automatically be updated.

ALTER PLACEMENT POLICY - 图1

Note

This feature is not available on TiDB Serverless clusters.

ALTER PLACEMENT POLICY replaces the previous policy with the new definition. It does not merge the old policy with the new one. In the following example, FOLLOWERS=4 is lost when the ALTER PLACEMENT POLICY is executed:

  1. CREATE PLACEMENT POLICY p1 FOLLOWERS=4;
  2. ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";

Synopsis

AlterPolicyStmt

ALTER PLACEMENT POLICY - 图2

PolicyName

ALTER PLACEMENT POLICY - 图3

PlacementOptionList

ALTER PLACEMENT POLICY - 图4

PlacementOption

ALTER PLACEMENT POLICY - 图5

CommonPlacementOption

ALTER PLACEMENT POLICY - 图6

SugarPlacementOption

ALTER PLACEMENT POLICY - 图7

AdvancedPlacementOption

ALTER PLACEMENT POLICY - 图8

  1. AlterPolicyStmt ::=
  2. "ALTER" "PLACEMENT" "POLICY" IfExists PolicyName PlacementOptionList
  3. PolicyName ::=
  4. Identifier
  5. PlacementOptionList ::=
  6. PlacementOption
  7. | PlacementOptionList PlacementOption
  8. | PlacementOptionList ',' PlacementOption
  9. PlacementOption ::=
  10. CommonPlacementOption
  11. | SugarPlacementOption
  12. | AdvancedPlacementOption
  13. CommonPlacementOption ::=
  14. "FOLLOWERS" EqOpt LengthNum
  15. SugarPlacementOption ::=
  16. "PRIMARY_REGION" EqOpt stringLit
  17. | "REGIONS" EqOpt stringLit
  18. | "SCHEDULE" EqOpt stringLit
  19. AdvancedPlacementOption ::=
  20. "LEARNERS" EqOpt LengthNum
  21. | "CONSTRAINTS" EqOpt stringLit
  22. | "LEADER_CONSTRAINTS" EqOpt stringLit
  23. | "FOLLOWER_CONSTRAINTS" EqOpt stringLit
  24. | "LEARNER_CONSTRAINTS" EqOpt stringLit

Examples

ALTER PLACEMENT POLICY - 图9

Note

To know which regions are available in your cluster, see SHOW PLACEMENT LABELS.

If you do not see any available regions, your TiKV installation might not have labels set correctly.

  1. CREATE PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";
  2. CREATE TABLE t1 (i INT) PLACEMENT POLICY=p1; -- Assign policy p1 to table t1
  3. ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4; -- The rules of t1 will be updated automatically.
  4. SHOW CREATE PLACEMENT POLICY p1\G;
  1. Query OK, 0 rows affected (0.08 sec)
  2. Query OK, 0 rows affected (0.10 sec)
  3. ***************************[ 1. row ]***************************
  4. Policy | p1
  5. Create Policy | CREATE PLACEMENT POLICY `p1` PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4
  6. 1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also