agentleFS
huiferhuifer/CloudSaver/skills/query-rewriter/SKILL.md

query-rewriter

Skill2 starsChanged 5 months agoApache-2.0View on GitHub

SQL query rewriting expert. Identifies inefficient query patterns and provides optimized alternatives. Trigger when user mentions query optimization, SQL rewriting, or query performance.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. SkillMedev/database-performance★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow the specific reference file for detailed instructions.

    line 43

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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 Query Rewriting Expert

Common Anti-Patterns

Anti-PatternProblemReference
SELECT *Fetches unnecessary datareferences/select-star.md
N+1 queriesToo many round tripsreferences/n-plus-one.md
IN with subqueryMay process too many rowsreferences/exists-vs-in.md
OR across columnsPrevents index usagereferences/or-optimization.md
OR conditionsCannot use indexreferences/union-instead-of-or.md
Type mismatchImplicit conversionreferences/implicit-conversion.md

Audit Workflow

Step 1: Identify Problem Patterns

Check for:

  • SELECT * usage
  • N+1 query patterns
  • IN with large subqueries
  • OR conditions across columns
  • Type mismatches

Step 2: Match Anti-Pattern

Identify which anti-pattern the query matches and apply the corresponding solution from the reference file.

Step 3: Apply Rewrite

Follow the specific reference file for detailed instructions.

Step 4: Verify Improvement

EXPLAIN ANALYZE <rewritten_query>;

Benchmark Reference

OptimizationBeforeAfterImprovement
SELECT * → specific100ms20ms80%
N+1 → batch500ms50ms90%
IN → EXISTS500ms50ms90%
OR → UNION200ms20ms90%
Type fix150ms2ms98.7%

Output Format

## Query Rewriting Report

### 1. Original Query
```sql
<original_query>

2. Anti-Patterns Detected

PatternProblemReference
.........

3. Recommended Rewrite

<optimized_query>

4. Expected Improvement

  • Query time: Xms → Yms (Z% faster)
  • Rows processed: X → Y (Z% reduction)

5. Implementation

Reference: references/<case-name>.md

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.