index-advisor
Index Advisor Protocol
This skill focuses on making database reads remarkably fast while minimizing write amplification and storage bloat. It recommends standard, composite, partial, and covering indexes based on actual or predicted query workload.
Core principle: Indexes are not free. Every index accelerates reads but slows down writes, inserts, and consumes disk space.
1. Analysis Phase (Static vs. Dynamic)
- Default (Static): Analyze based on provided SQL queries, schema files, or output from
schema-architect. - Dynamic (On-Demand): Only connect to a live database to run
EXPLAINor read actual index usage statistics if the user explicitly requests it.
2. Optimization Methodology
The B-Tree Ordering Rule for Composites
For Composite Indexes, always apply the rule of Equality, Sort, Range:
- Equality: Fields used in
=orIN. - Sort: Fields used in
ORDER BY. - Range: Fields used in
>,<, orBETWEEN.
Example Query:
SELECT * FROM orders WHERE tenant_id = 5 AND status = 'active' ORDER BY created_at DESC LIMIT 10
Recommended Optimal Index: (tenant_id, status, created_at DESC)
Index Type Selection
Select the correct index type according to the target database engine:
- B-Tree: Default for standard lookups, strings, and integers.
- Partial/Filtered Indexes: Highly recommended for sparse data or booleans (e.g.,
WHERE status = 'pending'). - GIN / GiST: For full-text search, arrays, and geospatial data in PostgreSQL.
- BRIN: For large sequential time-series data chunks.
3. The "Drop" Recommendation
Optimization isn't just about adding new indexes. Identify candidates for removal:
- Redundant Indexes: An index on
(A)is entirely redundant and should be dropped if you just created an index on(A, B). - Unused Indexes: Flag non-system indexes with low usage rates.
4. Expected Output Structure
Required Outputs (Must write BOTH to docs/database-report/):
- Human-Readable Markdown (
docs/database-report/index-advisor-report.md)
### ๐ Index Optimization Report
- **Query Addressed:** [Identify specific SQL query]
- **Applied Rule:** Equality, Sort, Range match.
- **Expected Impact:** Prevention of sequential scan of 1M rows.
#### ๐ REQUIRED FIX
```sql
CREATE INDEX CONCURRENTLY idx_orders_tenant_status_date
ON orders (tenant_id, status, created_at DESC);
๐๏ธ CLEANUP
DROP INDEX CONCURRENTLY idx_orders_tenant;
2. **Machine-Readable JSON (`docs/database-report/index-advisor-output.json`)**
```json
{
"skill": "index-advisor",
"recommended_indexes": [
{"table": "orders", "columns": ["tenant_id", "status", "created_at"], "type": "B-Tree", "action": "CREATE"}
],
"redundant_indexes": [
{"table": "orders", "index_name": "idx_orders_tenant", "action": "DROP"}
]
}
Guardrails
- Don't Over-Index: Warn the user if a single table acquires more than 5-7 indexes or if indexes combined overlap the table size.
- Zero-Downtime: ALWAYS recommend
CREATE INDEX CONCURRENTLYin PostgreSQL to avoid locking the table taking down production operations. - High Cardinality Check: Only index where selectivity is high; indexing a boolean col
(is_active)without a partial clause is an anti-pattern.
More from fatih-developer/fth-skills
task-decomposer
Break down large, complex, or ambiguous tasks into independent subtasks with dependency maps, execution order, and success criteria. Plan first, then execute step by step. Triggers on 'how should I do this', 'where do I start', 'plan the project', 'break it down', 'implement' or whenever a task involves multiple phases.
24context-compressor
Compress long conversation histories, large code files, research results, and documents by 70% without losing critical information. Triggers when context window fills up, when summarizing previous steps in multi-step tasks, before loading large files into context, or on 'summarize', 'compress', 'reduce context', 'save tokens'.
18multi-brain-debate
Two-round debate protocol where perspectives challenge each other before consensus. Round 1 presents independent positions, Round 2 allows counter-arguments and rebuttals. Produces battle-tested decisions for high-stakes choices.
17multi-brain-score
Confidence scoring overlay for multi-brain decisions. Each perspective rates its own confidence (1-10) with justification. Consensus uses scores as weights, flags low-confidence areas, and surfaces uncertainty explicitly.
15checkpoint-guardian
Automatic risk assessment before every critical action in agentic workflows. Detects irreversible operations (file deletion, database writes, deployments, payments), classifies risk level, and requires confirmation before proceeding. Triggers on destructive keywords like deploy, delete, send, publish, update database, process payment.
14parallel-planner
Analyze multi-step tasks to identify which steps can run in parallel, build dependency graphs, detect conflicts (write-write, read-write, resource contention), and produce optimized execution plans. Triggers on 3+ independent steps, 'speed up', 'run simultaneously', 'parallelize', 'optimize' or any task where sequential execution wastes time.
14