Statement compatibility
The SQL that you can run with a database cluster group for Aurora depends on how you connect:
-
A routed session at the routing endpoint. The routing layer runs a statement when it can resolve the statement to one member cluster. Each statement and transaction runs on the member cluster that holds its data. To work with data on several member clusters, run a statement on each one and combine the results in your application.
-
A pinned session at the routing endpoint. A session pin passes statements through to one member cluster, so anything that the member cluster accepts runs there, including DDL, administrative statements, and catalog reads. For more information, see Session pinning.
-
A direct connection to a member cluster. A direct connection carries the full SQL surface of a standalone Aurora DB cluster, with cluster names.
For when to use each connection, see Connecting to the routing endpoint. For the statements that belong to the group itself, such as data mapping writes and CREATE SCALEOUT TABLE, see Scaleout SQL reference.
Reading the tables
The tables in this topic use the following grades.
- Supported
-
Runs in that kind of connection.
- Conditional
-
Runs with the restrictions in the notes.
- Answered by the routing layer
-
The routing layer replies from its own state, and no member cluster sees the statement. See Statements the routing layer answers itself.
- Not supported in query routing
-
Runs on a direct connection or in a pinned session. In a routed session, the routing layer refuses it and runs nothing.
- Not supported
-
Doesn't run in that kind of connection.
- Not applicable
-
The combination doesn't arise.
- Varies by statement
-
The grade differs for each statement in the group.
When the routing layer can't resolve a statement to exactly one member cluster, it refuses the statement and returns no partial result. Aurora MySQL returns error 1235 (SQLSTATE 42000). One code covers several causes, so handle the code, not the message text. A statement that the routing layer can't parse returns error 1064 instead. To decode an error, see Error codes for database cluster groups for Aurora.
Statement support matrix
DDL runs only on a direct connection or in a pinned session.
Aurora MySQL grades each statement by the following access patterns. Direct cluster and cluster pin mean a connection to a member cluster endpoint or a session pinned to one member cluster. Database distribution and table distribution mean query routing, where the routing layer resolves the member cluster from the database name or the table name. Multi cluster means a statement whose objects resolve to more than one member cluster.
To reach one member cluster with the full surface, pin the session. Query routing resolves a routing key from equality and IN predicates only. In the Multi cluster pattern, every statement is Not supported in query routing. In the following table, the statement groups follow the chapters of the MySQL reference manual.
| Statements | Direct cluster and cluster pin | Database distribution | Table distribution |
|---|---|---|---|
| Data types: numeric, date and time, string, spatial, and JSON. Built-in functions and operators. | Supported | Supported | Supported |
Queries: SELECT, TABLE, VALUES, subqueries, common table expressions (WITH), parenthesized query expressions, and UNION, INTERSECT, and EXCEPT |
Supported | Supported | Supported |
Data changes: INSERT, UPDATE, DELETE, and REPLACE |
Supported | Supported | Supported |
CALL of a stored procedure |
Supported | Supported | Not supported in query routing |
Loads: LOAD DATA, LOAD XML, and LOAD DATA FROM S3, into a table with a database-level or table-level mapping |
Supported | Supported | Supported |
Transactions: START TRANSACTION, COMMIT, ROLLBACK, SAVEPOINT, ROLLBACK TO SAVEPOINT, RELEASE SAVEPOINT, SET TRANSACTION, LOCK TABLES, and UNLOCK TABLES |
Supported | Supported | Supported |
Prepared statements: PREPARE, EXECUTE, and DEALLOCATE PREPARE |
Supported | Supported | Supported |
Utility and administration: table maintenance statements, SET, DESCRIBE, EXPLAIN, and USE |
Supported | Supported | Supported |
SHOW |
Supported | Varies by statement | Varies by statement |
HELP and FLUSH |
Supported | Not supported in query routing | Not supported in query routing |
information_schema, AUTO_INCREMENT, check constraints, generated columns, and foreign keys within one member cluster |
Supported | Supported | Supported |
performance_schema, mysql, and sys |
Supported | Not routed under their own names. Routable like any other database through a data mapping with a different router database name | Not routed under their own names. Routable like any other database through a data mapping with a different router database name |
Data definition: CREATE, ALTER, and DROP of databases, tables, indexes, views, triggers, events, procedures, functions, tablespaces, logfile groups, servers, and spatial reference systems; RENAME TABLE; and TRUNCATE TABLE |
Supported | Not supported in query routing | Not supported in query routing |
DO, HANDLER, and XA transactions |
Supported | Not supported in query routing | Not supported in query routing |
Compound statements: BEGIN ... END, statement labels, DECLARE, variables in stored programs, flow control, cursors, and condition handling |
Supported | Not supported in query routing | Not supported in query routing |
Component, plugin, and loadable function statements. Only the cluster's primary user can run CREATE FUNCTION ... SONAME. |
Supported | Not supported in query routing | Not supported in query routing |
| Account management for member cluster users | Supported | Not applicable | Not applicable |
| Other administrative statements | Varies by statement | Varies by statement | Varies by statement |
IMPORT TABLE, LOCK INSTANCE FOR BACKUP, resource group management, and CLONE |
Not applicable | Not applicable | Not applicable |
Under a database-level mapping, the routing layer sends CALL to the member cluster of the procedure's database. LOCK TABLES runs when every table that it names is on one member cluster and none is a scaleout table. You can't update a routing key column, and the routing layer refuses a statement that would move a row to another member cluster.
You manage router users at the routing endpoint with CREATE USER, ALTER USER, DROP USER, RENAME USER, SET PASSWORD, GRANT, and REVOKE (see Router users and routing layer privileges). Each of these statements commits on its own, so the routing layer refuses it with error 1179 inside an open transaction. Commit or roll back first. A bulk load into a scaleout table doesn't run through the routing layer (see Loading data into member clusters).
In query routing, the routing layer supports the following SHOW statements: SHOW CHARACTER SET, SHOW COLLATION, SHOW COLUMNS, SHOW CREATE DATABASE, SHOW CREATE TABLE, SHOW CREATE USER, SHOW DATABASES, SHOW ERRORS, SHOW GRANTS, SHOW INDEX, SHOW PRIVILEGES, SHOW TABLE STATUS, SHOW TABLES, SHOW VARIABLES, SHOW WARNINGS, SHOW SCALEOUT TABLES, and SHOW SCALEOUT ROUTING FUNCTIONS. SHOW STATUS returns no rows. Other SHOW statements return an error; to run them, pin the session to a member cluster.
Text-protocol and binary-protocol prepared statements are supported on tables with database-level and table-level mappings. In a session that isn't pinned, the routing layer refuses the following binary-protocol commands with error 1235: server-side cursors (COM_STMT_FETCH), long data (COM_STMT_SEND_LONG_DATA), and a reset (COM_STMT_RESET) of a statement that the routing layer forwarded to a member cluster. Some drivers send a reset before every execute, so use a driver setting that doesn't, or pin the session. These commands work in a pinned session.
Statements by mapping type
In a routed session, the kind of data mapping decides which statements resolve to one member cluster:
-
Database-level mappings (Aurora MySQL). Every object in the database is on one member cluster. A statement that stays inside objects on one member cluster runs as it does on that member cluster, including joins, subqueries, common table expressions, data changes, transactions, savepoints, session variables, and
EXPLAIN. -
Table-level mappings. The data mappings place each table on its own, and a statement runs when every table that it names is on one member cluster.
-
Scaleout tables. Every statement on a scaleout table carries its routing key as an equality or
INpredicate with literal values that resolve to one member cluster. Under aCOLUMNrouting function, a range comparison orBETWEENalso resolves when oneVALUES IN RANGEcollocation holds the whole range. The key must be an integer,DATE,DATETIME, orTIMESTAMPcolumn. Any other range,LIKE, a null test, or a function or arithmetic on the key column doesn't resolve one. You can't update a routing key column, so insert the row under the new key and delete the old row. For the routing functions, see Routing functions. For the data types that a routing key can use, see Engine settings for the routing key.
The routing layer refuses an INSERT ... SELECT and an INSERT ... SET into a scaleout table with error 1235. Insert with VALUES, and include the routing key column in every row.
Each member cluster generates AUTO_INCREMENT and sequence values on its own, so a value can repeat between member clusters. Generate keys in your application, for example as UUIDs. The member cluster enforces every data privilege, so the grants of the member cluster user with the same name decide what a routed session can read and write (see Router users and routing layer privileges).
Joins and statements across member clusters
In a routed session, a join, UNION, or subquery runs when every object in it resolves to one member cluster. The following combinations resolve.
| Combination | Result |
|---|---|
| Databases with database-level mappings, and tables with table-level mappings, all on the same member cluster | Runs on that member cluster |
| Scaleout tables whose keys in the statement resolve to one member cluster | Runs on that member cluster |
A key in WHERE for one scaleout table, carried to the others by ON equalities on the key column, also through LEFT JOIN on the preserved side and through several joins |
Resolves for every table that it reaches |
A self-join over one scaleout table on the key, or a WITH RECURSIVE query with the key in the anchor member |
Runs on that member cluster |
A statement that reads or writes objects on different member clusters returns error 1235 on Aurora MySQL. Combine the results in your application, or keep the rows in one collocation. A join between a scaleout table and a table with a database-level or table-level mapping doesn't route, so split the statement. In a transaction, the routing layer refuses a statement that resolves to a second member cluster, and the transaction stays open. To keep joins inside one collocation, see Designing schemas and queries for one member cluster. For transactions and retries, see Running queries and transactions through the routing layer.
Where a statement needs data from several member clusters, Aurora DSQL is a complementary option for distributed queries and transactions.
Catalog reads at the routing endpoint
A pinned session or a direct connection reads the full catalog of one member cluster, with cluster names. At the routing endpoint, the routing layer answers information_schema reads, SHOW DATABASES, and SHOW FULL TABLES with the router names from the data mappings. A scaleout table appears in information_schema with the values of one of its member tables, so its TABLE_ROWS and sizes aren't totals. To read its definition, run SHOW CREATE SCALEOUT TABLE, or introspect it over a pinned session. For the catalog reads that the routing layer answers, see SHOW, KILL, and catalog reads.
The routing layer answers SELECT 1 without a member cluster, so it checks only that the routing endpoint answers. To test routing, query a mapped table by its router name.
Protocol features
Applications connect to the routing endpoint with standard MySQL drivers, as they connect to an Aurora DB cluster endpoint. The following table describes protocol features.
| Feature | Aurora MySQL |
|---|---|
| Prepared statements on a scaleout table | Server-side prepared statements run on scaleout tables; the routing layer resolves the member cluster at each execute. A text PREPARE from before the pin keeps working when its tables are on the pinned member cluster and none is a scaleout table. Any other text PREPARE from before the pin returns error 4163 when you run it. Its message is User-level lock name 'Prepared statement cannot run in the current pin state. ' should not exceed 64 characters., where the lock name is the message padded with spaces to 65 characters. A binary-protocol prepared statement from before the pin returns error 1235 (Prepared statement cannot run in the current pin state.). Prepare either kind again after the pin. |
| Prepared statements on a system table | Send each read of a dbclustergroup_sys table as plain text. The routing layer refuses a text PREPARE and a binary-protocol prepare of the read with error 1235, This statement type is not supported. |
| Several statements in one request | Run when the client enables CLIENT_MULTI_STATEMENTS (for example allowMultiQueries=true), up to 256 statements in one request. A request with more statements returns error 1235. Without the option, a request with several statements returns error 1064. |
| Character set | Declare utf8mb4 in the connection handshake. |
| Protocol compression | Turn off compression in the client. |
Connection reset (COM_RESET_CONNECTION) |
Keeps the connection ID and clears user variables, routing layer variables, and the session pin, then ends its member cluster sessions. The connection's next statement opens new member cluster sessions. |
Changing the user on an open connection (COM_CHANGE_USER) |
Signs in again as another router user. |
| Query attributes | Not supported. The routing endpoint doesn't advertise query attributes, so drivers send queries without them. |
Server-side cursors (COM_STMT_FETCH) and long data (COM_STMT_SEND_LONG_DATA) |
In a session that isn't pinned, both return error 1235. Both work in a pinned session. |
For character sets and collations, see Character sets and collations. For the driver and pool settings that go with these features, see Driver and ORM settings and Managing connections.