

# SELECT FROM dbclustergroup\_sys.data\_mappings

Use `SELECT ... FROM dbclustergroup_sys.data_mappings` to read the data mappings of a database cluster group for Aurora: which member cluster holds each database or table, under which router name, and in which collocation.

## Description
<a name="databaseclustergroups-sql-select-data-mappings-description"></a>

Reads data mappings. The routing layer answers the read from its own state, so the read reaches no member cluster and doesn't test routing. To test routing, query a mapped table by its router name.

For the columns of the table, see [data\_mappings](databaseclustergroups-sysviews-data-mappings.md). For the concepts, see [Data mappings and collocations](databaseclustergroups-data-mappings.md). To change the mappings, see [Changing data mappings](databaseclustergroups-changing-mappings.md).

## Syntax
<a name="databaseclustergroups-sql-select-data-mappings-syntax"></a>

The select list, the optional `WHERE` clause, and the optional `LIMIT` clause take the forms that the parameters describe.

```sql
SELECT { * | {{column}} [AS {{alias}}] [, {{column}} [AS {{alias}}] ...] | COUNT(*) [AS {{alias}}] }
  FROM dbclustergroup_sys.data_mappings [[AS] {{table_alias}}]
 [WHERE { {{column}} = '{{value}}' | ({{column}}, {{column}} [, ...]) = ('{{value}}', '{{value}}' [, ...]) }]
 [LIMIT {{row_count}} [OFFSET {{offset}}] | LIMIT {{offset}}, {{row_count}}];
```

## Parameters and options
<a name="databaseclustergroups-sql-select-data-mappings-parameters"></a>

The select list names what to return. The `WHERE` and `LIMIT` clauses are optional.

\*  
Every column of `data_mappings`. You can't combine `*` with another select item.

column  
A column of `data_mappings`, such as `router_db_name` or `member_cluster_alias`. You can give it an alias with `AS`, and you can qualify it with the table alias, such as `m.router_db_name`.

COUNT(\*)  
The number of matching rows. It must be the only select item. You can give it an alias with `AS`.

WHERE  
Optional. One equality, or one tuple equality, on any column except `db_cluster_identifier`. Every value is a single-quoted string. Without `WHERE`, the statement returns every mapping. To match the database-level row of a database, use `(router_db_name, router_table_name) = ('app', '')`.

LIMIT row\_count [OFFSET offset], or LIMIT offset, row\_count  
Optional. Returns at most `row_count` rows after skipping `offset` rows. Each value is a non-negative integer literal.

## Where it runs and required privileges
<a name="databaseclustergroups-sql-select-data-mappings-privileges"></a>

Run the statement at the routing endpoint, in a session in query routing mode that isn't pinned. A pinned session passes the statement through to its member cluster, where it fails. You can run it inside a transaction, and with `autocommit=0`.

The router user needs `dbclustergroup_metadata_read_only`, `dbclustergroup_metadata_admin`, or `dbclustergroup_super_admin`. Without one, the read fails with error 1227. `dbclustergroup_move_admin` alone doesn't allow reading `data_mappings`. For all privileges for database cluster groups for Aurora, see [Routing layer privileges](databaseclustergroups-router-users.md#databaseclustergroups-router-users-privileges).

## Usage notes
<a name="databaseclustergroups-sql-select-data-mappings-usage"></a>

