View a markdown version of this page

INSERT INTO dbclustergroup_sys.data_mappings - Amazon Aurora

INSERT INTO dbclustergroup_sys.data_mappings

Use INSERT INTO dbclustergroup_sys.data_mappings to place a database or a table on a member cluster of a database cluster group for Aurora.

Description

Adds data mappings: rows that place a database or a table on a member cluster, under a router name, in a collocation. A mapping write moves no data. It changes only where the routing layer sends statements for that object.

For the columns of the table, see data_mappings. For the concepts, see Data mappings and collocations. For the task, see Changing data mappings.

Syntax

The columns that you name differ, as the parameters describe.

INSERT INTO dbclustergroup_sys.data_mappings (column [, column ...]) VALUES ('value' [, 'value' ...]) [, ('value' [, ...]) ...];

Parameters and options

Each parameter is a column of data_mappings. The column list is required, and every value is a single-quoted string.

cluster_db_name

Required. The database name on the member cluster (the cluster database name).

cluster_table_name

The table name on the member cluster. Omit it for a database-level mapping.

router_db_name

The database name that applications use through the routing endpoint. Defaults to cluster_db_name.

router_table_name

The table name that applications use through the routing endpoint (the router table name). Defaults to cluster_table_name. For a member table of a scaleout table, it's the name that the MEMBERS clause of CREATE SCALEOUT TABLE names.

member_cluster_alias

Required. A member_cluster_alias value that dbclustergroup_sys.member_cluster_mappings lists. Copy it from the listing, and don't derive it from a DB cluster identifier. The routing layer refuses a member cluster alias that the listing doesn't show and writes no row. The listing shows a member cluster that is still joining only after it can route.

router_collocation_group

The collocation of the object. Name a new collocation, or a collocation that is already on the same member cluster. If you omit it, the mapping takes the member_cluster_alias value as its collocation, so every object mapped that way on one member cluster moves together. Name a collocation where you want finer control.

db_cluster_identifier

Read-only. Leave it out.

Where it runs and required privileges

Run the statement at the routing endpoint, in a session in query routing mode that isn't pinned, and outside a transaction. A pinned session passes the statement through to its member cluster, where it fails. On Aurora MySQL, the routing layer refuses a mapping write inside a transaction, and a session with autocommit=0 counts as an open transaction. Run SET autocommit = 1, or commit, before the write.

The routing layer accepts a read of data_mappings inside a transaction.

