View a markdown version of this page

Statements the routing layer answers itself - Amazon Aurora

Statements the routing layer answers itself

The routing layer of a database cluster group for Aurora sends each routed statement to the one member cluster that holds its data. The routing layer answers some statements from its own state, and they never reach a member cluster. These include some table-less SELECT statements, the session settings that it holds, and reads of the group's system tables. A successful answer to one of these shows that the routing endpoint is reachable, not that a member cluster is.

In a session pinned to a member cluster, these statements pass through to that member cluster, which answers them. For more information, see Session pinning.

Summary

The following table summarizes what answers common statements in an unpinned session at the routing endpoint.

Statement Answered by Notes
SELECT VERSION() Routing layer The MySQL version part of the group's minimum engine version, not each member cluster's
SELECT 1, SELECT DATABASE(), and a fixed set of functions Routing layer See Table-less SELECT statements
SELECT LAST_INSERT_ID(), ROW_COUNT(), FOUND_ROWS() Member cluster Routed to the member cluster that served the statement they report on
SET of a session variable Routing layer Buffered and replayed on each member session. See Supported system variables
SHOW VARIABLES, SELECT @@variable Routing layer Answered from the session state that the routing layer tracks
SHOW DATABASES, SHOW FULL TABLES Routing layer The router names from the data mappings, plus the system schemas dbclustergroup_sys and dbclustergroup_data_movement
Metadata SHOW statements, such as SHOW COLUMNS and SHOW CREATE TABLE Routing layer Only objects that have a data mapping. See SHOW, KILL, and catalog reads
information_schema reads Routing layer A scaleout table appears under its own name, with the values of one member table. See SHOW, KILL, and catalog reads
SHOW WARNINGS, SHOW ERRORS Member cluster From the member cluster that ran the previous statement. Send each one immediately after the statement that it reports on
SHOW COLLATION, SHOW CHARACTER SET Routing layer Not the definitive list of what the routing layer accepts. See Character sets and collations
SHOW GRANTS Routing layer Router users and privileges for database cluster groups for Aurora
Reads of dbclustergroup_sys and dbclustergroup_data_movement, SHOW SCALEOUT statements Routing layer See System tables for database cluster groups for Aurora
SHOW PROCESSLIST, SHOW FULL PROCESSLIST Refused Error 1235. Query router_processlist instead
KILL QUERY, KILL CONNECTION Routing layer Sessions at the routing endpoint, from any connection to the routing endpoint
SHOW STATUS, SHOW GLOBAL STATUS Routing layer The column names with no rows. See Status variables
SHOW ENGINE INNODB STATUS Not answered An error in a session that isn't pinned. Pin the session or connect to the member cluster. See Status variables

Table-less SELECT statements

A table-less SELECT names no table, such as the health check that a connection pool or driver sends, or a read of a function or a variable. The routing layer answers a fixed set of these statements, such as health checks and the functions that the following table lists. It refuses the others. On Aurora MySQL, the version that the routing layer returns is the MySQL version part of the group's minimum engine version, not each member cluster's. Read each member cluster's EngineVersion from describe-db-clusters, or run SELECT VERSION() in a session pinned to that member cluster, or in a SELECT on one of its tables that has rows.

The following table shows how the routing layer answers a SELECT with no table.

Statement At the routing endpoint
SELECT 1 Answered by the routing layer. It reaches no member cluster, so it doesn't test routing
SELECT VERSION() The MySQL version part of the group's minimum engine version, not each member cluster's
SELECT DATABASE(), SCHEMA() The router database name that the session named, not the cluster database name
NOW(), CURRENT_TIMESTAMP(), LOCALTIME(), LOCALTIMESTAMP(), CURDATE(), CURRENT_DATE(), CURTIME(), CURRENT_TIME(), UTC_TIMESTAMP(), UTC_DATE(), UTC_TIME(), CONVERT_TZ(), USER(), SESSION_USER(), SYSTEM_USER(), CURRENT_USER(), CONNECTION_ID(), DBCLUSTERGROUP_TRACE_ID(), UUID(), HEX(), UNHEX(), UUID_TO_BIN(), BIN_TO_UUID(), MOD(), CONCAT(), CONCAT_WS(), CAST(), CONVERT() USING Evaluated by the routing layer. CONNECTION_ID() returns the session's global connection ID, the ID in router_processlist. CONVERT() USING takes utf8mb4 only
SELECT LAST_INSERT_ID(), ROW_COUNT(), FOUND_ROWS() Routed to the member cluster that served the statement they report on
SELECT @@variable The session value that the routing layer tracks. See Supported system variables
Literals or arithmetic only, such as SELECT 1+1 or SELECT 'x', DO, and a function outside the set that the routing layer evaluates, such as SLEEP(), with no table Refused with error 1235 (SQLSTATE 42000), No member cluster could be resolved for this query. Compute the value in your application and pass it as a literal. For a pool health check, use SELECT 1

Inside a statement that names a mapped table, any function works, because the member cluster evaluates it.

