Agent skill

Query Optimization Patterns

by revfactory in revfactory/harness-100

SQL/NoSQL 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드.

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/ko/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
~1k tokens
SKILL.md length
302 words
Files
1
Skills in repo
464
Repo updated
First seen
Licence
Apache-2.0

At a glance

SQL/NoSQL 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드.

  • Tasks that involve Query optimization
  • SKILL.md covers 실행 계획 분석, 인덱스 전략, N+1 문제 해결 and 페이지네이션 최적화, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve NoSQL databases

What it does

Query Optimization Patterns is an agent skill from revfactory/harness-100. SQL/NoSQL 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드. '쿼리 최적화', '실행 계획', 'EXPLAIN', '인덱스 설계', 'N+1 문제', '느린 쿼리', 'slow query', 'DB 성능' 등 데이터베이스 쿼리 성능 개선 시 이 스킬을 사용한다. bottleneck-analyst와 optimization-engineer의 DB 성능 분석 역량을 강화한다. 단, 전체 시스템 프로파일링이나 벤치마크 실행은 이 스킬의 범위가 아니다.

Its SKILL.md is about 1k 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 and NoSQL databases. It works with SQL. The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Query optimization
  • Tasks that involve NoSQL databases

Example prompts

  • “EXPLAIN”
  • “N+1 문제”
  • “slow query”
  • “/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 1k tokens when it runs. Until then it costs about 79 tokens; SKILL.md has 302 words of instructions outside code blocks.

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

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). 302 words, ~1,015 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 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드. '쿼리 최적화', '실행 계획', 'EXPLAIN', '인덱스 설계', 'N+1 문제', '느린 쿼리', 'slow query', 'DB 성능' 등 데이터베이스 쿼리 성능 개선 시 이 스킬을 사용한다. bottleneck-analyst와 optimization-engineer의 DB 성능 분석 역량을 강화한다. 단, 전체 시스템 프로파일링이나 벤치마크 실행은 이 스킬의 범위가 아니다.

Query Optimization Patterns — 쿼리 최적화 패턴 가이드

데이터베이스 쿼리 성능을 체계적으로 분석하고 최적화하는 방법론.

실행 계획 분석

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;
핵심 지표 해석
지표의미위험 신호
Seq Scan전체 테이블 스캔큰 테이블에서 발생 시
Nested Loop행 단위 조인외부 테이블이 클 때
Hash Join해시 기반 조인work_mem 초과 시 디스크 사용
Sort정렬메모리 초과 시 외부 정렬
Bitmap Heap Scan인덱스 → 테이블 접근lossy 비트맵 시 성능 저하
actual time실제 소요 시간첫 행 vs 전체 행 차이
rowsestimated vs actual 차이10배 이상 차이 → 통계 갱신
위험 패턴 탐지
❌ Seq Scan on large_table (rows=10000000)
   → 인덱스 추가 필요

❌ Sort Method: external merge (Disk: 256MB)
   → work_mem 증가 또는 인덱스 정렬

❌ Nested Loop (actual rows=1000000)
   → Hash Join 또는 Merge Join으로 전환

❌ estimated=100 actual=100000
   → ANALYZE 실행하여 통계 갱신

인덱스 전략

인덱스 유형별 사용
인덱스 유형적합한 경우부적합한 경우
B-Tree (기본)등호, 범위, 정렬배열, JSON, 전문 검색
Hash등호 비교만범위 쿼리
GIN배열, JSONB, 전문 검색단순 등호/범위
GiST지리공간, 범위 타입단순 스칼라
BRIN물리적으로 정렬된 데이터랜덤 분포
복합 인덱스 설계 원칙
sql
-- 왼쪽 접두사 규칙 (Leftmost Prefix)
CREATE INDEX idx_orders ON orders(status, created_at, customer_id);

-- 이 인덱스가 커버하는 쿼리:
✅ 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 누락)

-- 컬럼 순서 결정 기준:
-- 1. 등호 조건 컬럼 먼저 (선택도 높은 것)
-- 2. 범위 조건 컬럼 다음
-- 3. ORDER BY 컬럼 마지막
커버링 인덱스
sql
-- 테이블 접근 없이 인덱스만으로 쿼리 완료
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 발생 → 힙 접근 불필요

N+1 문제 해결

문제 진단
python
# N+1 패턴 (느림!)
orders = Order.objects.filter(status="PAID")  # 쿼리 1
for order in orders:
    print(order.customer.name)  # 쿼리 N (주문 수만큼)
# 총 쿼리: 1 + N

