DROP PLACEMENT POLICY

DROP PLACEMENT POLICY is used to drop a previously created placement policy.

DROP PLACEMENT POLICY - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

DropPolicyStmt

DROP PLACEMENT POLICY - 图2

PolicyName

DROP PLACEMENT POLICY - 图3

  1. DropPolicyStmt ::=
  2. "DROP" "PLACEMENT" "POLICY" IfExists PolicyName
  3. PolicyName ::=
  4. Identifier

Examples

Placement policies can only be dropped when they are not referenced by any tables or partitions.

  1. CREATE PLACEMENT POLICY p1 FOLLOWERS=4;
  2. CREATE TABLE t1 (a INT PRIMARY KEY) PLACEMENT POLICY=p1;
  3. DROP PLACEMENT POLICY p1; -- This statement fails because the placement policy p1 is referenced.
  4. -- Finds which tables and partitions reference the placement policy.
  5. SELECT table_schema, table_name FROM information_schema.tables WHERE tidb_placement_policy_name='p1';
  6. SELECT table_schema, table_name FROM information_schema.partitions WHERE tidb_placement_policy_name='p1';
  7. ALTER TABLE t1 PLACEMENT POLICY=default; -- Removes the placement policy from t1.
  8. DROP PLACEMENT POLICY p1; -- Succeeds.
  1. Query OK, 0 rows affected (0.10 sec)
  2. Query OK, 0 rows affected (0.11 sec)
  3. ERROR 8241 (HY000): Placement policy 'p1' is still in use
  4. +--------------+------------+
  5. | table_schema | table_name |
  6. +--------------+------------+
  7. | test | t1 |
  8. +--------------+------------+
  9. 1 row in set (0.00 sec)
  10. Empty set (0.01 sec)
  11. Query OK, 0 rows affected (0.08 sec)
  12. Query OK, 0 rows affected (0.21 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also