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 agentmods add skills/notysoty/openagentskills/sql-query-optimizernpx skills add Notysoty/openagentskills --skill sql-query-optimizergit clone --depth 1 https://github.com/Notysoty/openagentskillsWhat 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 | $0.00020 | $0.01362 |
| Opus 5 | $0.00010 | $0.00681 |
| Sonnet 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 2d 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.
- 2d 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 19d ago), licensed MIT. It adds 20 tokens to every session and 1,362 once invoked, about $0.0001 per session on Opus 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-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.
sql-optimization
SQL query optimization techniques and best practices.
postgresql-expert
Expert-level PostgreSQL database administration, advanced queries, performance tuning, and production operations.
database-query-optimization
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.
sql-optimization
Skill "sql-optimization" from chaterm/terminal-skills, covering sql 优化与调优, 概述, 执行计划分析, mysql explain and postgresql explain.
memory_progressive_disclosure
3-layer search protocol that minimizes token waste when querying persistent memory.