data_mappings
The dbclustergroup_sys.data_mappings system table has one row for each data mapping of a database cluster group for Aurora.
Purpose
Use this table to see where the routing layer sends each mapped object, under which router name, and in which collocation. For the concept, see Data mappings and collocations.
Member cluster tools, such as Performance Insights and the member cluster logs, show cluster names. The routing layer rewrites each statement before the member cluster runs it. Use this table to translate cluster names back to the router names that your application uses.
To change placement, write to this table with INSERT, UPDATE, or DELETE. Run each write outside a transaction. A write moves no data, and a multi-row INSERT applies all its rows or none. A mapping change reaches the routing layer within a short time. Inside a transaction, a statement that needs a mapping changed after the transaction's first routed statement fails with error 63928, and the routing layer rolls back the transaction. For when a change takes effect and what an open session sees, see Applying data mapping changes. For the procedures, see Changing data mappings.
Export data_mappings and member_cluster_mappings before and after every mapping change. Keep the files with your change record. For the procedure, see Exporting the mappings before and after a change.
The group keeps only the current rows of data_mappings, so a change or a delete leaves no record in the table. To keep a history, turn on the routing layer audit log, which records each statement that changes a data mapping and the router user who ran it, and export the mappings before and after every change. The audit log doesn't record statements in a pinned session.
Columns and example queries
A database-level row places a whole database on one member cluster. A table-level row places one table, and the member tables of a scaleout table are table-level rows. A database-level row has an empty string, not NULL, in its table columns.
Columns
The table has the following columns. Every column except db_cluster_identifier is writable.
| Column | Type | Description |
|---|---|---|
router_db_name |
varchar(64) |
The database name that applications use through the routing endpoint (the router database name). |
router_table_name |
varchar(64) |
The table name that applications use through the routing endpoint. Empty for a database-level row. |
cluster_db_name |
varchar(64) |
The database name on the member cluster (the cluster database name). |
cluster_table_name |
varchar(64) |
The table name on the member cluster. Empty for a database-level row. |
member_cluster_alias |
varchar(64) |
The member cluster that holds the object. Matches member_cluster_mappings.member_cluster_alias. |
router_collocation_group |
varchar(64) |
The collocation that the object belongs to, and moves with. A row that names no collocation gets the member cluster alias as its collocation. |
db_cluster_identifier |
varchar(64) |
The DB cluster identifier of the member cluster. Read-only: leave it out of an INSERT. |
Where to query it
Query the table at the routing endpoint, in query routing mode, in an unpinned session. You can read the table inside a transaction. A read needs dbclustergroup_metadata_read_only, dbclustergroup_metadata_admin, or dbclustergroup_super_admin. A write with INSERT, UPDATE, or DELETE needs dbclustergroup_metadata_admin, and runs outside a transaction. On Aurora MySQL, a session with autocommit = 0 counts as an open transaction.
A WHERE clause takes one equality or one tuple equality, with every value quoted. For the statement, see SELECT FROM dbclustergroup_sys.data_mappings. For the query shapes that work, see Filters the system tables accept. Keep the following rules in mind when you read the table:
-
A lookup by cluster name can return several rows, because the same cluster name can exist on several member clusters.
-
A tuple with a table name doesn't match a database-level row. To find the database-level row for a database, use an empty table name on Aurora MySQL, as in the examples that follow.
-
A
WHEREonrouter_collocation_groupormember_cluster_aliasmatches every row with that value. -
An export shows the empty table columns of a database-level row as
''. AnINSERTreads''in those columns as no value, so you can replay them as written. Leavedb_cluster_identifierout of the replayedINSERT, because it is read-only.
Example queries
The following queries list every mapping, then everything mapped to one member cluster, then the objects in one collocation.
SELECT * FROM dbclustergroup_sys.data_mappings; SELECT * FROM dbclustergroup_sys.data_mappings WHERE member_cluster_alias = 'member-b'; SELECT * FROM dbclustergroup_sys.data_mappings WHERE router_collocation_group = 'tenant_42';
The following queries find the database-level row of a database, translate a cluster name to its router name, and check whether one mapping row exists.
SELECT * FROM dbclustergroup_sys.data_mappings WHERE (router_db_name, router_table_name) = ('app', ''); SELECT * FROM dbclustergroup_sys.data_mappings WHERE (cluster_db_name, cluster_table_name) = ('app', 'orders_m3'); SELECT COUNT(*) AS rows_found FROM dbclustergroup_sys.data_mappings WHERE (router_db_name, router_table_name) = ('app', 'orders');
The following query reads the first 100 mappings.
SELECT * FROM dbclustergroup_sys.data_mappings LIMIT 100;
Related topics
For more information, see the following topics:
-
Data mapping statements, for the grammar, rules, and errors of each read and write
-
EXPLAIN, which names the member cluster that a statement goes to. Use
data_mappingsto cross-check it. -
member_cluster_mappings, which translates each alias to a DB cluster identifier