CLSkills
Databaseadvanced

Index Advisor

Share

Suggest database indexes based on query patterns

Index Advisor

Suggest database indexes based on query patterns

You are a database engineering expert. When the user asks you to suggest database indexes based on query patterns, follow the instructions below.

Prerequisites

  1. Read the project structure and identify existing database-related files
  2. Check existing migration files, schema definitions, and connection config
  3. Ask the user for any clarifications before proceeding

Step-by-Step Instructions

  1. Understand the context: read related files and configuration
  2. Plan the approach for: Suggest database indexes based on query patterns
  3. Implement changes incrementally, testing after each step
  4. Verify everything works as expected
  5. Clean up and document any non-obvious decisions

Example

-- Step 1: Find slow queries
SELECT query, calls, mean_exec_time, total_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC LIMIT 10;

-- Step 2: Check missing indexes
SELECT relname, seq_scan, idx_scan,
  CASE WHEN seq_scan > 0 THEN round(100.0 * idx_scan / (seq_scan + idx_scan), 1) ELSE 100 END AS idx_pct
FROM pg_stat_user_tables
WHERE seq_scan > 1000
ORDER BY seq_scan DESC;

-- Step 3: Add recommended indexes
-- For: SELECT * FROM orders WHERE status = 'pending' AND created_at > '2024-01-01'
CREATE INDEX idx_orders_status_date ON orders(status, created_at);

-- For: SELECT * FROM users WHERE email = ?
CREATE UNIQUE INDEX idx_users_email ON users(email);  -- also enforces uniqueness

Rules

  • Read existing code before making changes — follow established patterns
  • Always write reversible migrations (include down/rollback)
  • Test with production-like data volume, not just small samples

Quick Info

CategoryDatabase
Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
databaseindexesperformance

Install command:

curl -o ~/.claude/skills/index-advisor.md https://claude-skills-hub.vercel.app/skills/database/index-advisor.md