SQL Optimization Patterns
ynulihao/AgentSkillOS
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc.
$ npx skills add revfactory/harness-100 --skill query-optimization-patterns -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install revfactory/harness-100 query-optimization-patterns --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/revfactory/harness-100.git skills-src && mkdir -p .claude/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .claude/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .claude/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patternsType 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 revfactory/harness-100 --skill query-optimization-patterns -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install revfactory/harness-100 query-optimization-patterns --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/revfactory/harness-100.git skills-src && mkdir -p .agents/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .agents/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .agents/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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 revfactory/harness-100 --skill query-optimization-patterns -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install revfactory/harness-100 query-optimization-patterns --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/revfactory/harness-100.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .cursor/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .cursor/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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/revfactory/harness-100.git --path en/29-performance-optimizer/.claude/skills/query-optimization-patterns--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 revfactory/harness-100 --skill query-optimization-patterns -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install revfactory/harness-100 query-optimization-patterns --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/revfactory/harness-100.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .gemini/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .gemini/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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 revfactory/harness-100 query-optimization-patternsInstalls 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 revfactory/harness-100 --skill query-optimization-patterns -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/revfactory/harness-100.git skills-src && mkdir -p .github/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .github/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .github/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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 revfactory/harness-100 --skill query-optimization-patterns -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install revfactory/harness-100 query-optimization-patterns --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/revfactory/harness-100.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/en/29-performance-optimizer/.claude/skills/query-optimization-patterns .opencode/skills/query-optimization-patterns && 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-patterns" agent skill from https://github.com/revfactory/harness-100/tree/main/en/29-performance-optimizer/.claude/skills/query-optimization-patterns into .opencode/skills/query-optimization-patterns/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "query-optimization-patterns", 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-optimization-patternsSQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc.
Query Optimization Patterns is an agent skill from revfactory/harness-100. SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc. database performance optimization guide. 'query optimization', 'execution plan', 'EXPLAIN', 'index ', 'N+1 ', 'slow query', 'slow query', 'DB performance' etc. database query performance improvement this for. bottleneck-analystand optimization-engineerof DB performance analysis -ize. , before system profilingthis benchmark execution this of scope .
Its SKILL.md is about 1.3k 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. It works with SQL. The licence is Apache-2.0.
Read from SKILL.md and the folder at commit 8e8d35c. 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 Patterns loads about 1.3k tokens when it runs. Until then it costs about 120 tokens; SKILL.md has 256 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 revfactory/harness-100 at commit 8e8d35c, republished under its Apache-2.0 licence (© revfactory). 256 words, ~1,251 tokens.
.claude/skills/query-optimization-patterns/SKILL.md (or your agent's skills folder).database query performance systematicas analysisand optimizationlower methodology.
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT o.*, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE o.created_at > '2024-01-01'
ORDER BY o.total_amount DESC
LIMIT 10;| metric | of | risk |
|---|---|---|
| Seq Scan | before table | large tablefrom |
| Nested Loop | join | external tablethis |
| Hash Join | hash join | work_mem exceeding disk for |
| Sort | sort | memory exceeding external sort |
| Bitmap Heap Scan | index → table | lossy map performance lower |
| actual time | actual between | vs before this |
| rows | estimated vs actual this | 10 or more this → statistics renewal |
❌ Seq Scan on large_table (rows=10000000)
→ index addition necessary
❌ Sort Method: external merge (Disk: 256MB)
→ work_mem or index sort
❌ Nested Loop (actual rows=1000000)
→ Hash Join or Merge Joinas transition
❌ estimated=100 actual=100000
→ ANALYZE executionto statistics renewal| index type | suitable | unsuitable |
|---|---|---|
| B-Tree (default) | etc., scope, sort | , JSON, before search |
| Hash | etc. only | scope query |
| GIN | , JSONB, before search | simple etc./scope |
| GiST | between, scope type | simple |
| BRIN | -basedas sortthe data | distribution |
-- rule (Leftmost Prefix)
CREATE INDEX idx_orders ON orders(status, created_at, customer_id);
-- this index lower query:
✅ WHERE status = 'PAID'
✅ WHERE status = 'PAID' AND created_at > '2024-01-01'
✅ WHERE status = 'PAID' AND created_at > '2024-01-01' AND customer_id = 123
❌ WHERE created_at > '2024-01-01' (status )
❌ WHERE customer_id = 123 (status, created_at )
-- column decision criteria:
-- 1. etc. cases column (optionalalso high )
-- 2. scope cases column
-- 3. ORDER BY column -- table this indexonlyas query completed
CREATE INDEX idx_covering ON orders(status, created_at) INCLUDE (total_amount);
SELECT total_amount FROM orders
WHERE status = 'PAID' AND created_at > '2024-01-01';
-- Index Only Scan → heap necessary# N+1 pattern (!)
orders = Order.objects.filter(status="PAID") # query 1
for order in orders:
print(order.customer.name) # query N (order countonly)
# query: 1 + N
# Eager Loadingas resolution
orders = Order.objects.filter(status="PAID").select_related("customer") # query 1 (JOIN)
# or
orders = Order.objects.filter(status="PAID").prefetch_related("items") # query 2 (IN)| ORM | N+1 resolution | |
|---|---|---|
| Django | select_related / prefetch_related | FK JOIN / Reverse IN |
| SQLAlchemy | joinedload / subqueryload | JOIN / query |
| TypeORM | relations / @JoinColumn | eager/lazy configuration |
| Prisma | include | automatic |
| JPA | @EntityGraph / JOIN FETCH | JPQL/Criteria |
| SQL | performance | suitable | |
|---|---|---|---|
| OFFSET | LIMIT 20 OFFSET 10000 | O(N) — | , seconds this |
| Keyset | WHERE id > 1000 LIMIT 20 | O(1) — | , |
| Cursor | encryptionthe keyset | O(1) | API, clientfor |
-- OFFSET (10000from → 10000 after )
SELECT * FROM orders ORDER BY id LIMIT 20 OFFSET 10000;
-- Keyset (immediate corresponding locationas)
SELECT * FROM orders WHERE id > 10000 ORDER BY id LIMIT 20;| pattern | resolution | |
|---|---|---|
SELECT * | necessary column before | necessary columnonly people |
WHERE func(column) | index for impossible | transformation constant as this |
LIKE '%keyword%' | before search index(GIN) | |
| query IN () | slow execution | JOINas transition |
| -based type transformation | index invalid-ize | type day |
© revfactory, Apache-2.0. 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 en/29-performance-optimizer/.claude/skills/query-optimization-patterns of revfactory/harness-100.
Open the folder on GitHubat commit 8e8d35c
Query Optimization Patterns 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 Patterns this skillrevfactory/harness-100 | 1.3k | — | ~1.3k | Automated safety check: Pass | Apache-2.0 | |
| SQL Optimization Patternsynulihao/AgentSkillOS | 617 | 10 repos | ~3.3k | Automated safety check: Pass | None | |
| Query Engine Designrevfactory/claude-code-harness | 120 | — | ~474 | Automated safety check: Pass | None | |
| Query Performance Safetydoccker/cc-use-exp | 1.1k | — | ~3.3k | Automated safety check: Pass | Custom licence | |
| SQL Optimization Patternssickn33/agentic-awesome-skills | 47k | 1 repos | ~566 | Automated safety check: Pass | MIT | |
| SQL Database Assistantborghei/Claude-Skills | 874 | — | ~1.5k | Automated safety check: Pass | MIT |
ynulihao/AgentSkillOS
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
revfactory/claude-code-harness
SQL query engine design and implementation guide. An agent skill from revfactory/claude-code-harness.
doccker/cc-use-exp
当代码涉及循环内查询、批量 ID 查询、IN 子句、BFS/递归遍历、嵌套 service 调用时触发。防止 N+1 查询、IN 子句过长、递归内存炸裂等性能陷阱。
sickn33/agentic-awesome-skills
Diagnose slow SQL with query plans, preserve query results, and verify indexing or query changes against representative data.
borghei/Claude-Skills
This skill should be used when the user asks to "optimize SQL queries", "explore database schemas", "generate migration SQL", "analyze query performance", or "document database structure".
PrepLabsAI/InterviewMentor
A Data Engineering interviewer focused on database performance.
revfactory/harness-100
A skill for analyzing website anti-bot defense mechanisms and developing legitimate evasion strategies.
revfactory/harness-100
Reference for designing how an API reports failures: structured error codes, response shapes, client-friendly messages, an error catalog and retry or fallback advice.
revfactory/harness-100
Walks a backend-dev agent through OWASP API Top 10 checks, authentication and authorization patterns, and defense code during API design.
revfactory/harness-100
Methodology for systematically designing and generating CLI tool argument parser structures.
revfactory/harness-100
Audience segmentation skill used by the analyst and curator agents.
revfactory/harness-100
Audio storytelling skill used by the podcast scriptwriter and show note editor.
Works with
Categories
SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc. Query Optimization Patterns is an agent skill from revfactory/harness-100. SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc.
Query Optimization Patterns fits situations like: tasks that involve Query optimization.
Run `npx skills add revfactory/harness-100 --skill query-optimization-patterns -a claude-code`. Or copy the skill folder (en/29-performance-optimizer/.claude/skills/query-optimization-patterns in revfactory/harness-100) into .claude/skills/query-optimization-patterns in your project. Claude Code loads it when a task matches its description.
Run `npx skills add revfactory/harness-100 --skill query-optimization-patterns -a codex`. Or copy the skill folder (en/29-performance-optimizer/.claude/skills/query-optimization-patterns in revfactory/harness-100) into .agents/skills/query-optimization-patterns 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 revfactory/harness-100 --skill query-optimization-patterns -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-patterns, .gemini/skills/query-optimization-patterns, .github/skills/query-optimization-patterns and .opencode/skills/query-optimization-patterns in your project.
SKILL.md names no scripts, command-line tools or credentials: Query Optimization Patterns 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 Patterns is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 1.3k tokens (SKILL.md is roughly 5k 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 Patterns: SQL Optimization Patterns (ynulihao/AgentSkillOS, 617 stars), Query Engine Design (revfactory/claude-code-harness, 120 stars), Query Performance Safety (doccker/cc-use-exp, 1.1k stars) and SQL Optimization Patterns (sickn33/agentic-awesome-skills, 47k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
revfactory (a GitHub user) maintains it in revfactory/harness-100, which has 1,290 GitHub stars. The repository holds 464 skills in this directory. The repository was last updated on March 22, 2026.
Source: revfactory/harness-100 on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.