Discover Database
rand/cc-polymath
Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.
Diagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning.
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimization --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/database/query-optimization .claude/skills/query-optimization && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .claude/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimizationType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimization --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .agents/skills && cp -r skills-src/database/query-optimization .agents/skills/query-optimization && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .agents/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimization --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/database/query-optimization .cursor/skills/query-optimization && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .cursor/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/seb1n/awesome-ai-agent-skills.git --path database/query-optimization--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimization --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/database/query-optimization .gemini/skills/query-optimization && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .gemini/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimizationInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .github/skills && cp -r skills-src/database/query-optimization .github/skills/query-optimization && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .github/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install seb1n/awesome-ai-agent-skills query-optimization --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/database/query-optimization .opencode/skills/query-optimization && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "query-optimization" agent skill from https://github.com/seb1n/awesome-ai-agent-skills/tree/main/database/query-optimization into .opencode/skills/query-optimization/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
query-optimizationDiagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning.
Query Optimization is an agent skill from seb1n/awesome-ai-agent-skills. Diagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning. Use when the user provides a query, performance symptom, or EXPLAIN plan; use sql-query-generation when creating a new query from requirements.
Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Databases, covering Query optimization, SQL and ORMs and data access. It works with SQL. The repository describes itself as: 103 ready-to-use AI agent skills for Claude Code, OpenAI Codex, Gemini CLI, Cursor, GitHub Copilot, Windsurf, and other Agent Skills-compatible tools. Complete SKILL.md… The licence is MIT.
6 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 75865a5. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
No scripts in the folder and no shell commands in SKILL.md (its code samples are sql and python).
From the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Query Optimization loads about 2.6k tokens when it runs. Until then it costs about 72 tokens; SKILL.md has 995 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from seb1n/awesome-ai-agent-skills at commit 75865a5, republished under its MIT licence (© seb1n). 995 words, ~2,635 tokens.
.claude/skills/query-optimization/SKILL.md (or your agent's skills folder).This skill enables an AI agent to diagnose and fix slow database queries. The agent uses EXPLAIN/EXPLAIN ANALYZE to interpret query execution plans, identifies missing indexes and inefficient scan patterns, rewrites queries to eliminate performance bottlenecks, detects and resolves N+1 query problems in ORMs, and recommends monitoring tools to track query performance over time. The focus is on practical, measurable improvements with before-and-after evidence.
Identify the slow query: Collect the problematic query from slow query logs, application performance monitoring (APM) tools, or user reports. Note the current execution time, the table sizes involved, and how frequently the query runs. High-frequency slow queries should be prioritized over rare ones.
Analyze the execution plan: Run EXPLAIN ANALYZE (PostgreSQL) or EXPLAIN FORMAT=JSON (MySQL) on the query to obtain the actual execution plan. Look for sequential scans on large tables, nested loop joins with high row estimates, sort operations on unindexed columns, and large gaps between estimated and actual row counts.
Identify optimization opportunities: Based on the plan, identify concrete fixes: add indexes for columns in WHERE, JOIN, and ORDER BY clauses; rewrite subqueries as JOINs; replace SELECT * with specific columns; add LIMIT clauses where appropriate; use covering indexes to avoid table lookups; eliminate redundant or duplicate conditions.
Apply optimizations: Create the necessary indexes, rewrite the query, or adjust ORM usage. For N+1 problems, switch from lazy loading to eager loading (e.g., select_related/prefetch_related in Django, include in Prisma, joinedload in SQLAlchemy). Apply one change at a time to measure each improvement independently.
Measure and validate: Re-run EXPLAIN ANALYZE on the optimized query and compare execution time, rows scanned, and plan structure against the original. Verify that the query returns identical results. Check that new indexes do not degrade write performance beyond acceptable thresholds.
Set up ongoing monitoring: Configure slow query logging with appropriate thresholds (e.g., 100ms for PostgreSQL via log_min_duration_statement). Integrate with monitoring tools like pg_stat_statements, Datadog, or Grafana to track query performance trends and catch regressions early.
Provide the slow SQL query (or describe the ORM operation) along with the database type and approximate table sizes. If possible, include the current EXPLAIN output. The agent will analyze the plan, recommend specific optimizations, and provide the rewritten query with index creation statements. The agent can also review ORM code for N+1 patterns and suggest eager loading fixes.
Problem: A report query joining orders with users and products takes 4.2 seconds on a table with 500K orders.
Original query and EXPLAIN:
EXPLAIN ANALYZE
SELECT *
FROM orders o
JOIN users u ON o.user_id = u.id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON oi.product_id = p.id
WHERE o.status = 'shipped'
AND o.ordered_at >= '2025-01-01';Nested Loop (cost=0.00..98452.30 rows=12340 width=892) (actual time=0.08..4201.33 rows=11842 loops=1)
-> Seq Scan on orders o (cost=0.00..15420.00 rows=24500 width=64) (actual time=0.04..1823.12 rows=24312 loops=1)
Filter: ((status = 'shipped') AND (ordered_at >= '2025-01-01'))
Rows Removed by Filter: 475688
-> Index Scan using order_items_order_id_idx on order_items oi (...)
Planning Time: 0.45 ms
Execution Time: 4201.88 msDiagnosis: Sequential scan on orders (500K rows) filtering by status and ordered_at. No composite index exists for these filter columns. Also selecting all columns when only a subset is needed.
Fix — add a composite index and rewrite the query:
-- Create composite index matching the WHERE clause
CREATE INDEX idx_orders_status_ordered_at ON orders(status, ordered_at);
-- Rewrite query with specific columns
EXPLAIN ANALYZE
SELECT o.id AS order_id, u.full_name, u.email,
p.name AS product_name, oi.quantity, oi.unit_price,
o.ordered_at
FROM orders o
JOIN users u ON o.user_id = u.id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON oi.product_id = p.id
WHERE o.status = 'shipped'
AND o.ordered_at >= '2025-01-01';Optimized EXPLAIN:
Nested Loop (cost=1.12..3842.56 rows=12340 width=198) (actual time=0.06..87.42 rows=11842 loops=1)
-> Index Scan using idx_orders_status_ordered_at on orders o (cost=0.42..892.15 rows=24500 width=24) (actual time=0.03..12.68 rows=24312 loops=1)
Index Cond: ((status = 'shipped') AND (ordered_at >= '2025-01-01'))
-> Index Scan using order_items_order_id_idx on order_items oi (...)
Planning Time: 0.52 ms
Execution Time: 88.04 msResult: Execution time dropped from 4,201ms to 88ms (48x improvement) by replacing a sequential scan with an index scan and reducing the data transferred with specific column selection.
Problem: A view listing 100 orders with their user names and product details generates 201 SQL queries (1 for orders + 100 for users + 100 for products) and takes 1.8 seconds.
Before — N+1 pattern:
# views.py — Triggers N+1 queries
def order_list(request):
orders = Order.objects.filter(status="shipped").order_by("-ordered_at")[:100]
results = []
for order in orders:
results.append({
"id": order.id,
"customer": order.user.full_name, # Lazy load: 1 query per order
"items": [
{"product": item.product.name, "qty": item.quantity}
for item in order.items.all() # Lazy load: 1 query per order
],
})
return JsonResponse(results, safe=False)Django Debug Toolbar output: 201 queries in 1,823ms.
After — eager loading with select_related and prefetch_related:
# views.py — Fixed with eager loading
def order_list(request):
orders = (
Order.objects
.filter(status="shipped")
.select_related("user") # JOIN for user (1:1/FK)
.prefetch_related("items__product") # Prefetch items + products (1:N)
.order_by("-ordered_at")[:100]
)
results = []
for order in orders:
results.append({
"id": order.id,
"customer": order.user.full_name, # No extra query
"items": [
{"product": item.product.name, "qty": item.quantity}
for item in order.items.all() # No extra query
],
})
return JsonResponse(results, safe=False)Django Debug Toolbar output: 3 queries in 42ms.
Result: Query count dropped from 201 to 3, and response time dropped from 1,823ms to 42ms (43x improvement). select_related uses a SQL JOIN for the user FK, while prefetch_related issues a single IN query for all order items and their products.
ANALYZE variant runs the query and shows actual row counts and timings, which often differ significantly from estimates and reveal the real bottleneck.(status, ordered_at) is far more effective than separate indexes on each column, because the database can use a single index range scan.select_related (Django), joinedload (SQLAlchemy), include (Prisma), or includes (ActiveRecord) to batch related-object loading into one or two queries instead of hundreds.pg_stat_statements in PostgreSQL or Performance Schema in MySQL to track the most time-consuming queries by total execution time, not just individual query duration.ANALYZE (PostgreSQL) or ANALYZE TABLE (MySQL) to refresh statistics and get accurate plans.REINDEX (PostgreSQL) or OPTIMIZE TABLE (MySQL) to reclaim space.PREPARE/EXECUTE or set plan_cache_mode = force_custom_plan for queries with highly variable parameter selectivity.QuerySet.query (Django) or .toSQL() (Knex) to inspect the actual SQL and override with raw queries when the ORM's output is suboptimal.© seb1n, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in database/query-optimization of seb1n/awesome-ai-agent-skills.
Open the folder on GitHubat commit 75865a5
Query Optimization next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Query Optimization this skillseb1n/awesome-ai-agent-skills | 206 | — | ~2.6k | Automated safety check: Pass | MIT | |
| Discover Databaserand/cc-polymath | 181 | — | ~2k | Automated safety check: Pass | MIT | |
| Ef Corecodewithmukesh/dotnet-claude-kit | 751 | 1 repos | ~2.3k | Automated safety check: Pass | MIT | |
| Dsqlawslabs/agent-plugins | 912 | — | ~6.9k | Automated safety check: Pass | Apache-2.0 | |
| Postgresdbericrisco/rsc-harness | 156 | — | ~4.4k | Automated safety check: Pass | MIT | |
| SQL ToolkitLeoYeAI/openclaw-master-skills | 2.2k | — | ~3k | Automated safety check: Pass | MIT |
rand/cc-polymath
Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.
codewithmukesh/dotnet-claude-kit
Entity Framework Core patterns for .NET 10. An agent skill from codewithmukesh/dotnet-claude-kit.
awslabs/agent-plugins
Build with Aurora DSQL — manage schemas, execute queries, handle migrations, diagnose query plans, diagnose cluster performance, load data, and develop applications with a serverless, distributed…
ericrisco/rsc-harness
A skill your agent uses when PostgreSQL engine behaviour decides the answer — schema and type design, index choice, reading EXPLAIN on a slow query, zero-downtime DDL and backfills, or ops (roles…
LeoYeAI/openclaw-master-skills
Query, design, migrate, and optimize SQL databases. An agent skill from LeoYeAI/openclaw-master-skills.
hashgraph-online/awesome-codex-plugins
Read and compare Django/PostgreSQL query execution plans using QuerySet.explain(), EXPLAIN, EXPLAIN ANALYZE, scan types, joins, estimates, actual timing, buffers, and row counts.
seb1n/awesome-ai-agent-skills
Plan, execute, document, and retest authorized security assessments of AI agents and multi-agent workflows using safe adversarial cases, synthetic identities, canaries, and evidence-based findings.
seb1n/awesome-ai-agent-skills
Build a preliminary, evidence-based EU AI Act readiness assessment across AI-system inventory, territorial scope, operator roles, prohibited-practice screening, risk classification, transparency…
seb1n/awesome-ai-agent-skills
Design and verify auditable human oversight, approval gates, escalation paths, and safe state transitions for AI agent workflows.
seb1n/awesome-ai-agent-skills
Design, implement, harden, and verify Model Context Protocol (MCP) servers with precise tool contracts, least-privilege authorization, safe transports, structured errors, and interoperability tests.
seb1n/awesome-ai-agent-skills
Inspect, extract, OCR, create, merge, split, reorder, rotate, annotate, fill, redact, compress, secure, and verify PDF documents while preserving source files and visual fidelity.
seb1n/awesome-ai-agent-skills
Audit agent skills, plugins, prompts, manifests, scripts, dependencies, and bundled assets for provenance, prompt-injection, permission, execution, exfiltration, persistence, and update risk.
Works with
Categories
Diagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning. Query Optimization is an agent skill from seb1n/awesome-ai-agent-skills. Diagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning.
Query Optimization fits situations like: the user provides a query; performance symptom; use sql-query-generation when creating a new query from requirements.
Run `npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a claude-code`. Or copy the skill folder (database/query-optimization in seb1n/awesome-ai-agent-skills) into .claude/skills/query-optimization in your project. Claude Code loads it when a task matches its description.
Run `npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a codex`. Or copy the skill folder (database/query-optimization in seb1n/awesome-ai-agent-skills) into .agents/skills/query-optimization in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add seb1n/awesome-ai-agent-skills --skill query-optimization -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/query-optimization, .gemini/skills/query-optimization, .github/skills/query-optimization and .opencode/skills/query-optimization in your project.
SKILL.md names no scripts, command-line tools or credentials: Query Optimization is instructions for the agent only. Our summary lists: Python 3.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Query Optimization is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.
About 2.6k tokens (SKILL.md is roughly 11k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Query Optimization: Discover Database (rand/cc-polymath, 181 stars), Ef Core (codewithmukesh/dotnet-claude-kit, 751 stars), Dsql (awslabs/agent-plugins, 912 stars) and Postgresdb (ericrisco/rsc-harness, 156 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
seb1n (a GitHub user) maintains it in seb1n/awesome-ai-agent-skills, which has 206 GitHub stars. The repository holds 92 skills in this directory. The repository was last updated on August 9, 2026.
Source: seb1n/awesome-ai-agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.