"data-sql-optimization"

"data-sql-optimization" is a skill for Claude Code from charlieviettq/awesome-agent-skill. It costs 89 tokens per session (1,302 once invoked), scanned A, a copy of data-sql-optimization, MIT.

A guide to making SQL queries run faster. SQL is the language used to read and change data in many databases.

In plain words
What is it for?
Use it to inspect query execution plans, choose indexes, fix N+1 query problems, and improve database performance.
Why use it?
It helps identify the actual cause of slow queries, such as scanning too much data, missing indexes, or inefficient joins, instead of relying on guesses.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to inspect query execution plans, choose indexes, fix N+1 query problems, and improve database performance.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/charlieviettq/awesome-agent-skill/data-sql-optimization
Install

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.

Any agent
npx skills add charlieviettq/awesome-agent-skill --skill data-sql-optimization
Clone the repo
git clone --depth 1 https://github.com/charlieviettq/awesome-agent-skill

Made for: Claude Code.

Wrote 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.

agentmods badge for "data-sql-optimization"

README.md
[![agentmods](https://agentmods.dev/badge/skills/charlieviettq/awesome-agent-skill/data-sql-optimization/github.svg)](https://agentmods.dev/skills/charlieviettq/awesome-agent-skill/data-sql-optimization)
Your own site
<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.

agentmods 80×15 button for "data-sql-optimization"

Your own site · 80×15
<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>
Per session 89 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,302 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 97% copy Near-identical to another mod in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 9d ago against content hash c12814732540, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-13, from the pricing page.

Security

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.

Origin

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.

.claude/skills/data-sql-optimization/SKILL.md · 110 lines

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

Read the full file on GitHub · 110 lines

Files

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.

Changes

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.

  1. 9d ago First seen · 110 lines · 89 tokens per session scan A c12814732540

Subscribe to this mod's changes

"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.

Related

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.

oliver-kriska/claude-elixir-phoenix · 45 tokens

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.

oliver-kriska/claude-elixir-phoenix · 46 tokens

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.

oliver-kriska/claude-elixir-phoenix · 49 tokens

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.

laolaoshiren/claude-code-skills-zh · 19 tokens

ecto-constraint-debug

Debug Ecto constraint violations - trace triggers, check migrations, find duplicate data. Use when seeing uniqueconstraint, foreignkeyconstraint, or checkconstraint errors.

oliver-kriska/claude-elixir-phoenix · 36 tokens

sql-query-builder

Build SQL queries for construction databases. Generate optimized SQL queries for construction data retrieval.

datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction · 19 tokens