

# data\_mappings

The `dbclustergroup_sys.data_mappings` system table has one row for each data mapping of a database cluster group for Aurora.

## Purpose
<a name="databaseclustergroups-sysviews-data-mappings-purpose"></a>

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](databaseclustergroups-data-mappings.md).

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](databaseclustergroups-sql-insert-data-mappings.md), [UPDATE](databaseclustergroups-sql-update-data-mappings.md), or [DELETE](databaseclustergroups-sql-delete-data-mappings.md). 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](databaseclustergroups-data-mappings.md#databaseclustergroups-when-a-data-mapping-change-takes-effect). For the procedures, see [Changing data mappings](databaseclustergroups-changing-mappings.md).

**Tip**  
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](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings).

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 name="databaseclustergroups-sysviews-data-mappings-columns"></a>

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](databaseclustergroups-sql-select-data-mappings.md). For the query shapes that work, see [Filters the system tables accept](databaseclustergroups-system-views.md#databaseclustergroups-sysviews-filters). 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 `WHERE` on `router_collocation_group` or `member_cluster_alias` matches every row with that value.
+ An export shows the empty table columns of a database-level row as `''`. An `INSERT` reads `''` in those columns as no value, so you can replay them as written. Leave `db_cluster_identifier` out of the replayed `INSERT`, 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.

```sql
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.

```sql
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.

```sql
SELECT * FROM dbclustergroup_sys.data_mappings LIMIT 100;
```

## Related topics
<a name="databaseclustergroups-sysviews-data-mappings-related"></a>

For more information, see the following topics:
+ [Data mapping statements](databaseclustergroups-sql-mappings.md), for the grammar, rules, and errors of each read and write
+ [Changing data mappings](databaseclustergroups-changing-mappings.md)
+ [EXPLAIN](databaseclustergroups-sql-explain.md), which names the member cluster that a statement goes to. Use `data_mappings` to cross-check it.
+ [member\_cluster\_mappings](databaseclustergroups-sysviews-member-cluster-mappings.md), which translates each alias to a DB cluster identifier