# Eager Loading으로 해결
orders = Order.objects.filter(status="PAID").select_related("customer")  # 쿼리 1 (JOIN)
# 또는
orders = Order.objects.filter(status="PAID").prefetch_related("items")  # 쿼리 2 (IN)
ORM별 해결
ORMN+1 해결방법
Djangoselect_related / prefetch_relatedFK JOIN / Reverse IN
SQLAlchemyjoinedload / subqueryloadJOIN / 서브쿼리
TypeORMrelations / @JoinColumneager/lazy 설정
Prismainclude자동 배치
JPA@EntityGraph / JOIN FETCHJPQL/Criteria

페이지네이션 최적화

방식SQL성능적합
OFFSETLIMIT 20 OFFSET 10000O(N) — 느림소규모, 초반 페이지
KeysetWHERE id > 1000 LIMIT 20O(1) — 빠름대규모, 무한 스크롤
Cursor암호화된 keysetO(1)API, 클라이언트용
sql
-- OFFSET (10000번째부터 → 10000행 스캔 후 버림)
SELECT * FROM orders ORDER BY id LIMIT 20 OFFSET 10000;

-- Keyset (즉시 해당 위치로)
SELECT * FROM orders WHERE id > 10000 ORDER BY id LIMIT 20;

쿼리 안티패턴

안티패턴문제해결
SELECT *불필요한 컬럼 전송필요한 컬럼만 명시
WHERE func(column)인덱스 사용 불가변환을 상수 쪽으로 이동
LIKE '%keyword%'풀스캔전문 검색 인덱스(GIN)
서브쿼리 IN (대량)느린 실행JOIN으로 전환
암시적 타입 변환인덱스 무효화타입 일치

쿼리 최적화 체크리스트

  • EXPLAIN ANALYZE 실행하여 실행 계획 확인
  • Seq Scan이 의도적인지 확인 (소량 데이터는 OK)
  • estimated vs actual rows 차이 확인
  • 필요한 인덱스 존재 여부
  • N+1 쿼리 패턴 없는지 확인
  • 페이지네이션이 keyset 기반인지 확인
  • 불필요한 ORDER BY / DISTINCT 제거
  • 트랜잭션 범위가 최소한인지 확인

© 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 ko/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—~1kAutomated safety check: PassApache-2.0
Nw Query OptimizationnWave-ai/nWave617—~1.3kAutomated safety check: PassMIT
DB SculptorEliasOulkadi/shokunin114—~3.1kAutomated safety check: NotesMIT
Postgresql Best Practices CloudbaseTencentCloudBase/CloudBase-AI-Toolkit1.1k1 repos~1.3kAutomated safety check: PassMIT
Discover Databaserand/cc-polymath181—~2kAutomated safety check: PassMIT
Query Expertjamesrochabrun/skills215—~4.3kAutomated safety check: PassMIT

Similar skills

  • Nw Query Optimization

    nWave-ai/nWave

    SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns

    617 GitHub stars~1.3k tokensUpdated 21 days ago
    DatabasesAuto-check passed
  • DB Sculptor

    EliasOulkadi/shokunin

    Design database schemas with Prisma/Drizzle, PostgreSQL index strategy (B-tree, GIN, GiST, BRIN, Hash), query optimization (EXPLAIN ANALYZE), migration safety (expand/contract, zero-downtime), and…

    114 GitHub stars~3.1k tokensUpdated 2 days ago
    DatabasesAuto-check: notes
  • Postgresql Best Practices Cloudbase

    TencentCloudBase/CloudBase-AI-Toolkit

    CloudBase PostgreSQL access-pattern and slow-query quality guidance.

    1.1k GitHub starsUsed in 1 repo~1.3k tokens
    DatabasesAuto-check passed
  • 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.

    181 GitHub stars~2k tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • Query Expert

    jamesrochabrun/skills

    Master SQL and database queries across multiple systems. An agent skill from jamesrochabrun/skills.

    215 GitHub stars~4.3k tokensUpdated 8 mo ago
    DatabasesAuto-check passed
  • Mongodb

    ericrisco/rsc-harness

    A skill your agent uses when modeling MongoDB documents (embed versus reference, the 16MB cap, bucket and subset patterns), choosing or fixing indexes (compound order by the ESR rule, partial, TTL…

    156 GitHub stars~4.8k 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 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드. Query Optimization Patterns is an agent skill from revfactory/harness-100. SQL/NoSQL 쿼리 최적화 패턴, 실행 계획 분석, 인덱스 전략, N+1 문제 해결 등 데이터베이스 성능 최적화 가이드.

When should I use Query Optimization Patterns?

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

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 (ko/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 (ko/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 1k tokens (SKILL.md is roughly 4.1k 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: Nw Query Optimization (nWave-ai/nWave, 617 stars), DB Sculptor (EliasOulkadi/shokunin, 114 stars), Postgresql Best Practices Cloudbase (TencentCloudBase/CloudBase-AI-Toolkit, 1.1k stars) and Discover Database (rand/cc-polymath, 181 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.