Skip to content
MySQL plug-in

Jobs

View Markdown

This chapter describes the job types the plug-in adds. Topics: 8.1 Run EXPLAIN

The plug-in adds one job type, MySQL - Run Explain Plan (ip_mysql_run_explain). It runs EXPLAIN for a statement you supply against one monitored MySQL Database target and returns the execution plan.

The job is read-only: it asks the server for the statement’s plan and does not execute the statement.

ItemValue
Job typeip_mysql_run_explain (MySQL - Run Explain Plan in the job library)
Target typeip_mysql_database
Targets per runExactly one
Query (query)Required. The statement to explain: a SELECT, WITH, TABLE, INSERT, REPLACE, UPDATE or DELETE statement, or one opening with (. Anything else is refused without being run, including a query that starts with ANALYZE, since EXPLAIN ANALYZE executes the statement. It may span several lines and contain -- or # comments; it is explained as typed. Substitute real values for any ? placeholders: a digest taken from Query Analyzer is normalized and will not explain as it stands.
Database Name (db_name)Optional. The schema to run the statement against. Supply it whenever the statement’s object names are not fully qualified.

Credentials. The job needs two, and they do different things:

  • The target’s monitoring credential, the MySQL account from 2.4, held in the target’s MySQL Database monitoring credential set. This is what connects to MySQL and asks for the plan.
  • A Host Preferred Credential on the target, a named host credential whose run-as is the management agent’s operating-system user. This is what lets the agent start the plug-in’s own program on the agent host. That user must be able to read the Connector/J jar in the agent’s ip_plugin/xmys/lib directory (2.9), and when the credential switches user through sudo it must keep the agent’s environment: a sudo rule with env_reset and no env_keep makes the job fail with a message that says EMSTATE is not set in the job step.

Set the host credential once per target, under Setup → Security → Preferred Credentials: select the MySQL Database target type, open Manage Preferred Credentials, and set the target’s host credential set to a named credential that runs as the agent’s operating-system user.

Note: The job’s connection runs under the query time limit of 6.2. EXPLAIN does not execute the statement, but the server takes time to plan one that joins many tables. A plan the server has not produced after 50 seconds is stopped, and the job fails with QUERY_TIMEOUT: the EXPLAIN was stopped at the 50-second limit.

Plan format. The job returns the classic plan table: one row per table access, with the twelve columns the Explain Plan region of Query Analyzer shows (5.1). On a MySQL server the job asks for that format by name, with EXPLAIN FORMAT=TRADITIONAL, so the server’s explain_format variable does not change what the job returns. MySQL 9.7 sets that variable to TREE, and MySQL 8.0.32 and later let an administrator set it to TREE or JSON.

A MariaDB server has one tabular format, and the job sends it a plain EXPLAIN. When a server answers with anything other than the classic table, the job fails with one line that lists the columns the server returned. It does not show an empty plan.

Statements that change data. MySQL checks the privileges a statement needs before it plans it. EXPLAIN of an INSERT, REPLACE, UPDATE or DELETE statement therefore needs the privilege to run that statement, although nothing is run. The monitoring account of 2.4 holds SELECT only, so for such a statement the job fails with one line:

MISSING_PRIVILEGE: the monitoring account 'em_monitoring'@'agent1' does not hold the UPDATE privilege on table shop.orders. MySQL checks the privileges of a statement before it plans it, so EXPLAIN needs them although it does not run the statement. Nothing was run.

The line names the missing privilege, the account as the server identified it, and the table or column. To see the plan, grant that privilege on that table to the monitoring account, or explain the SELECT that reads the same rows with the same WHERE clause.

A REPLACE needs both INSERT and DELETE, and the line names the one the server found missing first. A SELECT on a table the account cannot read keeps MySQL’s own message.

Note: Without a Host Preferred Credential on the target the job fails with Unable to get credentials for defaultHostCred. The agent’s own operating-system credential is not resolved automatically for this job type, so a named host credential is required rather than optional.

Note: The job starts the plug-in through the same launcher as the collections, so a missing or unusable Connector/J fails the job before any program starts, with the same one-line message the collections show (2.9). An agent still on an earlier plug-in version than the OMS fails the job with Perl’s Can't open perl script; that agent’s collections are unaffected. Upgrade the agent (3.4).

To run the job:

  1. Choose Enterprise → Job → Activity, then Create Job.
  2. Select MySQL - Run Explain Plan.
  3. Name the job and add exactly one MySQL Database target.
  4. On the Parameters tab, enter the Query and, where the statement needs it, the Database Name.
  5. Check the Credentials tab if the target’s preferred credentials are not the ones you want used.
  6. Submit.

Done when the run shows Succeeded under Job Activity and its step output holds the plan rows. A run that could not explain the statement ends Failed, and its step output holds one em_error line that names the fault.

The plan comes back in the job’s output: open the completed run from Enterprise → Job → Activity, drill into it, and open the step’s output log. Both parameters are recorded with the results, so a saved job is also a record of the statement that was explained.

The Query Analyzer page (5.1) submits the same job for you and renders what it returns as a grid in its Explain Plan region. That is the quicker route when you are already looking at the statement; the job library route is the one to use when you want the run recorded, scheduled or repeated.