SQL Optimizer: Leveraging Agent Skills for Slow Query Analysis and Rewriting

Introduction

One common cause of occasional online API timeouts and report tasks dragging down slave databases is mismatched SQL syntax or indexes relative to the execution plan. Troubleshooting often involves cross-referencing slow query logs, EXPLAIN output, and table structures, followed by manual deduction on whether to add composite indexes or rewrite subqueries. The following introduces the “SQL Optimizer,” a community Skill on SkillHub. It consolidates “slow query analysis, index recommendation, inefficient SQL rewriting, and execution plan metric interpretation” into a reusable Agent capability, outputting results in structured Markdown tables.

What is this

“SQL Optimizer” is an Agent Skill from the SkillHub community (community), located at @user_c1ff727a/sql-pro-v2. The current version is 1.0.0, categorized under dev-programming, and maintained by the publisher user_c1ff727a. The official introduction positions it as a Professional SQL query optimization assistant: analyzing slow queries, recommending index strategies, rewriting inefficient SQL, and explaining metrics in the execution plan; output is presented in structured Markdown tables. The tag indicates requires_api_key=false, meaning using this Skill itself does not rely on additional API keys.

SkillHub Page: https://www.skillhub.cn/skills/user_c1ff727a/sql-pro-v2
API Entry: https://api.skillhub.cn/user_c1ff727a/sql-pro-v2

Core Functions

The following capabilities are derived from the official introduction; details not present in the materials are not extended.

  1. Slow Query Analysis: Centered on the SQL and context you provide, it sorts out syntax and access paths that may cause performance issues.
  2. Index Strategy Recommendation: Based on table structure and query patterns, it provides recommendations on index direction (specific statements and trade-offs are generated by the model combined with Skill guidance).
  3. Inefficient SQL Rewriting: Proposes rewrite ideas or equivalent SQL for obviously uneconomical syntax.
  4. Execution Plan Metric Explanation: Explains metric items in the execution plan to facilitate reading in conjunction with EXPLAIN type outputs.
  5. Structured Markdown Tables: Conclusions and comparison information are presented in table format for easy pasting into documents or tickets.

Installation and Activation

The Skill is based on the universal SKILL.md format. When installing on SkillHub, you need to let the Agent follow the official installation instructions and install the skill to the skills directory recognized by the current client; if --dir is not specified, it defaults to ./skills/, which may not be loaded by environments like Cursor.

Method 1: Let AI install via SkillHub docs

Send the following prompt to an AI that supports Skills (consistent with the SkillHub page):

Please install `@user_c1ff727a/sql-pro-v2` according to https://skillhub.cn/install/skillhub.md.

Method 2: Use SkillHub CLI locally

First, perform an environment check, then install to the corresponding directory. Taking Cursor as an example, the skills directory is usually ~/.cursor/skills/; for Claude Code, it is ~/.claude/skills/; for Codex, it is often ~/.codex/skills/ or .agents/skills/ under the project. For other client paths, refer to Section 4 of https://skillhub.cn/install/skillhub.md.

Check CLI:

command -v skillhub && skillhub --version

If not installed, you can perform a full installation (recommended by docs):

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

Install this Skill (replace --dir with your current Agent’s skills directory):

skillhub install @user_c1ff727a/sql-pro-v2 --dir ~/.cursor/skills/

After installation, refresh or restart according to your client’s requirements to load the new Skill. The “Install” count for this Skill on the public page is 0, which only represents the installation count under SkillHub’s statistical criteria; it does not indicate whether your local configuration was successful. Determine success based on whether the local directory and Agent recognize it.

Typical Usage

The official materials do not include fixed sample SQL or screenshot tickets. Usage should be organized around the input types declared by the Skill to facilitate the Agent answering according to the SKILL.md workflow.

  1. After enabling the Skill, state the database type and version (if known), relevant table structures, or CREATE TABLE snippets in the conversation.
  2. Paste the SQL to be optimized; if there are metrics like duration or scanned rows from slow query logs, include them as well.
  3. Provide the execution plan: e.g., raw text from MySQL’s EXPLAIN / EXPLAIN ANALYZE or PostgreSQL’s EXPLAIN (ANALYZE, BUFFERS), to facilitate the “Execution Plan Metric Explanation” capability.
  4. Clarify requirements: whether you only need index suggestions, only rewrites, or a tabular comparison of “Before Rewrite / After Rewrite / Expected Impact”, etc.; the Skill promises to output in structured Markdown tables, suitable for direct inclusion in review records.

Through the above steps, what you get is analysis and recommendations generated by the model based on the current context. Before going live, you should still verify the execution plan and data correctness in the test environment.

Scenarios and Notes

Who is it for: Backend and data-related developers who write SQL daily and perform performance troubleshooting; those who want to align “Analysis—Index—Rewrite—Plan Interpretation” terminology using a unified Skill in the IDE, rather than writing prompts from scratch every time.

Community Skill: The source is community, and behavior is bounded by the SKILL.md in the repository and model capabilities; complex production issues (sharding, specific vendor optimizer details) still require combination with DBAs and real load testing.

No API Key Requirement: requires_api_key=false indicates that the Skill metadata does not require binding to third-party keys; actual inference still depends on the model and quota of the Agent you are using.

Platform Data (SkillHub fetched, 2026-10-22): Rating 100000, Downloads 749. This may differ from ratings and download counts reposted by third parties; refer to the SkillHub page.

Conclusion

“SQL Optimizer” consolidates slow query analysis, index recommendations, SQL rewriting, and execution plan interpretation into an installable Agent capability, organizing output with Markdown tables. It is suitable as a fixed collaboration template for SQL troubleshooting. Installation and coordinates are subject to SkillHub:

  • Page: https://www.skillhub.cn/skills/user_c1ff727a/sql-pro-v2
  • Coordinates: @user_c1ff727a/sql-pro-v2
  • API: https://api.skillhub.cn/user_c1ff727a/sql-pro-v2
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye