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
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. For the concepts, see Data mappings and collocations. To change the mappings, see Changing data mappings.
Syntax
The select list, the optional WHERE clause, and the optional LIMIT clause take the forms that the parameters describe.
SELECT { * |column[ASalias] [,column[ASalias] ...] | COUNT(*) [ASalias] } FROM dbclustergroup_sys.data_mappings [[AS]table_alias] [WHERE {column= 'value' | (column,column[, ...]) = ('value', 'value' [, ...]) }] [LIMITrow_count[OFFSEToffset] | LIMIToffset,row_count];
Parameters and options
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 asrouter_db_nameormember_cluster_alias. You can give it an alias withAS, and you can qualify it with the table alias, such asm.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. WithoutWHERE, 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_countrows after skippingoffsetrows. Each value is a non-negative integer literal.
Where it runs and required privileges
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.
Usage notes
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 asFOR UPDATE. In the select list, it refuses every function and expression except a standaloneCOUNT(*). Sort, group, and combine the rows in your client. For the query shapes that work, see Filters the system tables accept. -
A
WHEREon a shared value, such asrouter_collocation_group,member_cluster_alias, orrouter_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 withNULLmatches no row. -
To filter by member cluster, use
member_cluster_alias. The routing layer refusesdb_cluster_identifierin aWHEREclause. -
LIMITapplies to the result afterCOUNT(*).SELECT COUNT(*) ... LIMIT 0returns no row, andLIMIT 1returns the count. -
While no one changes the mappings, every read returns rows in the same order, so consecutive
LIMIT ... OFFSETpages cover the table with no gaps and no repeats. A mapping change between pages can shift rows. To export the table, read it with oneSELECTand noLIMIT. See Exporting the mappings before and after a change. -
On Aurora MySQL, the routing layer refuses a text
PREPAREand a binary-protocol prepare of this statement. Send it as plain text, for example withuseServerPrepStmts=falsein MySQL Connector/J. -
The routing layer doesn't support
EXPLAINof this statement.
Examples
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.
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
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 holds none of dbclustergroup_metadata_read_only, dbclustergroup_metadata_admin, and dbclustergroup_super_admin. |
| 1235 (42000) | ORDER BY is not supported on this table: sort in your client. |
| 1235 (42000) | GROUP BY and HAVING are not supported on this table, or DISTINCT is not supported on this table. |
| 1235 (42000) | JOINs are not supported on this table, or Subqueries in FROM are not supported on this table. |
| 1235 (42000) | Locking reads (FOR UPDATE/FOR SHARE/LOCK IN SHARE MODE) are not supported on this table. |
| 1235 (42000) | AND/OR are not supported in the WHERE clause on this table: use the tuple form. |
| 1235 (42000) | The WHERE clause uses IN, !=, <, >, LIKE, IS NULL, or a range. The clause supports only column = 'value' or a tuple equality. |
| 1235 (42000) | Only literal values are allowed. No expressions, subqueries, or variables. |
| 1235 (42000) | db_cluster_identifier cannot be used in a WHERE clause on this table: filter by member_cluster_alias instead. |
| 1235 (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 (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 (42000) | Unknown column '<name>': the name isn't a column of data_mappings. |
| 1235 (42000) | This statement type is not supported: a PREPARE or binary-protocol prepare of the read. Send it as plain text. |
Related statements
For more information, see the following: