EXPLAIN
Shows the plan that a member cluster of a database cluster group for Aurora uses for a routed statement.
Description
At the routing endpoint, EXPLAIN runs on the member cluster that the statement routes to. The routing layer has no planner and no table statistics, so it builds no plan and prints no cost of its own. The plan that you read is the member cluster's plan, in its native form, and it names objects by their cluster names. The routing layer doesn't rewrite cluster names back to router names, so you match a plan node to your query yourself.
By default, the routing layer adds its routing decision to the plan: the member cluster that it selected and the cluster name behind each router name. Use these routing rows to relate a plan node to your query. The routing rows keep the native column layout of the engine, so a client that reads the output by column position reads well-formed rows. Where a tool needs only the native plan, turn the routing rows off with dbclustergroup_explain_routing_details, for example SET SESSION dbclustergroup_explain_routing_details = OFF on Aurora MySQL.
On Aurora MySQL, the routing row appears only in TRADITIONAL output, as the first row, before the member cluster's plan: id 0, select_type ROUTER, table router, and the routing decision in Extra. FORMAT=JSON and FORMAT=TREE return the member cluster's plan with no routing information.
Syntax
The options are those of the engine's own EXPLAIN.
EXPLAIN [options]routable_statement;
Parameters and options
The statement takes the following parameters.
options-
Optional. The output options, as for
EXPLAINon a member cluster. On Aurora MySQL,FORMAT = { TRADITIONAL | JSON | TREE }. routable_statement-
A statement that the routing layer routes to one member cluster, on an object with any mapping type. For a scaleout table, the statement carries a routing key predicate that resolves it to one member cluster.
Where it runs and required privileges
Run the statement at the routing endpoint, in a session that isn't pinned. In a pinned session, and on a member cluster endpoint, the member cluster answers EXPLAIN itself, with no routing information.
The member cluster checks the member cluster user's privileges on the objects in the statement, as for the statement itself. For the privileges for database cluster groups for Aurora, see Privileges.
Usage notes
Keep the following in mind when you use the statement.
-
The plan comes from the writer of the member cluster, which runs routed statements.
-
The routing layer doesn't support
EXPLAINon a query over adbclustergroup_systable, because no member cluster holds a plan for it. -
An
EXPLAINwhose inner statement spans member clusters returns an error rather than a partial plan. -
EXPLAIN ANALYZEruns the statement on the member cluster, as it does on a direct connection. For a data change statement, it doesn't change any rows. On Aurora MySQL, for a multi-tableUPDATEorDELETE, it runs the plan and shows timing. For a single-tableUPDATEorDELETE, it returns<not executable by iterator executor>, with no plan and no timing. For anINSERTwithVALUESor aREPLACE, it shows the plan with no timing, and for anINSERT ... SELECTit times theSELECT. The timing covers the member cluster's execution only, not the time that the routing layer uses. -
A bare
ANALYZEwith no table has nothing to resolve, and the routing layer refuses anANALYZEof a scaleout table or of tables on more than one member cluster. To analyze a member table, use a pinned session or a direct connection.
EXPLAIN ANALYZE works on a scaleout table when a routing key predicate resolves the statement to one member cluster. A statement that doesn't resolve fails as the statement would without EXPLAIN.
Examples
The following example explains a read of one key of the scaleout table app.orders.
EXPLAIN SELECT * FROM app.orders WHERE tenant_id = 42 AND order_id = 7;
Errors
EXPLAIN follows the routing rules of the statement that it wraps, and returns the errors of that statement. For all errors from the routing layer, see Error codes for database cluster groups for Aurora.
On Aurora MySQL, the routing layer refuses the following EXPLAIN statements with error 1235 (SQLSTATE 42000) and runs nothing on a member cluster:
-
An
EXPLAINorEXPLAIN ANALYZEof a statement on adbclustergroup_systable, including a data mapping write. The message isThis statement type is not supported, and the write doesn't run. -
An
EXPLAINof a statement on a scaleout table that has no routing key predicate. The message isCannot resolve routing target: insufficient routing information. -
An
EXPLAINof a statement whose routing key values resolve to more than one member cluster. The message says that statements across member clusters aren't supported.
Related statements
For more information, see the following: