sql-optimization-patterns skill
✓ 인증됨쿼리 실행 계획 분석, 인덱싱 전략, 효율적인 SQL 패턴 구현을 통해 데이터베이스 성능을 최적화합니다.
- GitHub 스타
- 42,413
- 파일
- 2
- 마지막 커밋
- 2026년 11월 9일
- 라이선스
- MIT
- 허용된 도구
- —
sql-optimization-patterns skill은 무엇을 하나요?
sql-optimization-patterns은(는) agent skill입니다. 쿼리 실행 계획 분석, 인덱싱 전략, 효율적인 SQL 패턴 구현을 통해 데이터베이스 성능을 최적화합니다.
skill의 SKILL.md에서 생성된 요약입니다.
sql-optimization-patterns skill 정보
데이터베이스 성능을 개선하고 느린 쿼리를 제거하는 것이 이 SKILL의 주요 기능입니다. 개발자는 이를 사용하여 느린 작업을 디버깅하고, 효율적인 데이터베이스 스키마를 설계하며, 전체적인 데이터베이스 부하 또는 비용을 줄일 수 있습니다. 특히 에이전트가 실행 계획을 분석하거나 애플리케이션 응답 시간을 개선하기 위해 N+1 쿼리 문제를 해결해야 할 때 유용합니다.
에이전트가 PostgreSQL의 EXPLAIN 또는 EXPLAIN ANALYZE 출력을 해석하여 Seq Scan이나 비효율적인 조인 방식과 같은 문제를 식별해야 할 때 이 SKILL을 로드해야 합니다. B-Tree, Hash, GIN, GiST, BRIN을 포함한 다양한 인덱스 유형을 구현하기 위한 구체적인 전략을 제공합니다. 또한 SELECT * 사용을 피하거나 테이블 조인 전 데이터를 필터링하여 JOIN 작업을 최적화하는 것과 같은 실무적인 쿼리 패턴도 다룹니다.
쿼리 작성을 넘어, ANALYZE 또는 VACUUM 명령 실행과 같은 데이터베이스 유지 관리 작업도 지원합니다. 과도한 인덱싱이나 인덱스 사용을 방해하는 암시적 형 변환과 같은 일반적인 실수들을 식별하는 데 도움을 줍니다. 시스템 뷰를 통해 통계를 모니터링함으로써 데이터셋이 커짐에 따라 확장성을 유지할 수 있도록 누락되었거나 사용되지 않는 인덱스를 찾아낼 수 있습니다.
agent가 수행할 수 있는 작업
- 1쿼리 실행 계획 분석PostgreSQL EXPLAIN 출력을 검토하여 느린 전체 테이블 스캔을 식별하고 쿼리 비용을 추정합니다.
- 2특화된 인덱싱 전략 구현데이터 검색 속도를 높이기 위해 JSONB 데이터를 위한 GIN 또는 범위 쿼리를 위한 B-Tree와 같은 특정 인덱스 유형을 생성합니다.
- 3비효율적인 SQL 패턴 리팩토링불필요한 컬럼 조회를 피하고 성능 향상을 위해 조인 로직을 최적화하도록 쿼리를 재작성합니다.
- 4데이터베이스 유지 관리 필요성 식별시스템 통계를 조회하여 사용되지 않거나 누락된 인덱스를 찾아 쓰기 오버헤드를 줄이고 읽기 속도를 개선합니다.
skill의 SKILL.md를 기반으로 작성되었습니다. 모든 사용 사례는 해당 문서의 인용구와 대조 확인되었습니다.
sql-optimization-patterns skill 설치 방법
각 명령은 skill 폴더를 클라이언트의 skills 디렉터리에 복사합니다. 클라이언트를 재시작하거나 새 세션을 시작하여 로드하세요.플러그인에 sql-optimization-patterns skill 설치
/plugin marketplace add wshobson/agents /plugin install developer-essentials@claude-code-workflows
Claude Code에 sql-optimization-patterns skill 설치
~/.claude/skills/sql-optimization-patterns/SKILL.md
$ npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns ~/.claude/skills/sql-optimization-patternsClaude Code (project)에 sql-optimization-patterns skill 설치
.claude/skills/sql-optimization-patterns/SKILL.md
$ npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns .claude/skills/sql-optimization-patternsCodex에 sql-optimization-patterns skill 설치
~/.agents/skills/sql-optimization-patterns/SKILL.md
$ npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns ~/.agents/skills/sql-optimization-patternsGemini CLI에 sql-optimization-patterns skill 설치
~/.gemini/skills/sql-optimization-patterns/SKILL.md
$ npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns ~/.gemini/skills/sql-optimization-patternsClaude.ai에 sql-optimization-patterns skill 설치
npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns sql-optimization-patterns && zip -r sql-optimization-patterns.zip sql-optimization-patterns # claude.ai → Customize → Skills → + → Create skill → Upload a skill → sql-optimization-patterns.zip
자동 검사
2026년 11월 15일에 실행됨전체 보고서 →자동 검사를 통과했습니다. 보안 감사는 아닙니다. 에이전트가 실행하기 전에 스크립트를 읽어 보세요. 검사 방식
- 소스 저장소 연결 및 접근 가능wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns is public and reachablegithub.com/wshobson/agents/tree/HEAD/plugins/developer-essen ↗통과
- 오픈 소스 라이선스 (OSI)MITspdx.org/licenses/MIT.html ↗통과
- 최근 1년 내 커밋 또는 릴리스Last commit 2026-11-09github.com/wshobson/agents/commits ↗통과
- 스크립트에 다운로드 후 실행이나 자격 증명 탈취가 없음No scripts in the skill folder통과
- SKILL.md에 숨겨진 지침 없음No override phrases, safeguard switches, credential requests or hidden charactersgithub.com/wshobson/agents/blob/HEAD/plugins/developer-essen ↗통과
- 사전 허용 도구가 제한됨No pre-approved tools; the agent asks before using onegithub.com/wshobson/agents/blob/HEAD/plugins/developer-essen ↗통과
- SKILL.md가 Agent Skills 형식을 따름Valid name and description; says when to use it; 215 linesgithub.com/wshobson/agents/blob/HEAD/plugins/developer-essen ↗통과
SKILL.md
GitHub에서 보기SQL Optimization Patterns
Transform slow database queries into lightning-fast operations through systematic optimization, proper indexing, and query plan analysis.
When to Use This Skill
- Debugging slow-running queries
- Designing performant database schemas
- Optimizing application response times
- Reducing database load and costs
- Improving scalability for growing datasets
- Analyzing EXPLAIN query plans
- Implementing efficient indexes
- Resolving N+1 query problems
Core Concepts
1. Query Execution Plans (EXPLAIN)
Understanding EXPLAIN output is fundamental to optimization.
PostgreSQL EXPLAIN:
-- Basic explain
EXPLAIN SELECT * FROM users WHERE email = 'user@example.com';
-- With actual execution stats
EXPLAIN ANALYZE
SELECT * FROM users WHERE email = 'user@example.com';
-- Verbose output with more details
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT u.*, o.order_total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '30 days';
Key Metrics to Watch:
- Seq Scan: Full table scan (usually slow for large tables)
- Index Scan: Using index (good)
- Index Only Scan: Using index without touching table (best)
- Nested Loop: Join method (okay for small datasets)
- Hash Join: Join method (good for larger datasets)
- Merge Join: Join method (good for sorted data)
- Cost: Estimated query cost (lower is better)
- Rows: Estimated rows returned
- Actual Time: Real execution time
2. Index Strategies
Indexes are the most powerful optimization tool.
Index Types:
- B-Tree: Default, good for equality and range queries
- Hash: Only for equality (=) comparisons
- GIN: Full-text search, array queries, JSONB
- GiST: Geometric data, full-text search
- BRIN: Block Range INdex for very large tables with correlation
-- Standard B-Tree index
CREATE INDEX idx_users_email ON users(email);
-- Composite index (order matters!)
CREATE INDEX idx_orders_user_status ON orders(user_id, status);
-- Partial index (index subset of rows)
CREATE INDEX idx_active_users ON users(email)
WHERE status = 'active';
-- Expression index
CREATE INDEX idx_users_lower_email ON users(LOWER(email));
-- Covering index (include additional columns)
CREATE INDEX idx_users_email_covering ON users(email)
INCLUDE (name, created_at);
-- Full-text search index
CREATE INDEX idx_posts_search ON posts
USING GIN(to_tsvector('english', title || ' ' || body));
-- JSONB index
CREATE INDEX idx_metadata ON events USING GIN(metadata);
3. Query Optimization Patterns
Avoid SELECT *:
-- Bad: Fetches unnecessary columns
SELECT * FROM users WHERE id = 123;
-- Good: Fetch only what you need
SELECT id, email, name FROM users WHERE id = 123;
Use WHERE Clause Efficiently:
-- Bad: Function prevents index usage
SELECT * FROM users WHERE LOWER(email) = 'user@example.com';
-- Good: Create functional index or use exact match
CREATE INDEX idx_users_email_lower ON users(LOWER(email));
-- Then:
SELECT * FROM users WHERE LOWER(email) = 'user@example.com';
-- Or store normalized data
SELECT * FROM users WHERE email = 'user@example.com';
Optimize JOINs:
-- Bad: Cartesian product then filter
SELECT u.name, o.total
FROM users u, orders o
WHERE u.id = o.user_id AND u.created_at > '2024-01-01';
-- Good: Filter before join
SELECT u.name, o.total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.created_at > '2024-01-01';
-- Better: Filter both tables
SELECT u.name, o.total
FROM (SELECT * FROM users WHERE created_at > '2024-01-01') u
JOIN orders o ON u.id = o.user_id;
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Index Selectively: Too many indexes slow down writes
- Monitor Query Performance: Use slow query logs
- Keep Statistics Updated: Run ANALYZE regularly
- Use Appropriate Data Types: Smaller types = better performance
- Normalize Thoughtfully: Balance normalization vs performance
- Cache Frequently Accessed Data: Use application-level caching
- Connection Pooling: Reuse database connections
- Regular Maintenance: VACUUM, ANALYZE, rebuild indexes
-- Update statistics
ANALYZE users;
ANALYZE VERBOSE orders;
-- Vacuum (PostgreSQL)
VACUUM ANALYZE users;
VACUUM FULL users; -- Reclaim space (locks table)
-- Reindex
REINDEX INDEX idx_users_email;
REINDEX TABLE users;
Common Pitfalls
- Over-Indexing: Each index slows down INSERT/UPDATE/DELETE
- Unused Indexes: Waste space and slow writes
- Missing Indexes: Slow queries, full table scans
- Implicit Type Conversion: Prevents index usage
- OR Conditions: Can't use indexes efficiently
- LIKE with Leading Wildcard:
LIKE '%abc'can't use index - Function in WHERE: Prevents index usage unless functional index exists
Monitoring Queries
-- Find slow queries (PostgreSQL)
SELECT query, calls, total_time, mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;
-- Find missing indexes (PostgreSQL)
SELECT
schemaname,
tablename,
seq_scan,
seq_tup_read,
idx_scan,
seq_tup_read / seq_scan AS avg_seq_tup_read
FROM pg_stat_user_tables
WHERE seq_scan > 0
ORDER BY seq_tup_read DESC
LIMIT 10;
-- Find unused indexes (PostgreSQL)
SELECT
schemaname,
tablename,
indexname,
idx_scan,
idx_tup_read,
idx_tup_fetch
FROM pg_stat_user_indexes
WHERE idx_scan = 0
ORDER BY pg_relation_size(indexrelid) DESC;
이 스킬의 파일
2sql-optimization-patterns skill 질문
Claude Code에 sql-optimization-patterns skill을 어떻게 설치하나요?
npx degit wshobson/agents/plugins/developer-essentials/skills/sql-optimization-patterns ~/.claude/skills/sql-optimization-patterns를 실행합니다. Claude Code는 ~/.claude/skills(모든 프로젝트) 또는 .claude/skills(한 프로젝트)에서 skills를 로드하며, 설명이 작업과 일치할 때 skill을 사용합니다.
sql-optimization-patterns skill을 사용할 수 있는 클라이언트는 무엇인가요?
Agent Skills 형식을 읽는 모든 클라이언트(Claude Code, Codex, Gemini CLI, claude.ai(ZIP으로 업로드))가 사용할 수 있습니다. skill 내 스크립트는 클라이언트가 코드 실행을 허용하는 경우에만 실행됩니다.
PostgreSQL에서 쿼리 실행 계획을 어떻게 분석할 수 있나요?
EXPLAIN 명령어를 사용할 수 있으며, 실제 실행 통계가 필요한 경우 EXPLAIN ANALYZE를, 더 상세한 출력이 필요한 경우 EXPLAIN (ANALYZE, BUFFERS, VERBOSE)를 사용합니다.