SHOW, KILL, and catalog reads

At the routing endpoint, the catalog shows your mapped names, by router name, and the routing layer's own state. For a member cluster's engine state, sessions, or unmapped objects, read the member cluster directly, or use a session pin. On a member cluster, every catalog read shows cluster names. For how tools and ORMs are affected, see Statement compatibility.

Session statements, SHOW, and KILL

The following table shows how the routing layer answers session statements, SHOW, and KILL.

Statement At the routing endpoint
SET of a session variable Buffered by the routing layer and replayed on each member session. See Session variables the routing layer holds and forwards
SET SESSION router_cluster_pin, SET SESSION scaleout_tables_preferred_member Handled by the routing layer
Reads of dbclustergroup_sys and dbclustergroup_data_movement Answered by the routing layer
SHOW DATABASES The router names from the data mappings, plus the system schemas dbclustergroup_sys and dbclustergroup_data_movement
SHOW VARIABLES, SHOW SESSION VARIABLES Answered from the session state that the routing layer tracks
SHOW COLLATION, SHOW CHARACTER SET Answered, but not the definitive list of what the routing layer accepts. See Character sets and collations
SHOW WARNINGS, SHOW ERRORS The detail rows from the member cluster that ran the previous statement
SHOW GRANTS, SHOW GRANTS FOR Answered from the router users and privileges for database cluster groups for Aurora. SHOW GRANTS FOR another user needs dbclustergroup_user_admin
SHOW PROCESSLIST, SHOW FULL PROCESSLIST Refused with error 1235. Query router_processlist instead
KILL CONNECTION id Ends the session at the routing endpoint and its member cluster connections. Send it on any connection to the routing endpoint. Ending another router user's session needs dbclustergroup_connection_admin
KILL QUERY id Cancels the running statement on each member cluster that runs it, and leaves the session open

If you end a routed session's member cluster session directly on the member cluster, with KILL or CALL mysql.rds_kill, what happens depends on the session's state. While that session has an open transaction, a running statement, or prepared statements on it, the routing layer doesn't open a replacement and ends the whole session at the routing endpoint. The member cluster rolls back an open transaction, and the client's next statement gets error 1927 (Connection was killed) or a lost connection (2013). A member cluster session that was idle, with none of those, can be replaced at the session's next statement on that member cluster. For a pinned session, the client gets error 1053, The pinned target is unreachable; reconnect and pin again, when no statement was running, or a lost connection (2013) if a statement was running. If you cancel the running statement directly on the member cluster with KILL QUERY, the statement fails with error 1317, and the session and its open transaction stay open.

Catalog reads that the routing layer answers

The routing layer answers the following catalog reads. A metadata SHOW statement returns only objects that have a data mapping: a database-level mapping exposes every object in that database, and a table-level mapping exposes only the tables that it names.

Read At the routing endpoint
SHOW TABLES, SHOW FULL TABLES, SHOW COLUMNS, SHOW INDEX, and SHOW CREATE TABLE for a mapped object Answered. SHOW TABLES under a table-level mapping is built from the data mappings, by router name. Under a database-level mapping, and for SHOW CREATE TABLE, SHOW COLUMNS, and SHOW INDEX, the routing layer sends the statement to a member cluster, and the result shows that member cluster's names for databases and tables
information_schema for mapped objects Answered from the member clusters that hold mapped objects, with databases and tables named by their router names. Some queries across member clusters, for example with a locking clause, are refused with error 1235
information_schema.tables A scaleout table appears under its own name, with the values of one member table. TABLE_ROWS, DATA_LENGTH, and the other statistics are that member table's values, not sums or averages. If a member cluster doesn't answer, the statement fails with an error and returns no rows
SHOW CREATE SCALEOUT TABLE, SHOW CREATE SCALEOUT ROUTING FUNCTION, SHOW SCALEOUT TABLES, SHOW SCALEOUT ROUTING FUNCTIONS Answered
SHOW TABLE STATUS For a mapped database on one member cluster, sent to that member cluster. The rows name tables by their cluster names. Under table-level mappings, only the mapped tables are listed. If the database's tables are on more than one member cluster, refused with ERROR 1235 (42000): No member cluster could be resolved for this query. For dbclustergroup_sys and dbclustergroup_data_movement, the routing layer answers one row for each system table, with Rows 0 and no sizes
SHOW CREATE DATABASE, SHOW CREATE SCHEMA Sent to the member cluster that holds the database. The result shows the database's cluster name, in the Database column and in the CREATE DATABASE text. If the database's tables are on more than one member cluster, refused with ERROR 1235 (42000): No member cluster could be resolved for this query. For dbclustergroup_sys and dbclustergroup_data_movement, refused with ERROR 1235 (42000): Virtual database 'dbclustergroup_sys' definition is not available
information_schema.ROUTINES, PARAMETERS, and VIEWS Answered, with databases named by their router names. ROUTINE_DEFINITION and VIEW_DEFINITION are the text stored on the member cluster, so a database name written inside a body is its cluster name
information_schema.SCHEMATA Answered, by router name. A database whose tables are on more than one member cluster appears once for each of those member clusters
information_schema.STATISTICS, KEY_COLUMN_USAGE, TABLE_CONSTRAINTS, REFERENTIAL_CONSTRAINTS, and CHECK_CONSTRAINTS Answered, with databases and tables named by their router names, including the table that a foreign key references
information_schema.CHARACTER_SETS, COLLATIONS, and KEYWORDS Sent unchanged to one member cluster. The rows describe the engine, not what the routing layer accepts
Catalog reads to run on member clusters

