agentleFS
divik-09divik-09/claude-skills-collection/skills/sql-optimizer/SKILL.md

sql-optimizer

Skill1 starsChanged 7 days agoMITView on GitHub

Write, explain, debug, and optimize SQL queries and schemas. Use whenever the user shares SQL, asks why a query is slow, wants help with joins, window functions, CTEs, indexing, or schema design, or pastes an EXPLAIN plan.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use changelog-keeper, 0-template and 8 more.

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.
  • JayRHaSkill

    changelog-keeper

    Maintains a CHANGELOG.md in the Keep a Changelog format with Semantic Versioning, grouping user-facing entries under Added/Changed/Deprecated/Removed/Fixed/Security and cutting dated releases from an Unreleased section. Use this skill when the user asks to "update the changelog", "add a changelog entry", "cut a release", "bump the version", "what changed since the last release", or to create/clean up a CHANGELOG.md or release notes.

    Also in 4 projects that use this

  • JayRHaSkill

    0-template

    Template for creating a new Agent Skill. Copy this folder, rename it to your skill's kebab-case name, and fill in every section. Use this as the starting point whenever you author a new skill for the AgentSkills library.

    Also in 3 projects that use this

  • xmqywxSkill

    meeting-summarizer

    Transform meeting transcripts into structured summaries with action items, decisions, follow-ups, and efficiency analysis. Works with any meeting format.

    Also in 3 projects that use this

  • +7 more from JayRHa

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask which database (PostgreSQL, MySQL, SQLite, BigQuery, SQL Server...) if it changes the answer.

    line 8
  2. Distinctive:

    Read the plan for: sequential scans on large tables, row estimates far from actuals, nested loops over big sets, sorts spilling to disk, …

    line 13
  3. Very specific:

    Filter early and select less: avoid SELECT *, push predicates down, limit columns.

    line 15
  4. Very specific:

    Use explicit JOIN ... ON, meaningful aliases, and CTEs for readability.

    line 23
  5. Very specific:

    Never run or suggest destructive statements (DELETE, UPDATE, DROP, TRUNCATE) without a WHERE check, a preview SELECT, and a transaction or …

    line 30

“Common” is measured: kept by at least 6 in 10 of the 9 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 Optimizer

Ask which database (PostgreSQL, MySQL, SQLite, BigQuery, SQL Server...) if it changes the answer. Dialect details matter.

Diagnosing slow queries

  1. Get the query, schema, row counts, existing indexes, and the EXPLAIN (ANALYZE) output. Do not optimize blind.
  2. Read the plan for: sequential scans on large tables, row estimates far from actuals, nested loops over big sets, sorts spilling to disk, repeated subplans.
  3. Apply fixes in this order:
    • Filter early and select less: avoid SELECT *, push predicates down, limit columns.
    • Index for the access pattern: match WHERE equality columns first, then range, then ORDER BY. Consider composite and covering indexes. Avoid wrapping indexed columns in functions (WHERE date(created_at) = ...) or leading wildcards.
    • Rewrite: replace correlated subqueries with joins or window functions, EXISTS instead of IN on large sets, avoid OR across different columns (use UNION ALL), avoid implicit type casts.
    • Schema or data: partitioning, summary tables, archiving, correct data types.
  4. State the expected effect and the trade-off (indexes slow writes and use space).

Writing queries

  • Use explicit JOIN ... ON, meaningful aliases, and CTEs for readability.
  • Watch NULL semantics (= NULL never true, NOT IN with NULLs, aggregate behavior).
  • Guard against join fan-out that inflates counts and sums. Verify with COUNT(*) vs COUNT(DISTINCT key).
  • Be explicit about time zones and half-open date ranges (>= start AND < end).

Safety

  • Never run or suggest destructive statements (DELETE, UPDATE, DROP, TRUNCATE) without a WHERE check, a preview SELECT, and a transaction or backup note.
  • Parameterize queries; never build SQL by string concatenation with user input.

Output

Provide the improved query, an explanation of what changed and why, suggested indexes as CREATE INDEX statements, and how to confirm the improvement.

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.