agentleFS
polardbpolardb/polardbx-skills/skills/sql-review/SKILL.md

sql-review

Skill8 starsChanged 28 days agoApache-2.0View on GitHub

Scan codebase for table schemas (DDL) and SQL statements, create a PolarDB-X test instance with mock data, analyze index usage via EXPLAIN, and provide index optimization recommendations. Works with any language/framework. Use when user says "sql review", "SQL审查", "索引分析", "索引推荐", "index review", "SQL优化", "检查索引", "review sql", "分析SQL", "explain分析", "慢查询分析", "sql performance".

  • Installs packages

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use code-review.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If mysql is not available, prompt the user to install it (brew install mysql-client / apt install mysql-client / scoop install mysql)

    line 18
  2. Very specific:

    If user chooses Aliyun instance mode, aliyun CLI must be available and configured with valid credentials (aliyun configure list)

    line 19
  3. Very specific:

    All temporary files use the sql_review_ prefix.

    line 20
  4. Distinctive:

    After scanning each mapper/table (Step 2): append that table's SQL inventory immediately.

    line 26
  5. Distinctive:

    After EXPLAIN analysis per table (Step 5): append that table's EXPLAIN results and recommended DDL immediately.

    line 27
  6. Distinctive:

    Rule: Never batch multiple tables before saving.

    line 30
  7. Distinctive:

    If user selects Aliyun instance: skip code scanning, execute the Aliyun collection path instead.

    line 42
  8. Very specific:

    Verify aliyun CLI availability, collect instance info from user, retrieve DDL from the instance, fetch SQL insight statistics (DAS API), …

    line 49
  9. Distinctive:

    Run EXPLAIN on each query (and each variant for multi-path queries).

    line 67

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SQL Review - Index Analysis & Recommendations

Scan codebase for DDL and SQL queries, create tables on a PolarDB-X test instance, populate mock data, analyze index usage via EXPLAIN, and output optimization recommendations.

Prerequisites

  • curl must be available (for PolarDB-X Zero API calls to create/destroy instances)
  • mysql CLI client must be available (to connect and execute SQL)
  • If mysql is not available, prompt the user to install it (brew install mysql-client / apt install mysql-client / scoop install mysql)
  • If user chooses Aliyun instance mode, aliyun CLI must be available and configured with valid credentials (aliyun configure list)
  • All temporary files use the sql_review_ prefix. $TMPDIR in this document refers to a writable temp directory — determine the appropriate path for the current OS (e.g. /tmp on Linux/macOS, %TEMP% on Windows)

Progress File

Critical for long sessions: Initialize $TMPDIR/sql_review_progress.md at the start of Step 2 and append incrementally throughout the entire workflow.

  • After scanning each mapper/table (Step 2): append that table's SQL inventory immediately.
  • After EXPLAIN analysis per table (Step 5): append that table's EXPLAIN results and recommended DDL immediately.
  • In Step 6 (Report): read the progress file as the single source of truth to assemble the final report.

Rule: Never batch multiple tables before saving. Process one table, save results, then move to the next. This prevents loss of work if the agent session runs out of context.

Workflow

Track progress on the following steps. Each step has a dedicated reference file — Read it when starting the step, then discard after completion.

Step 1-2: Confirm Scope & Scan Codebase

Confirm scan scope and database edition with the user, detect framework (MyBatis auto-detection), then collect all DDL and SQL statements via multi-round search. For MyBatis projects, extract SQL from XML mapper tags and generate multi-path variants for dynamic WHERE queries.

Scan scope options: Full repository, Specific module/directory, Recent Git commits, or Aliyun instance (collect SQL insights and slow queries via aliyun CLI, no codebase needed).

  • If user selects Aliyun instance: skip code scanning, execute the Aliyun collection path instead.
  • Otherwise: proceed with standard code scanning.

Read references/step-scan.md for detailed instructions.

Step 2: Aliyun Data Source Collection (Aliyun mode only)

Verify aliyun CLI availability, collect instance info from user, retrieve DDL from the instance, fetch SQL insight statistics (DAS API), slow query records, and optionally SQL audit logs (SLS API). Merge and deduplicate results, save to progress file with execution frequency and latency metrics.

Read references/step-aliyun.md for detailed instructions.

Step 3: Name Anonymization

Build randomized name mapping for all tables, columns, indexes (and MyBatis statement IDs). Persist mapping file. Transform all SQL to use anonymous names.

Read references/step-anonymize.md for detailed instructions.

Step 4: Test Instance Setup

Analyze data characteristics from code, create PolarDB-X test instance, create tables with anonymized DDL, and populate mock data via stored procedures.

Read references/step-instance.md for detailed instructions.

Step 5: EXPLAIN Analysis

Run EXPLAIN on each query (and each variant for multi-path queries). For problematic queries, explore multiple candidate indexes via CREATE -> EXPLAIN -> DROP cycles. Cross-validate indexes against all variants.

Read references/step-explain.md for detailed instructions.

Step 6: Report & Cleanup

Map anonymous names back to real names. Generate sql-review-report.md with 7 sections (overview, schema, inventory, query analysis, index recommendations, security notes, caveats). Clean up test instance and temp files.

Read references/step-report.md for detailed instructions.

Reference Documents

DocumentContent
references/index-design.mdEXPLAIN metrics, composite index principles, index exploration method, common patterns, mock data rules
references/mybatis.mdMyBatis dynamic SQL tag expansion rules, multi-path analysis algorithm, parameter placeholders

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.