要获取在命名连接中执行的可解释语句的执行计划,请使用以下语句:To obtain the execution plan for an explainable statement executing in a named connection, use this statement:
EXPLAIN [options] FOR CONNECTIONconnection_id;
EXPLAIN FOR CONNECTION 返回当前用于执行给定连接中查询的 EXPLAIN 信息。由于数据(及其支持的统计信息)的变化,它可能产生与在等效查询文本上运行 EXPLAIN 不同的结果。这种行为差异在诊断更短暂的性能问题时可能非常有用。例如,如果你在一个会话中运行一个执行时间很长的语句,在另一个会话中使用 EXPLAIN FOR
CONNECTION 可能会提供关于延迟原因的有用信息。EXPLAIN FOR CONNECTION returns
the EXPLAIN information that is
currently being used to execute a query in a given connection.
Because of changes to data (and supporting statistics) it may
produce a different result from running
EXPLAIN on the equivalent query
text. This difference in behavior can be useful in diagnosing
more transient performance problems. For example, if you are
running a statement in one session that is taking a long time to
complete, using EXPLAIN FOR
CONNECTION in another session may yield useful
information about the cause of the delay.
connection_id 是连接标识符,可从 INFORMATION_SCHEMA PROCESSLIST 表或 SHOW PROCESSLIST 语句中获取。如果您具有 PROCESS 权限,则可以为任何连接指定标识符。否则,您只能为自己的连接指定标识符。在所有情况下,您必须具有足够的权限才能解释指定连接上的查询。connection_id is the connection
identifier, as obtained from the
INFORMATION_SCHEMA
PROCESSLIST table or the
SHOW PROCESSLIST statement. If
you have the PROCESS privilege,
you can specify the identifier for any connection. Otherwise,
you can specify the identifier only for your own connections. In
all cases, you must have sufficient privileges to explain the
query on the specified connection.
如果指定的连接没有执行语句,则结果为空。否则,EXPLAIN FOR CONNECTION 仅适用于被执行语句可解释的情况。这包括 SELECT、DELETE、INSERT、REPLACE 和 UPDATE。(然而,EXPLAIN FOR CONNECTION 不适用于预处理语句,即使这些预处理语句属于上述类型。)If the named connection is not executing a statement, the result
is empty. Otherwise, EXPLAIN FOR CONNECTION
applies only if the statement being executed in the named
connection is explainable. This includes
SELECT,
DELETE,
INSERT,
REPLACE, and
UPDATE. (However,
EXPLAIN FOR CONNECTION does not work for
prepared statements, even prepared statements of those types.)
如果命名连接正在执行可解释的语句,输出将是使用EXPLAIN对该语句本身执行时所获得的内容。If the named connection is executing an explainable statement,
the output is what you would obtain by using
EXPLAIN on the statement itself.
如果命名连接正在执行不可解释的语句,则会发生错误。例如,您无法为当前会话命名连接标识符,因为EXPLAIN是不可解释的:If the named connection is executing a statement that is not
explainable, an error occurs. For example, you cannot name the
connection identifier for your current session because
EXPLAIN is not explainable:
mysql>SELECT CONNECTION_ID();+-----------------+ | CONNECTION_ID() | +-----------------+ | 373 | +-----------------+ 1 row in set (0.00 sec) mysql>EXPLAIN FOR CONNECTION 373;ERROR 1889 (HY000): EXPLAIN FOR CONNECTION command is supported only for SELECT/UPDATE/INSERT/DELETE/REPLACE
Com_explain_other状态变量表示执行的EXPLAIN FOR
CONNECTION语句的数量。The Com_explain_other status variable
indicates the number of
EXPLAIN FOR
CONNECTION statements executed.