Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add Notysoty/openagentskills --skill sql-query-optimizergit clone --depth 1 https://github.com/Notysoty/openagentskillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/notysoty/openagentskills/sql-query-optimizer)<a href="https://agentmods.dev/skills/notysoty/openagentskills/sql-query-optimizer"><img src="https://agentmods.dev/badge/skills/notysoty/openagentskills/sql-query-optimizer/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/notysoty/openagentskills/sql-query-optimizer"><img src="https://agentmods.dev/badge/skills/notysoty/openagentskills/sql-query-optimizer.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00020 | $0.01362 |
| Opus 5.5 | $0.00008 | $0.00545 |
| Sonnet 5.5 | $0.00004 | $0.00272 |
| Haiku 4.5 | $0.00002 | $0.00136 |
Grade A, and why
SQL Query Optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 143 lines — stays where its author put it; the contents beside it link to each section on GitHub.
SQL Query Optimizer
What this skill does
This skill directs the agent to analyze a SQL query for common performance anti-patterns and rewrite it to execute more efficiently. It checks indexes, join strategies, subquery usage, N+1 patterns, unnecessary full table scans, and more — then provides a side-by-side comparison of the original and optimized query with a plain-English explanation of each change.
Use this when a query is running slowly in production, when you're writing a complex query for the first time and want a second opinion, or when you're reviewing a pull request that touches database queries.
How to use
Claude Code / Cursor / Codex
Copy this file to .agents/skills/sql-query-optimizer/SKILL.md in your project root (for Claude Code), or add the instructions below to your .cursorrules (for Cursor).
Then ask:
- "Optimize this query using the SQL Query Optimizer skill."
- "This query takes 3 seconds on 500k rows. Use the SQL Query Optimizer skill to improve it."
Provide the query, and optionally:
- The database system (PostgreSQL, MySQL, SQLite, etc.)
- Relevant table schemas and row counts
- Any existing index definitions
- The
EXPLAINorEXPLAIN ANALYZEoutput if available
The Prompt / Instructions for the Agent
When asked to optimize a SQL query, follow these steps:
-
Identify the database system (PostgreSQL, MySQL, SQLite, MSSQL). Syntax and optimizer behavior differ. If not specified, ask.
-
Analyze for these anti-patterns in order:
- Missing indexes: Are columns in
WHERE,JOIN ON,ORDER BY, orGROUP BYclauses indexed? Flag unindexed columns on large tables. - *SELECT : Does the query select all columns when only a few are needed? Unnecessary columns increase I/O and memory.
- N+1 queries: Is this query run inside a loop in application code (indicated by a comment or context)? Suggest a single JOIN or subquery instead.
- Correlated subqueries: Does the
WHEREclause contain a subquery that references the outer query? These execute once per row. Rewrite as a JOIN or CTE. - Non-sargable predicates: Are functions applied to indexed columns in
WHERE(e.g.,WHERE YEAR(created_at) = 2024)? This prevents index use. - Implicit type coercions: Do joins compare columns of different types (e.g.,
INTvsVARCHAR)? This forces a full scan. - Unnecessary DISTINCT or ORDER BY: Is
DISTINCTused where it's not needed? IsORDER BYapplied to a subquery that is later filtered? - Large offset pagination: Does the query use
LIMIT x OFFSET ywith a large offset? Suggest keyset pagination instead.
- Missing indexes: Are columns in
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 143 lines · 20 tokens per session scan A 7ff2863adcb7
SQL Query Optimizer is a skill published in the GitHub repository Notysoty/openagentskills (9 stars, last pushed 2mo ago), licensed MIT. It adds 20 tokens to every session and 1,362 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
sql-optimization
A guide to improving SQL queries, the commands used to read and change data in databases. It covers examining how MySQL and PostgreSQL execute queries and designing indexes that help them find data faster.
sql-sentinel
Audit SQL for the cost & performance anti-patterns that burn warehouse credits. Catches SELECT , full-table scans, non-sargable predicates, Cartesian joins, NULL-trap NOT IN, and 17 more rules. Scores warehouse health 0-100 and outputs a prioritized cost-reduction plan for BigQuery, Snowflake, Redshift, and Postgres.
postgresql-expert
Expert-level PostgreSQL database administration, advanced queries, performance tuning, and production operations. Use when the user mentions database, SQL, or performance, or when the task involves Advanced Data Types, Full-Text Search, Advanced Indexes, or Advanced Queries.
relational-database-design
Designs or reviews a relational database schema for a given domain. Covers table structure, normalization, indexes, constraints, and migration strategy. Invoked when the user asks to design a schema, review a database structure, or optimize a data model.
Database Performance Testing
Database performance testing including query optimization, index analysis, connection pooling, slow query detection, and N+1 query prevention.
database-query-optimization
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.