---
name: mysql-explain-tuning
description: "Interpret exported MySQL/MariaDB EXPLAIN output (tabular or JSON): full scans, filesort, temporary tables, poor key use; propose indexes and rewrites. Offline. Use when a MySQL or MariaDB query is slow and its EXPLAIN output is available."
---
# MySQL EXPLAIN tuning (lite)
## When to use
- A pasted MySQL or MariaDB EXPLAIN output, tabular or `FORMAT=JSON`.
- A slow query or slow log entry with its plan.
- The plan shows `Using filesort`, `Using temporary` or `type: ALL`.
## Agent flow
1. Ask the user for the exported EXPLAIN (table or `EXPLAIN FORMAT=JSON`) and the query.
2. Save the plan to a file and run `awk -f scripts/explain-lite.awk plan.txt`.
3. Read the findings per table (`file:line: RULE message`).
4. Propose an index with an explicit column order: equality columns, then one range column, then ORDER BY columns.
5. Propose a rewrite when an index is not enough (avoid functions on indexed columns, sort fewer rows).
6. State that validating the change needs a new EXPLAIN from the user. Never run SQL yourself.
## Rules covered by the script
- SK076-R01 `type: ALL` on a table with 10000 or more estimated rows.
- SK076-R02 `Using filesort`.
- SK076-R03 `Using temporary`.
Exit code: 0 no findings, 1 findings, 2 usage error. The script reads the file only and touches nothing else.
See `references/reading-explain.md` for how to read each column.
— ‹guest · 2026-12-03› —
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.