Agent skill

Query Optimization Patterns

by revfactory in revfactory/harness-100

SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc.

Apache-2.0Auto-check passedDatabases

Install Query Optimization Patterns

skills CLI
$ npx skills add revfactory/harness-100 --skill query-optimization-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install revfactory/harness-100 query-optimization-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ 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-src

Use ~/.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/

Facts

Skill name
query-optimization-patterns
GitHub stars
1.3k
Token cost
~1.3k tokens
SKILL.md length
256 words
Files
1
Skills in repo
464
Repo updated
First seen
Licence
Apache-2.0

At a glance

SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc.

  • Tasks that involve Query optimization
  • SKILL.md covers execution plan analysis, index strategy, N+1 resolution and thisthis optimization, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

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.

When your agent uses it

  • Tasks that involve Query optimization

Example prompts

  • “query optimization”
  • “execution plan”
  • “EXPLAIN”
  • “/query-optimization-patterns”

Requirements

  • Python 3

What it can do on your machine

Read from SKILL.md and the folder at commit 8e8d35c. It shows what the files ask for, not the result of running them.

  • Tool permissions

    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.

  • Runs code

    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.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

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.

Always · name and description, kept in context so the agent knows when to use it
~120
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

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.

Safety

Auto-check passed

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.

SKILL.md

The full file from revfactory/harness-100 at commit 8e8d35c, republished under its Apache-2.0 licence (© revfactory). 256 words, ~1,251 tokens.