The router user needs dbclustergroup_metadata_admin or dbclustergroup_super_admin. Reading data_mappings with SELECT needs dbclustergroup_metadata_read_only, dbclustergroup_metadata_admin, or dbclustergroup_super_admin. Without one, the read fails with error 1227. 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. A statement that the routing layer routed on an older mapping returns a retryable error, and a retry routes on the new mapping. For what an open session and an open transaction see, see Applying data mapping changes.

  • Mapping writes aren't transactional. A multi-row INSERT applies all its rows or none, but BEGIN and COMMIT don't group separate statements, and a failed statement doesn't undo the statements before it. Put each set of mappings that must appear together in one multi-row INSERT, so that each intermediate state still routes.

  • One INSERT can add at most 1,000 mappings. A larger statement fails with error 1235 and adds nothing, for example put of 1500 entries exceeds the per-request limit of 1000; split the write into smaller requests. For more information about the limit, see Routing metadata and naming limits.

  • Create the object on the member cluster first. The routing layer doesn't create it, and a mapping with a wrong cluster name registers without an error. Check each pair of cluster names against the member cluster that the member cluster alias points at.

  • A database has one mapping level. While a database has a database-level mapping, the routing layer refuses a table-level mapping in it. See Using database-level and table-level mappings.

  • Every fully qualified router name (database and table) is unique across the group. An object on a member cluster has one mapping. To change its router name, update the row. See UPDATE dbclustergroup_sys.data_mappings.

  • A mapping names explicit values, and the routing layer reads % and * as ordinary characters, not as patterns. To place every table of a database, map the database.

  • Database and table names can't be empty and can't contain a period, white space, a control character, a character above U+FFFF, or any of `, ", ', \, ,, (, /*, and */. A collocation name accepts letters, digits, _, $, and -. The routing layer reserves the names of its system tables, in any letter case and in any name column: dbclustergroup_sys, data_mappings, member_cluster_mappings, router_user_definition, dbclustergroup_data_movement, move_info, and router_processlist. A router_collocation_group value can use them.

  • Export the mappings before and after every change. See Exporting the mappings before and after a change.

A router_collocation_group value is stored as you write it and compared case-sensitively, so C1 and c1 are two collocations. It can contain letters, digits, _, $, and -.

While a data movement job moves a collocation, the routing layer refuses a mapping write that touches the collocation or any object in it, with error 1205 (Metadata for ... is being changed by another operation).

A mapping change needs an available writer instance on every member cluster that it affects. This includes both the old and the new member cluster when you repoint a mapping. If one has no available writer, the change fails and nothing changes. The member clusters don't need to be reachable through the routing endpoint, because the routing layer reaches them directly.

Examples

The following examples map two tables of the database app_db on one member cluster, each in its own collocation, in one multi-row INSERT, and read the rows back. Filter a read with one equality or one tuple equality, and sort in your client. For the read, see SELECT FROM dbclustergroup_sys.data_mappings.

INSERT INTO dbclustergroup_sys.data_mappings (cluster_db_name, cluster_table_name, router_db_name, router_table_name, member_cluster_alias, router_collocation_group) VALUES ('app_db', 'orders', 'app_db', 'orders', 'member-a', 'cg_orders'), ('app_db', 'customers', 'app_db', 'customers', 'member-a', 'cg_customers'); SELECT * FROM dbclustergroup_sys.data_mappings WHERE (router_db_name, router_table_name) = ('app_db', 'orders');

The following example maps the whole database global on member-a.

INSERT INTO dbclustergroup_sys.data_mappings (cluster_db_name, router_db_name, member_cluster_alias, router_collocation_group) VALUES ('global', 'global', 'member-a', 'cg_global');

Errors

The statement can return the following errors. A refused statement writes no row. 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.
64004 (42000) Member cluster '<alias>' doesn't exist: the member_cluster_alias value isn't in member_cluster_mappings.
64060 (42000) The database already has a mapping of the other level. One database holds database-level or table-level mappings, not both.
64062 (42000) The collocation is on another member cluster.
64021 (42000) Table '<db>.<table>' already has a data mapping (Database '<db>' ... for a database-level mapping): the router name is already mapped.
1235 (42000) physical table '<db>.<table>' is already mapped on member cluster '<alias>' as '<router name>' (physical database '<db>' ... for a database-level mapping), or physical table '<db>.<table>' on member cluster '<alias>' overlaps the database mapping '<router name>' -> '<db>': the object on that member cluster already has a mapping, under the router name in the message.
1235 (42000) Column 'cluster_db_name' cannot be empty, or Column 'member_cluster_alias' cannot be NULL: a required column is missing.
1235 (42000) Column list is required for INSERT, or Only simple INSERT INTO ... VALUES (...) is supported: the statement has no column list, or uses REPLACE, INSERT IGNORE, ON DUPLICATE KEY UPDATE, or INSERT ... SET. To change a mapping, use UPDATE.
1235 (42000) Reserved identifier: '<name>' cannot be used as a name: a name is reserved.
1235 (42000) put of <n> entries exceeds the per-request limit of 1000; split the write into smaller requests: your statement adds more than 1,000 mappings, so it adds nothing. Split the rows across several statements.
1235 (42000) db_cluster_identifier is read-only: the statement sets db_cluster_identifier.
1059 (42000) A name is longer than 64 characters.
1412 (HY000) After a mapping change, a statement that the routing layer routed on the older mapping returns this error. On Aurora MySQL, the statement ends and an open transaction stays open, so retry the statement or the transaction.

For more information, see the following: