CREATE PLACEMENT POLICY

CREATE PLACEMENT POLICY is used to create a named placement policy that can later be assigned to tables, partitions, or database schemas.

CREATE PLACEMENT POLICY - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

CreatePolicyStmt

CREATE PLACEMENT POLICY - 图2

PolicyName

CREATE PLACEMENT POLICY - 图3

PlacementOptionList

CREATE PLACEMENT POLICY - 图4

PlacementOption

CREATE PLACEMENT POLICY - 图5

CommonPlacementOption

CREATE PLACEMENT POLICY - 图6

SugarPlacementOption

CREATE PLACEMENT POLICY - 图7

AdvancedPlacementOption

CREATE PLACEMENT POLICY - 图8

  1. CreatePolicyStmt ::=
  2. "CREATE" "PLACEMENT" "POLICY" IfNotExists 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
  25. | "SURVIVAL_PREFERENCES" EqOpt stringLit

Examples

CREATE 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" FOLLOWERS=4;
  2. CREATE TABLE t1 (a INT) PLACEMENT POLICY=p1;
  3. SHOW CREATE PLACEMENT POLICY p1;
  1. Query OK, 0 rows affected (0.08 sec)
  2. Query OK, 0 rows affected (0.10 sec)
  3. +--------+---------------------------------------------------------------------------------------------------+
  4. | Policy | Create Policy |
  5. +--------+---------------------------------------------------------------------------------------------------+
  6. | p1 | CREATE PLACEMENT POLICY `p1` PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1" FOLLOWERS=4 |
  7. +--------+---------------------------------------------------------------------------------------------------+
  8. 1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also