Download SKILL.mdSave it as .claude/skills/query-optimization-patterns/SKILL.md (or your agent's skills folder).
name
query-optimization-patterns
description
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 .

Query Optimization Patterns — query optimization pattern guide

database query performance systematicas analysisand optimizationlower methodology.

execution plan analysis

PostgreSQL EXPLAIN
sql
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;
core metric
metricofrisk
Seq Scanbefore tablelarge tablefrom
Nested Loopjoinexternal tablethis
Hash Joinhash joinwork_mem exceeding disk for
Sortsortmemory exceeding external sort
Bitmap Heap Scanindex → tablelossy map performance lower
actual timeactual betweenvs before this
rowsestimated vs actual this10 or more this → statistics renewal
risk pattern detection
❌ 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 strategy

index typeper for
index typesuitableunsuitable
B-Tree (default)etc., scope, sort, JSON, before search
Hashetc. onlyscope query
GIN, JSONB, before searchsimple etc./scope
GiSTbetween, scope typesimple
BRIN-basedas sortthe datadistribution
index principle
sql
--   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 
index
sql
-- 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 resolution

python
# 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)
ORMper resolution
ORMN+1 resolution
Djangoselect_related / prefetch_relatedFK JOIN / Reverse IN
SQLAlchemyjoinedload / subqueryloadJOIN / query
TypeORMrelations / @JoinColumneager/lazy configuration
Prismaincludeautomatic
JPA@EntityGraph / JOIN FETCHJPQL/Criteria

thisthis optimization

SQLperformancesuitable
OFFSETLIMIT 20 OFFSET 10000O(N) —, seconds this
KeysetWHERE id > 1000 LIMIT 20O(1) —,
Cursorencryptionthe keysetO(1)API, clientfor
sql
-- 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;

query pattern

patternresolution
SELECT *necessary column beforenecessary columnonly people
WHERE func(column)index for impossibletransformation constant as this
LIKE '%keyword%'before search index(GIN)
query IN ()slow executionJOINas transition
-based type transformationindex invalid-izetype day

query optimization list

  • EXPLAIN ANALYZE executionto execution plan confirmation
  • Seq Scanthis ofalso-based confirmation ( data OK)
  • estimated vs actual rows this confirmation
  • necessary index
  • N+1 query pattern without confirmation
  • thisthisthis keyset confirmation
  • necessary ORDER BY / DISTINCT removal
  • transaction scope minimum confirmation

© 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

Files

Just SKILL.md in en/29-performance-optimizer/.claude/skills/query-optimization-patterns of revfactory/harness-100.

Open the folder on GitHubat commit 8e8d35c

Compare with similar skills

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.

Query Optimization Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Query Optimization Patterns this skillrevfactory/harness-1001.3k—~1.3kAutomated safety check: PassApache-2.0
SQL Optimization Patternsynulihao/AgentSkillOS61710 repos~3.3kAutomated safety check: PassNone
Query Engine Designrevfactory/claude-code-harness120—~474Automated safety check: PassNone
Query Performance Safetydoccker/cc-use-exp1.1k—~3.3kAutomated safety check: PassCustom licence
SQL Optimization Patternssickn33/agentic-awesome-skills47k1 repos~566Automated safety check: PassMIT
SQL Database Assistantborghei/Claude-Skills874—~1.5kAutomated safety check: PassMIT

Similar skills

  • SQL Optimization Patterns

    ynulihao/AgentSkillOS

    Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.

    617 GitHub starsUsed in 10 repos~3.3k tokens
    DatabasesAuto-check passed
  • Query Engine Design

    revfactory/claude-code-harness

    SQL query engine design and implementation guide. An agent skill from revfactory/claude-code-harness.

    120 GitHub stars~474 tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • Query Performance Safety

    doccker/cc-use-exp

    当代码涉及循环内查询、批量 ID 查询、IN 子句、BFS/递归遍历、嵌套 service 调用时触发。防止 N+1 查询、IN 子句过长、递归内存炸裂等性能陷阱。

    1.1k GitHub stars~3.3k tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • SQL Optimization Patterns

    sickn33/agentic-awesome-skills

    Diagnose slow SQL with query plans, preserve query results, and verify indexing or query changes against representative data.

    47k GitHub starsUsed in 1 repo~566 tokens
    DatabasesAuto-check passed
  • SQL Database Assistant

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

    874 GitHub stars~1.5k tokensUpdated today
    DatabasesAuto-check passed
  • SQL Optimization Interviewer

    PrepLabsAI/InterviewMentor

    A Data Engineering interviewer focused on database performance.

    112 GitHub stars~2.1k tokensUpdated today
    DatabasesAuto-check passed

More from revfactory/harness-100

All 464 skills in this repo
  • Anti Bot Analyzer

    revfactory/harness-100

    A skill for analyzing website anti-bot defense mechanisms and developing legitimate evasion strategies.

    1.3k GitHub stars~1.1k tokensUpdated 6 mo ago
    Auto-check passed
  • API Error Design Patterns

    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.

    1.3k GitHub stars~1.6k tokensUpdated 6 mo ago
    Auto-check passed
  • API Security Checklist

    revfactory/harness-100

    Walks a backend-dev agent through OWASP API Top 10 checks, authentication and authorization patterns, and defense code during API design.

    1.3k GitHub stars~1.7k tokensUpdated 6 mo ago
    Auto-check passed
  • Arg Parser Generator

    revfactory/harness-100

    Methodology for systematically designing and generating CLI tool argument parser structures.

    1.3k GitHub stars~1.2k tokensUpdated 6 mo ago
    Auto-check passed
  • Audience Segmentation

    revfactory/harness-100

    Audience segmentation skill used by the analyst and curator agents.

    1.3k GitHub stars~1.3k tokensUpdated 6 mo ago
    Auto-check passed
  • Audio Storytelling

    revfactory/harness-100

    Audio storytelling skill used by the podcast scriptwriter and show note editor.

    1.3k GitHub stars~1.6k tokensUpdated 6 mo ago
    Auto-check passed

Works with

Categories

Questions about Query Optimization Patterns

What does Query Optimization Patterns do?

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.

When should I use Query Optimization Patterns?

Query Optimization Patterns fits situations like: tasks that involve Query optimization.

How do I install Query Optimization Patterns in Claude Code?

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.

How do I install Query Optimization Patterns in Codex?

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.

Can I use Query Optimization Patterns in Cursor, Gemini CLI or GitHub Copilot?

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.

What does Query Optimization Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Query Optimization Patterns is instructions for the agent only. Our summary lists: Python 3.

Does Query Optimization Patterns access the network?

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.

Is Query Optimization Patterns safe to install?

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.

What licence does Query Optimization Patterns use?

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.

How many tokens does Query Optimization Patterns use?

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.

What are the alternatives to Query Optimization Patterns?

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.

Who maintains Query Optimization Patterns?

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.