Keep the following in mind when you use the statement.
+ The routing layer refuses `ORDER BY`, `GROUP BY`, `HAVING`, `DISTINCT`, joins, subqueries, common table expressions, and locking reads such as `FOR UPDATE`. In the select list, it refuses every function and expression except a standalone `COUNT(*)`. Sort, group, and combine the rows in your client. For the query shapes that work, see [Filters the system tables accept](databaseclustergroups-system-views.md#databaseclustergroups-sysviews-filters).
+ A `WHERE` on a shared value, such as `router_collocation_group`, `member_cluster_alias`, or `router_db_name`, matches every row with that value. A lookup by cluster name can return several rows, because the same cluster name can exist on several member clusters.
+ A database-level row holds an empty string, not `NULL`, in its table columns. A comparison with `NULL` matches no row.
+ To filter by member cluster, use `member_cluster_alias`. The routing layer refuses `db_cluster_identifier` in a `WHERE` clause.
+ `LIMIT` applies to the result after `COUNT(*)`. `SELECT COUNT(*) ... LIMIT 0` returns no row, and `LIMIT 1` returns the count.
+ While no one changes the mappings, every read returns rows in the same order, so consecutive `LIMIT ... OFFSET` pages cover the table with no gaps and no repeats. A mapping change between pages can shift rows. To export the table, read it with one `SELECT` and no `LIMIT`. See [Exporting the mappings before and after a change](databaseclustergroups-changing-mappings.md#databaseclustergroups-export-mappings).
+ On Aurora MySQL, the routing layer refuses a text `PREPARE` and a binary-protocol prepare of this statement. Send it as plain text, for example with `useServerPrepStmts=false` in MySQL Connector/J.
+ The routing layer doesn't support `EXPLAIN` of this statement.

## Examples
<a name="databaseclustergroups-sql-select-data-mappings-examples"></a>

The following examples read the data mappings in several ways. The first reads every mapping, and the others filter with one equality or one tuple equality, count the matching rows, or page through the table.

```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 = 'cg_orders';

SELECT * FROM dbclustergroup_sys.data_mappings
 WHERE (router_db_name, router_table_name) = ('app', '');

SELECT router_db_name, router_table_name, member_cluster_alias
  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');

SELECT * FROM dbclustergroup_sys.data_mappings LIMIT 100;

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

## Errors
<a name="databaseclustergroups-sql-select-data-mappings-errors"></a>

The statement can return the following errors. For the error texts and all errors from the routing layer, see [Routing and data mapping errors](databaseclustergroups-errors-routing.md).


| Aurora MySQL | Meaning | 
| --- | --- | 
| [1227](databaseclustergroups-errors-routing.md) (42000) | The router user holds none of dbclustergroup\_metadata\_read\_only, dbclustergroup\_metadata\_admin, and dbclustergroup\_super\_admin. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | ORDER BY is not supported on this table: sort in your client. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | GROUP BY and HAVING are not supported on this table, or DISTINCT is not supported on this table. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | JOINs are not supported on this table, or Subqueries in FROM are not supported on this table. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | Locking reads (FOR UPDATE/FOR SHARE/LOCK IN SHARE MODE) are not supported on this table. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | AND/OR are not supported in the WHERE clause on this table: use the tuple form. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | The WHERE clause uses IN, \!=, <, >, LIKE, IS NULL, or a range. The clause supports only column = 'value' or a tuple equality. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | Only literal values are allowed. No expressions, subqueries, or variables. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | db\_cluster\_identifier cannot be used in a WHERE clause on this table: filter by member\_cluster\_alias instead. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | The LIMIT or OFFSET clause uses another form. On this table, use LIMIT n, LIMIT n OFFSET m, or LIMIT m, n, with non-negative integer literals. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | A function or expression is in the select list, or \* is combined with other select items. Only COUNT(\*) as the sole select item is allowed. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | Unknown column '<name>': the name isn't a column of data\_mappings. | 
| [1235](databaseclustergroups-errors-routing.md) (42000) | This statement type is not supported: a PREPARE or binary-protocol prepare of the read. Send it as plain text. | 

## Related statements
<a name="databaseclustergroups-sql-select-data-mappings-related"></a>

For more information, see the following:
+ [INSERT INTO dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-insert-data-mappings.md)
+ [UPDATE dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-update-data-mappings.md)
+ [DELETE FROM dbclustergroup\_sys.data\_mappings](databaseclustergroups-sql-delete-data-mappings.md)
+ [SELECT FROM dbclustergroup\_data\_movement.move\_info](databaseclustergroups-sql-move-info.md)