Scaleout SQL reference
A database cluster group for Aurora adds SQL statements that belong to the group rather than to the database engine itself. You run them at the routing endpoint to manage routing functions, scaleout tables, data mappings, data movement, and sessions. Member tables and the other objects on member clusters are standard objects of the engine that you create on each member cluster. For the engine statements that work through the routing endpoint, see Statement compatibility, drivers, ORMs, and tools.
The errors table of each statement lists the Aurora MySQL error number.
Topics
SQL commands
The following table lists every statement in this reference. The following pages group the statements: Routing function statements, Scaleout table statements, Data mapping statements, Data movement statements, and Session and EXPLAIN statements. No statement in this reference runs on a member cluster directly.
| Statement | What it does | Runs on |
|---|---|---|
| CREATE SCALEOUT ROUTING FUNCTION | Creates a routing function that maps a routing key to collocations. | Routing endpoint, unpinned session |
| DROP SCALEOUT ROUTING FUNCTION | Removes a routing function that no scaleout table uses. | Routing endpoint, unpinned session |
| SHOW CREATE SCALEOUT ROUTING FUNCTION | Returns the definition of one routing function. | Routing endpoint, unpinned session |
| SHOW SCALEOUT ROUTING FUNCTIONS | Lists the routing functions in the group. | Routing endpoint, unpinned session |
| CREATE SCALEOUT TABLE | Creates one table name at the routing endpoint for rows spread across member tables. | Routing endpoint, unpinned session |
| ALTER SCALEOUT TABLE | Switches the routing function, or adds and removes member tables. | Routing endpoint, unpinned session |
| DROP SCALEOUT TABLE | Removes a scaleout table. By default, member tables and rows stay. | Routing endpoint, unpinned session |
| SHOW CREATE SCALEOUT TABLE | Returns the definition of one scaleout table. | Routing endpoint, unpinned session |
| SHOW SCALEOUT TABLES | Lists the scaleout tables in the group. | Routing endpoint, unpinned session |
| SELECT … FROM dbclustergroup_sys.data_mappings | Reads the data mappings. | Routing endpoint, unpinned session |
| INSERT INTO dbclustergroup_sys.data_mappings | Adds a mapping that places a database or a table on a member cluster. | Routing endpoint, unpinned session, autocommit mode |
| UPDATE dbclustergroup_sys.data_mappings | Changes the cluster name behind a router name, or repoints or renames a collocation. | Routing endpoint, unpinned session, autocommit mode |
| DELETE FROM dbclustergroup_sys.data_mappings | Removes a mapping. The object on the member cluster stays. | Routing endpoint, unpinned session, autocommit mode |
| EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION | Checks a move of one collocation without starting it. | Routing endpoint, unpinned session |
| ALTER DBCLUSTERGROUP MOVE COLLOCATION | Starts a data movement job that moves one collocation to another member cluster. | Routing endpoint, unpinned session |
| ALTER DBCLUSTERGROUP CUTOVER JOB | Starts the cutover of a job in the CDC Replication phase. | Routing endpoint, unpinned session |
| ALTER DBCLUSTERGROUP CANCEL JOB | Cancels a data movement job. | Routing endpoint, unpinned session |
| SELECT … FROM dbclustergroup_data_movement.move_info | Reads the status of data movement jobs. There is no SHOW statement for moves. |
Routing endpoint, unpinned session |
| SET router_cluster_pin | Pins the session to one member cluster, or clears the pin. | Routing endpoint, pinned or unpinned session |
| SET scaleout_tables_preferred_member | Names the member table that answers SHOW CREATE TABLE and DESCRIBE for a scaleout table. |
Routing endpoint, unpinned session |
| EXPLAIN | Shows which member cluster a routed statement reaches, and that member cluster's plan. | Routing endpoint, unpinned session |
Where these statements run
Run these statements at the routing endpoint, in a session that isn't pinned to a member cluster. The exception is SET router_cluster_pin, which also clears a pin. A pinned session passes its statements through to its member cluster unchanged, and you can't reach a scaleout table through a pinned session.
A pinned session doesn't run a statement on a dbclustergroup_sys table or a SCALEOUT statement. It forwards the statement to the member cluster, where the statement fails. The member cluster doesn't recognize these keywords, so it returns a syntax error. There is no separate error code for this case. Clear the pin to run the statement.
Run each statement in autocommit mode, outside an explicit transaction:
-
Data mapping changes aren't transactional. On Aurora MySQL, the routing layer refuses a data mapping write inside a transaction, the write changes nothing, and the transaction stays open.
-
A data mapping or routing function change reaches the routing layer within a short time. A statement routed on an earlier mapping returns Aurora MySQL error 1412; the session stays open, and a retry routes on the new mapping. 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 the retry rule, see Transaction errors and retries. For more information, see Data mappings and collocations.
-
On Aurora MySQL, the routing layer refuses a routing function or scaleout table statement inside a transaction, with error 1179,
… is not allowed inside a transaction (opened by BEGIN/START TRANSACTION or SET autocommit=0). -
One multi-row
INSERTintodata_mappingsapplies all its rows or none.One statement can add, change, or remove at most 1,000 data mappings. For more information about the limit, see Routing metadata and naming limits.
-
A sequence of these statements isn't atomic. If one statement fails, the statements before it stay applied. Check the result of each statement before you send the next.
Privileges
The routing layer checks its own privileges for database cluster groups for Aurora for these statements. Each member cluster checks the data privileges of the member cluster user when a routed statement runs there. Each command page names the privilege that it needs.
| Privilege for database cluster groups for Aurora | Statements |
|---|---|
dbclustergroup_metadata_admin |
CREATE and DROP SCALEOUT ROUTING FUNCTION; CREATE, ALTER, and DROP SCALEOUT TABLE; SELECT, INSERT, UPDATE, and DELETE on dbclustergroup_sys.data_mappings |
dbclustergroup_move_admin |
ALTER DBCLUSTERGROUP MOVE COLLOCATION, EXPLAIN ALTER DBCLUSTERGROUP MOVE COLLOCATION, ALTER DBCLUSTERGROUP CUTOVER JOB, ALTER DBCLUSTERGROUP CANCEL JOB |
dbclustergroup_super_admin |
Every statement in this reference. It implies every other privilege for database cluster groups for Aurora. |
dbclustergroup_metadata_read_only |
Read data_mappings, member_cluster_mappings, and move_info, without write access. |
| None | SET SESSION router_cluster_pin, SET scaleout_tables_preferred_member, EXPLAIN of a routed statement, SHOW SCALEOUT TABLES, SHOW SCALEOUT ROUTING FUNCTIONS, SHOW CREATE SCALEOUT TABLE, and SHOW CREATE SCALEOUT ROUTING FUNCTION |
A statement without its privilege for database cluster groups for Aurora returns an access-denied error that names the missing privilege. For the privileges that manage router users, sessions, and connections (dbclustergroup_user_admin, dbclustergroup_process_admin, and dbclustergroup_connection_admin), see Router users.
Order of creation
Create the objects of a scaleout table in the following order, and drop them in the reverse order. For a worked example with loading, see Creating and loading a scaleout table.
To create the objects of a scaleout table
-
On each member cluster, through a direct connection or a session pinned to that member cluster, create its member tables. This step is optional if the member table already exists:
SET SESSION router_cluster_pin = 'member_cluster_alias';You can also write
', which selects the database asmember_cluster_alias@database'USEdoes. -
At the routing endpoint, map each member table with one table-level data mapping. Put each member table of one scaleout table in a different collocation. See INSERT INTO dbclustergroup_sys.data_mappings.
-
At the routing endpoint, create the routing function, which can name only collocations that a data mapping already created. See CREATE SCALEOUT ROUTING FUNCTION.
-
At the routing endpoint, create the scaleout table. See CREATE SCALEOUT TABLE.
-
At the routing endpoint, insert and read one key for each collocation, and check each with EXPLAIN. The routing rows of each
EXPLAINshow the member cluster that the key reaches.
To remove a scaleout table, run DROP SCALEOUT TABLE and then DROP SCALEOUT ROUTING FUNCTION. Then delete the data mappings, and drop the member tables on their member clusters. Note that DROP SCALEOUT TABLE doesn't remove the actual table on the member clusters. It only removes the metadata used to route queries through scaleout tables.
Keep your own record of every CREATE SCALEOUT ROUTING FUNCTION and CREATE SCALEOUT TABLE statement that you run. You read the definitions back only with the SHOW CREATE statements, and you can't restore the routing rules on their own.
Keep the record with your export of the data mappings. See Exporting the mappings before and after a change.
SQL reference conventions
The SQL reference for database cluster groups for Aurora uses the following conventions.
Syntax notation
The syntax blocks in this reference use the following notation.
CAPS-
Words in uppercase are keywords. Enter them as shown.
name-
Words in italics are placeholders. Replace them with your own value. Parameters and error texts write a placeholder as
<name>. [ ]-
Square brackets enclose an optional part. Don't enter the brackets.
{ a | b }-
Braces enclose a choice. Enter one of the values separated by vertical bars, without the braces.
...-
An ellipsis means that you can repeat the preceding item.
…-
In an error text or a statement in a table, an ellipsis marks text that the reference leaves out.
Names and quoting
The following rules apply to names and quoting in these statements.
-
In data mapping writes, every value is a quoted string,
member_cluster_aliasincluded. -
In the move statements, the collocation and the member cluster aliases are identifiers. On Aurora MySQL, enclose them in backticks, which an alias that contains a hyphen needs.
-
A job ID is a string literal in single quotes.
-
Collocation names are case-sensitive.
Examples
The examples use the following objects:
-
A database
db. -
Member cluster aliases
member-a,member-b, andmember-c. -
A routing function
orders_mod_fnwith the collocationscoll_0andcoll_1, and a routing functiontenant_rfwith twelve collocations,cg_00tocg_11. -
A scaleout table
orders, keyed oncustomer_id, whose member tables have the router table namesorders_s1andorders_s2, and a scaleout tableitemsthat stays with it.
Each example is a SQL statement that you run at the routing endpoint, unless the example says otherwise. Sample output follows the statement where it helps.
Statements that database cluster groups for Aurora don't support
The routing layer refuses the following statement forms. Use the alternative in the last column.
| Statement | Aurora MySQL | Instead |
|---|---|---|
ALTER SCALEOUT ROUTING FUNCTION … |
1064 | Create a new routing function and switch the table to it. See Changing a routing function. |
CREATE OR REPLACE SCALEOUT ROUTING FUNCTION … |
1235 | Create a new routing function and switch the table to it. |
PARTITION BY a function other than MOD, HASH, PREFIX, or COLUMN |
1305 | A MOD, HASH, PREFIX, or COLUMN function. For a scheme that doesn't map to one of these, connect with session pinning, or map each database with a data mapping. See Routing functions. |
Two actions in one ALTER SCALEOUT TABLE statement |
1064 | One action for each statement |
DESCRIBE SCALEOUT TABLE … |
1064 | SHOW CREATE SCALEOUT TABLE |
INSERT … SELECT into a scaleout table |
1235 | INSERT … VALUES with the routing key in each row |
An UPDATE that changes a routing key column |
1235 | Choose a routing key whose value doesn't change. See Choosing a routing key and routing function. |
Data definition on a scaleout table name, such as ALTER TABLE or CREATE INDEX |
1235 | Run the same statement on each member table, through a pinned session or a direct connection. See Running DDL through a session pin. |
GRANT or REVOKE on a scaleout table |
Refused | Grant the privileges on each member table, on its member cluster. |
LOCK TABLES on a scaleout table |
1235 | Lock the member tables on their member clusters, through a pinned session or a direct connection. |
| A view over a scaleout table | 1235 | Query the scaleout table with its routing key. |
LOAD DATA or another bulk load into a scaleout table at the routing endpoint |
1235 | Load each member table through a pinned session or a direct connection. See Loading data into member clusters. |
SHOW SCALEOUT TABLES or SHOW SCALEOUT ROUTING FUNCTIONS with a LIKE or WHERE clause |
Refused | Omit the LIKE or WHERE clause. |