sql-optimization-patterns
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
Skill by jest-won
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/jest-won-sql-optimization-patterns
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
sql-optimization-patterns- Description
- Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
- License
- MIT
- Instructions
- 495 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# 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:**
```sql
-- 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
```sql
-- 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 \*:**
```sql
-- 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:**
```sql
-- 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:**
```sqlFrom jest-won/archi-ro, MIT.
More from jest-won/archi-ro
- 0.409score
task-distributor
jest-won
Use when distributing tasks across multiple agents or workers, managing queues, and balancing workloads to maximize throughput while respecting priorities and…
SkillDFreshness: DClaude Code +9 - 0.409score
agent-organizer
jest-won
Use when assembling and optimizing multi-agent teams to execute complex projects that require careful task decomposition, agent capability matching, and…
SkillDFreshness: DClaude Code +9 - 0.409score
knowledge-synthesizer
jest-won
Use when you need to extract actionable patterns from agent interactions, synthesize insights across multiple workflows, and enable organizational learning…
SkillDFreshness: DClaude Code +9 - 0.409score
multi-agent-coordinator
jest-won
Use when coordinating multiple concurrent agents that need to communicate, share state, synchronize work, and handle distributed failures across a system.
SkillDFreshness: DClaude Code +9 - 0.409score
performance-monitor
jest-won
Use when establishing observability infrastructure to track system metrics, detect performance anomalies, and optimize resource usage across multi-agent…
SkillDFreshness: DClaude Code +9 - 0.409score
coding-conventions
jest-won
Detect and follow existing code style conventions in any project.
SkillDFreshness: DClaude Code +9 - 0.409score
agent-installer
jest-won
Use this agent when the user wants to discover, browse, or install Claude Code agents from the awesome-claude-code-subagents repository.
SkillDFreshness: DClaude Code +9 - 0.409score
ultrawork
jest-won
Use for maximum-precision execution with strict explore-plan-execute-verify loops.
SkillDFreshness: DClaude Code +9 - 0.406score
error-coordinator
jest-won
Use this agent when distributed system errors occur and need coordinated handling across multiple components, or when you need to implement comprehensive…
SkillDFreshness: DClaude Code +9 - 0.406score
architect-reviewer
jest-won
Use this agent when you need to evaluate system design decisions, architectural patterns, and technology choices at the macro level.
SkillDFreshness: DClaude Code +9 - 0.406score
code-reviewer
jest-won
Use this agent when you need to conduct comprehensive code reviews focusing on code quality, security vulnerabilities, and best practices.
SkillDFreshness: DClaude Code +9 - 0.406score
context-manager
jest-won
Use for managing shared state, information retrieval, and data synchronization when multiple agents need coordinated access to context and metadata.
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 1
- Last commit (this folder)
- Mar 11, 2026 (7 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/jest-won/archi-ro
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from jest-won
- 0.409score
knowledge-synthesizer
jest-won
Use when you need to extract actionable patterns from agent interactions, synthesize insights across multiple workflows, and enable organizational learning…
SkillDFreshness: DClaude Code +9 - 0.409score
multi-agent-coordinator
jest-won
Use when coordinating multiple concurrent agents that need to communicate, share state, synchronize work, and handle distributed failures across a system.
SkillDFreshness: DClaude Code +9 - 0.409score
agent-organizer
jest-won
Use when assembling and optimizing multi-agent teams to execute complex projects that require careful task decomposition, agent capability matching, and…
SkillDFreshness: DClaude Code +9 - 0.409score
coding-conventions
jest-won
Detect and follow existing code style conventions in any project.
SkillDFreshness: DClaude Code +9 - 0.409score
agent-installer
jest-won
Use this agent when the user wants to discover, browse, or install Claude Code agents from the awesome-claude-code-subagents repository.
SkillDFreshness: DClaude Code +9 - 0.409score
performance-monitor
jest-won
Use when establishing observability infrastructure to track system metrics, detect performance anomalies, and optimize resource usage across multi-agent…
SkillDFreshness: DClaude Code +9
Cite this page
sql-optimization-patterns skill. Agent Mart. https://agentmart.dev/skills/jest-won-sql-optimization-patterns (last updated 2026-10-24)