sql-optimization
Installation
SKILL.md
sql-optimization Skill
Goal
This skill focuses on ensuring database interactions are performant and scalable.
Steps
1. The Golden Rule: Indexing
- Primary Keys: Always indexed by default (B-Tree).
- Foreign Keys: MUST be indexed manually in most DBs (Postgres/MySQL) to avoid full table scans on joins.
- Where Clauses: Columns used in
WHERE,ORDER BY,GROUP BYneed indexes. - Composite Indexes: Order matters!
(last_name, first_name)supports lookup bylast_nameORlast_name + first_name, but NOT byfirst_namealone.
2. Analyzing Queries (EXPLAIN ANALYZE)
Always run EXPLAIN ANALYZE on suspect queries.