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/soulcodex/agentic/sql-query-optimizationnpx skills add soulcodex/agentic --skill sql-query-optimizationgit clone --depth 1 https://github.com/soulcodex/agenticWhat 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.00070 | $0.00902 |
| Opus 5 | $0.00035 | $0.00451 |
| Sonnet 5 | $0.00014 | $0.00180 |
| Haiku 4.5 | $0.00007 | $0.00090 |
Grade A, and why
sql-query-optimization 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 yesterday.
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 — 117 lines — stays where its author put it; the contents beside it link to each section on GitHub.
SQL Query Optimization Skill
Step 1 — Reproduce the Slow Query
Establish a reproducible baseline before making any changes:
- Capture the exact query (including parameter values if possible).
- Note the current execution time (p95 from APM, or run it manually 3–5 times).
- Confirm the database engine (PostgreSQL, MySQL, SQLite, etc.) and version.
Step 2 — Run EXPLAIN (ANALYZE, BUFFERS)
PostgreSQL:
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT ...; -- paste the full query here
MySQL:
EXPLAIN FORMAT=JSON
SELECT ...;
Capture the full output before making any changes.
Step 3 — Identify the Bottleneck
Read the plan top-down (outermost → innermost). Look for:
| Signal | What it means |
|---|---|
Seq Scan on a large table |
No index — or the planner chose not to use one |
| Rows estimate far from actual | Stale statistics — run ANALYZE <table> |
Hash Join with a huge hash table |
May need a nested-loop + index for small inputs |
High Buffers: shared hit |
Heavily cached — latency is CPU-bound, not I/O |
High Buffers: shared read |
I/O bound — consider indexes or read replicas |
Bitmap Heap Scan with many rows |
Covering index may eliminate heap fetches |
Step 4 — Fix
Add an index (most common fix):
-- B-tree for equality and range
CREATE INDEX CONCURRENTLY ON orders(user_id);
-- Partial index for common filter
CREATE INDEX CONCURRENTLY ON orders(created_at)
WHERE status = 'pending';
-- Covering index to eliminate heap fetch
CREATE INDEX CONCURRENTLY ON orders(user_id)
INCLUDE (status, total_amount);
-- Expression index for function-wrapped column
CREATE INDEX CONCURRENTLY ON users(lower(email));
Always use CONCURRENTLY in production to avoid table locks.
Rewrite the query (when the plan is structurally wrong):
- Replace correlated subqueries with
JOINorEXISTS. - Replace
SELECT *with specific columns needed. - Replace
OFFSETpagination with keyset pagination:-- Instead of: LIMIT 20 OFFSET 10000 WHERE id > :last_seen_id ORDER BY id LIMIT 20 - Replace
IN (SELECT ...)withEXISTS (SELECT 1 FROM ...)for large subqueries.
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.
- yesterday First seen · 117 lines · 70 tokens per session scan A a598cb719967
sql-query-optimization is a skill published in the GitHub repository soulcodex/agentic (10 stars, last pushed 2d ago), licensed MIT. It adds 70 tokens to every session and 902 once invoked, about $0.0003 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
caching-strategies
When improving read performance and reducing database load.
database-query-optimization
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.
research-repository
Build a repository that makes findings findable, reusable, and cumulative across teams. Use when the same research keeps getting redone. For synthesising one study, use affinity-diagram.
survey-design
Design unbiased survey instruments — question wording, scales, and sampling — to measure attitudes at scale. Use when you need quantitative breadth. For behavioural experiments, use a-b-test-design (prototyping-testing).
localization-design
Design for multiple languages, writing directions, and cultural contexts — text expansion, RTL mirroring, and locale formats. Use when shipping beyond one locale. For the words themselves, use ux-writing (designer-toolkit).
design-negotiation
Advocate for design quality, scope, and timeline with partners and leadership using evidence and shared goals. Use in the conversation itself. For the commercial vocabulary behind it, use business-design (ux-strategy).