DELETE FROM dbclustergroup_sys.data_mappings
Use DELETE FROM dbclustergroup_sys.data_mappings to remove the router name of a database or a table in a database cluster group for Aurora.
Description
Removes data mappings. The delete doesn't change the object on the member cluster. After the delete reaches the routing layer, the routing layer no longer knows the router name, and a statement that names it returns a not-found error.
For the task, see Changing data mappings.
Syntax
DELETE FROM dbclustergroup_sys.data_mappings WHERE {column= 'value' | (column,column[, ...]) = ('value', 'value' [, ...]) };
Parameters and options
The statement takes the following parameters.
- WHERE
-
One equality, or one tuple equality, on the router name columns or on a shared value. A database-level row has an empty string, not
NULL, in its schema and table columns, so an empty string selects only that row. On Aurora MySQL,(router_db_name, router_table_name) = ('selects the database-level mapping.db', '')
Where it runs and required privileges
Run the statement where you run every mapping write: at the routing endpoint, in an unpinned session, outside a transaction. For the engine rules, see INSERT INTO dbclustergroup_sys.data_mappings.
The router user needs dbclustergroup_metadata_admin or dbclustergroup_super_admin. For all privileges for database cluster groups for Aurora, see Privileges.
Usage notes
Keep the following in mind when you use the statement.
-
A mapping change reaches the routing layer within a short time, and a statement routed on an older mapping returns a retryable error. See Applying data mapping changes.
-
Match exactly the rows that you mean, and check the number of affected rows. A
WHEREonrouter_collocation_groupormember_cluster_aliasdeletes every row with that value. ADELETEwhoseWHEREclause matches more than 1,000 rows fails with error 1235 and removes nothing. ADELETEwithout aWHEREclause removes every mapping that no scaleout table uses, up to 1,000 rows for each statement, table-level mappings first. Each repeat removes the next rows. It keeps the mappings that scaleout tables use, and when only those are left, it fails with error 1235. For more information about the limit, see Routing metadata and naming limits. The routing layer also refusesLIKEin theWHEREclause. Export the mappings first. For more information about exporting, see Exporting the mappings before and after a change. -
The routing layer refuses the delete of a mapping that a scaleout table still names as a member. Drop the scaleout table first. See DROP SCALEOUT TABLE.
-
To change a database from database-level to table-level mappings, delete the database-level row and insert the table-level rows directly after it. The database is unreachable through the routing endpoint between the two steps. See Using database-level and table-level mappings.
You can't delete a mapping that a data movement job holds a lock on. The statement fails with error 1205 (HY000), Metadata for … is being changed by another operation, and removes nothing. A DELETE without a WHERE clause fails the same way when any data movement job holds a lock. Wait until cleanup_status reads Complete in move_info, and then run the statement again.
The delete needs an available writer instance on each member cluster that holds a mapping that it deletes. If a member cluster has no available writer, the delete fails and removes nothing. The routing layer reaches member clusters directly, not through the routing endpoint.
Examples
The following example deletes the database-level mapping of app_db.
DELETE FROM dbclustergroup_sys.data_mappings WHERE (router_db_name, router_table_name) = ('app_db', '');
Errors
The statement can return the following errors. For the error texts and all errors from the routing layer, see Routing and data mapping errors.
| Aurora MySQL | Meaning |
|---|---|
| 1227 (42000) | The router user lacks dbclustergroup_metadata_admin. |
| 1235 (42000) | The write is inside a transaction. Commit or roll back, and send it again outside a transaction. |
| 1235 (42000) | cannot remove data mapping '<db>.<table>': referenced by a scaleout table: the mapping backs a scaleout table. Drop the scaleout table first. |
| 1235 (42000) | cannot remove all data mappings: <n> rows are still referenced by scaleout tables: a DELETE without a WHERE clause found only mappings that scaleout tables use, so it removed nothing. To remove those mappings, drop your scaleout tables first. |
| 1235 (42000) | Remove of <n> rows exceeds the per-request limit of 1000; narrow the filter or split the write into smaller requests: your WHERE clause matches more than 1,000 rows, so the statement removes nothing. Narrow the WHERE clause. |
| 1205 (HY000) | Metadata for … is being changed by another operation: a data movement job holds a lock on the mapping, or on any mapping for a DELETE without a WHERE clause, so the statement removes nothing. Run it again after the job's cleanup completes. |
| 1235 (42000) | AND/OR are not supported in the WHERE clause on this table: the WHERE clause has more than one condition. Use one equality or the tuple form. |
| 1412 (HY000) | After a mapping change, a statement that the routing layer routed on the older mapping returns this error. On Aurora MySQL, the routing layer resends a text-protocol statement up to 3 times first, then returns 1412 with the session and any open transaction intact, so retry the statement. |
| 63928 (40001) | Inside a transaction, a statement needed a mapping that changed after the transaction's first routed statement, and the routing layer rolled the whole transaction back. Retry the whole transaction from its first statement; don't send COMMIT. |
Related statements
For more information, see the following: