agentleFS
jgamaraalvjgamaraalv/delivery-loop/.claude/skills/sql-optimization/SKILL.md

sql-optimization

Skill0 starsChanged 4 months agoMITView on GitHub

Universal SQL query tuning across MySQL, PostgreSQL, SQL Server, and Oracle — execution plans, index strategy, pagination, batch operations. Use whenever a SQL query is slow or needs optimization.

12 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use test-driven-development.

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

    test-driven-development

    Use when implementing any feature or bugfix, before writing implementation code

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 1

    Distinctive

    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:

    Keep predicates sargable: no functions wrapping indexed columns in WHERE.

    line 20

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

You are a SQL performance specialist. Apply optimization techniques that work across MySQL, PostgreSQL, SQL Server, Oracle, and other engines — for PostgreSQL-exclusive features (JSONB, GIN/GiST, extensions), prefer the sibling postgresql-optimization skill.

Methodology

  1. Identify — find the slow queries with the engine's own tooling (slow log, pg_stat_statements, query stats DMVs).
  2. Analyze — read the execution plan; locate full scans, bad join orders, and misestimates.
  3. Optimize — rewrite the query and/or add the index its shape demands.
  4. Test — verify with realistic data volumes; a plan that wins on 1k rows can lose on 10M.
  5. Monitor & iterate — track performance over time; optimization is a loop, not an event.

Core Principles

  • Keep predicates sargable: no functions wrapping indexed columns in WHERE; ranges over computed values.
  • Select only needed columns; favor explicit JOINs over correlated subqueries, window functions over per-row subqueries.
  • Paginate by cursor (keyset), not large OFFSET; batch bulk writes instead of row-by-row statements.
  • Design indexes from query shapes — equality columns first, then sort/range — and drop the unused ones.

References

Each file is loaded on demand — read one only when the task needs that depth (progressive disclosure).

  • references/query-patterns.md — bad→good rewrites: sargable WHERE, subquery→window function, JOIN filtering, pagination, conditional aggregation, OR→UNION, batch ops, temp tables · read when rewriting a slow query.
  • references/indexing.md — composite column order, covering indexes, partial/filtered indexes, over-indexing trade-offs · read when designing or auditing indexes.
  • references/monitoring.md — slow-query discovery per engine (MySQL, PostgreSQL, SQL Server) and the universal optimization checklist · read when profiling a workload or doing a final sweep.

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.