mysql-get-query-plan
2 minute read
About
A mysql-get-query-plan tool gets the execution plan for a SQL statement against a MySQL
database.
mysql-get-query-plan takes one input parameter sql_statement and gets the execution plan for the SQL
statement against the source.
** Security **
The tool runs the supplied statement as EXPLAIN FORMAT=JSON <sql_statement>.
A plain EXPLAIN (without ANALYZE) only computes the query plan; it never
executes the wrapped statement, so SELECT, INSERT, UPDATE, and DELETE
inputs all return a plan without side effects.
Two execution vectors are blocked structurally rather than by parsing the input:
EXPLAIN ANALYZE(which does execute the statement) is unreachable. The tool fixes theFORMAT=JSONprefix, and MySQL’s grammar requiresANALYZEto appear beforeFORMAT=. A statement beginning withANALYZEtherefore lands afterFORMAT=JSONand is rejected by the server as a syntax error.- Multiple statements are not run. The MySQL driver does not enable
multi-statement execution by default, so input such as
SELECT 1; DROP TABLE tis rejected by the server rather than executed.
As defense in depth, configure the source with a least-privilege database
user scoped to only the objects the agent needs to plan against. This bounds
what any statement — including those that EXPLAIN does plan — can reach, and
is the recommended control for this tool. Avoid enabling the driver’s
multi-statement option on the source.
Compatible Sources
This tool can be used with the following database sources:
| Source Name |
|---|
| MySQL Source |
| Cloud SQL for MySQL Source |
Example
kind: tool
name: get_query_plan_tool
type: mysql-get-query-plan
source: my-mysql-instance
description: Use this tool to get the execution plan for a sql statement.
Reference
| field | type | required | description |
|---|---|---|---|
| type | string | true | Must be “mysql-get-query-plan”. |
| source | string | true | Name of the source the SQL should execute on. |
| description | string | true | Description of the tool that is passed to the LLM. |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.