The following catalog reads return no rows, an error, or the values of one member cluster at the routing endpoint. The last column says where to read the information instead.

Read At the routing endpoint Read it instead
information_schema.innodb_trx, and every other view whose rows differ by member cluster ERROR 1235 (42000): This catalog query is not supported A pinned session, or the member cluster endpoint
SHOW STATUS, SHOW SESSION STATUS, SHOW GLOBAL STATUS, and SHOW ENGINE INNODB STATUS SHOW STATUS in any scope returns its two columns and no rows. The others return an error Each member cluster
performance_schema, sys, and mysql queries Return an error unless accessed through a data mapping with a different router database name A pinned session, or the member cluster endpoint
information_schema for a scaleout table The values of one member table, not of the whole scaleout table SHOW SCALEOUT TABLES and SHOW CREATE SCALEOUT TABLE, or a pinned session for the member tables
SHOW CREATE TABLE, SHOW COLUMNS, SHOW INDEX, and DESCRIBE of a scaleout table Error 1146, unless scaleout_tables_preferred_member names a member table Set scaleout_tables_preferred_member, or describe a member table on its member cluster
information_schema.TRIGGERS, EVENTS, PARTITIONS, ENGINES, PLUGINS, VIEW_TABLE_USAGE, VIEW_ROUTINE_USAGE, and the *_EXTENSIONS views ERROR 1235 (42000): Querying 'information_schema.TRIGGERS' is not supported. The message names the view as you wrote it A pinned session, or the member cluster endpoint. Filter on the cluster name of the database
information_schema privilege and role views, such as USER_PRIVILEGES, SCHEMA_PRIVILEGES, TABLE_PRIVILEGES, and APPLICABLE_ROLES ERROR 1235 (42000): This catalog query is not supported SHOW GRANTS at the routing endpoint
SHOW TRIGGERS, SHOW EVENTS, SHOW CREATE VIEW, SHOW CREATE PROCEDURE, SHOW CREATE FUNCTION, SHOW CREATE TRIGGER, and SHOW CREATE EVENT ERROR 1235 (42000): This statement type is not supported A pinned session, or the member cluster endpoint
SHOW PROCEDURE STATUS, SHOW FUNCTION STATUS, SHOW PLUGINS, and SHOW OPEN TABLES ERROR 1235 (42000): This operation is not supported in query routing mode. Use the cluster endpoint directly or pin the session to a member cluster. A WHERE filter with =, such as WHERE Db = 'db', fails first with ERROR 1064 (42000): You have an error in your SQL syntax A pinned session, or the member cluster endpoint. information_schema.ROUTINES at the routing endpoint lists routines by router name
SHOW ENGINES, SHOW BINARY LOG STATUS, SHOW BINARY LOGS, SHOW REPLICA STATUS, and SHOW REPLICAS ERROR 1105 (HY000): An internal error occurred while processing the statement. Each member cluster
An unmapped database or table Not found. For a table, ERROR 1146 (42S02): Table 'db.tbl' doesn't exist The member cluster that holds it

At the routing endpoint, a SHOW statement that the routing layer sends to a member cluster returns that member cluster's result. Database and table names in it are cluster names, not router names. The system schemas dbclustergroup_sys and dbclustergroup_data_movement exist only in the routing layer. SHOW TABLES, SHOW TABLE STATUS, SHOW COLUMNS, and SHOW INDEX answer for them, but SHOW CREATE DATABASE and SHOW CREATE TABLE are refused with error 1235.

At the routing endpoint, SHOW ENGINES, SHOW BINARY LOGS, SHOW BINARY LOG STATUS, SHOW REPLICA STATUS, and SHOW REPLICAS return error 1105 (SQLSTATE HY000), An internal error occurred while processing the statement., because the answer belongs to one DB cluster and the routing layer doesn't forward these statements. The session isn't affected. To run these statements, connect to the member cluster's own endpoint, or pin the session to a member cluster.

To inspect a member cluster's engine state, sessions, locks, or full catalog, connect to its cluster endpoint. For per-instance performance_schema, connect to an instance endpoint. Find the endpoint from the db_cluster_identifier in member_cluster_mappings. A session pin to the member cluster gives you the same reads through the routing endpoint.

SELECT 1 checks that the routing endpoint answers, but it reaches no member cluster. To test routing, query a mapped table by its router name.