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 charlieviettq/awesome-agent-skill --skill data-sql-optimizationgit clone --depth 1 https://github.com/charlieviettq/awesome-agent-skillWrote 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/charlieviettq/awesome-agent-skill/data-sql-optimization)<a href="https://agentmods.dev/skills/charlieviettq/awesome-agent-skill/data-sql-optimization"><img src="https://agentmods.dev/badge/skills/charlieviettq/awesome-agent-skill/data-sql-optimization/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/charlieviettq/awesome-agent-skill/data-sql-optimization"><img src="https://agentmods.dev/badge/skills/charlieviettq/awesome-agent-skill/data-sql-optimization.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.00089 | $0.01302 |
| Opus 5 | $0.00044 | $0.00651 |
| Sonnet 5 | $0.00018 | $0.00260 |
| Haiku 4.5 | $0.00009 | $0.00130 |
Grade A, and why
"data-sql-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 9d 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.
This is a copy
97% identical to data-sql-optimization — 8 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.
How it starts
The opening of the file, as written. The whole thing — 110 lines — stays where its author put it; the contents beside it link to each section on GitHub.
SQL Query Optimization
Framework
IRON LAW: Measure Before Optimizing
NEVER guess which query is slow or why. Use EXPLAIN (EXPLAIN ANALYZE in
PostgreSQL) to see the actual execution plan. The database's plan often
differs from what you expect — a query you think is efficient may do
a full table scan, and a complex-looking query may use an index perfectly.
Measure → identify bottleneck → fix → measure again.
EXPLAIN Output Reading
Key metrics in EXPLAIN ANALYZE (PostgreSQL):
| Metric | What It Means | Red Flag |
|---|---|---|
| Seq Scan | Full table scan | On large tables (>100K rows) |
| Index Scan | Using an index | Expected for filtered queries |
| Nested Loop | Join method (row-by-row) | On large tables without index |
| Hash Join | Join method (hash table) | Normal for larger tables |
| Sort | Sorting results | Without index support on large sets |
| Actual Time | Milliseconds for this step | Compare to identify bottleneck |
| Rows | Actual rows processed vs estimated | Large mismatch = stale statistics |
Indexing Strategy
| When to Index | Index Type | Example |
|---|---|---|
| WHERE clause column | B-Tree (default) | CREATE INDEX idx_user_email ON users(email) |
| JOIN column | B-Tree | CREATE INDEX idx_order_user ON orders(user_id) |
| Composite filter | Composite index | CREATE INDEX idx_order_status_date ON orders(status, created_at) |
| Text search | GIN / Full-text | CREATE INDEX idx_product_name_gin ON products USING gin(name gin_trgm_ops) |
| Range queries | B-Tree | Columns used with BETWEEN, >, < |
Composite index column order matters: Put the most selective (highest cardinality) column first. INDEX(status, date) is good if you always filter by status. INDEX(date, status) is better if you always filter by date range first.
Common Anti-Patterns
| Anti-Pattern | Problem | Fix |
|---|---|---|
SELECT * |
Reads all columns, prevents index-only scans | Select only needed columns |
| Subquery in WHERE | Re-executes for each row | Rewrite as JOIN or CTE |
OR in WHERE |
Prevents index use | Rewrite as UNION or separate queries |
| Function on indexed column | WHERE YEAR(date) = 2024 bypasses index |
WHERE date >= '2024-01-01' AND date < '2025-01-01' |
| N+1 queries | 1 query for list + N queries for details | JOIN or batch query with IN |
| Missing pagination | Fetching all rows when only showing 20 | LIMIT + OFFSET or keyset pagination |
| Implicit type conversion | WHERE id = '123' (string vs int) |
Use correct type: WHERE id = 123 |
What ships with it
3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
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.
- 9d ago First seen · 110 lines · 89 tokens per session scan A c12814732540
"data-sql-optimization" is a skill published in the GitHub repository charlieviettq/awesome-agent-skill (26 stars, last pushed 1mo ago), licensed MIT. It adds 89 tokens to every session and 1,302 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. It is 97% identical to data-sql-optimization, differing in 8 lines, and is treated as a copy.
Other skills, from other repositories
ecto-patterns
Ecto patterns — schemas, changesets, queries, migrations, Multi, associations, preloads, upserts. Use when editing Repo calls, Ecto.Query, or schema fields. Skip for Ash.
phoenix-contexts
Phoenix context design — creating/splitting contexts, Scope (1.8+), Ecto.Multi, PubSub, routers, plugs, controllers. Use when editing contexts, routers, or designing boundaries.
ecto-n1-check
Detect N+1 query anti-patterns specifically — Repo calls inside Enum/for loops, missing preloads on associations. Use when N+1 is explicitly suspected, NOT for unrelated Ecto questions or wider database performance.
db-migrator
A database change helper that compares the code-defined database structure with its migration history and creates scripts for updating it. A database migration is a controlled change to tables, fields, indexes, or relationships.
ecto-constraint-debug
Debug Ecto constraint violations - trace triggers, check migrations, find duplicate data. Use when seeing uniqueconstraint, foreignkeyconstraint, or checkconstraint errors.
sql-query-builder
Build SQL queries for construction databases. Generate optimized SQL queries for construction data retrieval.