$ recombobulate _
home / tips / let-claude-recommend-the-right-database-indexes-for-your-queries
72

Let Claude Recommend the Right Database Indexes for Your Queries

recombobulate @recombobulate · Mar 26, 2026 · Debugging
let-claude-recommend-the-right-database-indexes-for-your-queries

Query optimisation and indexing are related but different problems. Rewriting a slow query helps — but adding the right index is often what makes it fast. Give Claude your actual query patterns and it will recommend exactly which indexes to add and why.

"Recommend database indexes for these read patterns:

1. SELECT * FROM orders WHERE user_id = ? AND status = 'pending'
   ORDER BY created_at DESC
2. SELECT * FROM products WHERE category_id = ? AND active = 1
   AND price BETWEEN ? AND ?
3. SELECT COUNT(*) FROM audit_logs WHERE model_type = ? AND model_id = ?

For each, explain whether to use a composite or single-column index,
the correct column order, and the trade-off on write performance.
Output Laravel migrations."

Composite index column order matters enormously — Claude explains the selectivity reasoning and picks the right order for each query. It also flags when an index will noticeably hurt write performance so you can make an informed trade-off rather than discover it in production.

// Generated migration
Schema::table('orders', function (Blueprint $table) {
    $table->index(['user_id', 'status', 'created_at'], 'orders_user_status_created_idx');
});

For even better results, include your EXPLAIN output from a slow query log — Claude can read it and pinpoint exactly which index is missing or being ignored by the planner.

An index on the wrong column does nothing — describe your actual query patterns and let Claude pick the right ones.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
161
Ask Claude to Find and Fix the Performance Bottleneck in a Slow Endpoint

When a page takes five seconds to load or an API endpoint times out under load, tell Claude which route is slow and it traces the entire code path — controller, services, queries, loops — identifying N+1 queries, redundant computations, missing indexes, and cacheable operations, then fixes each bottleneck.

recombobulate @recombobulate · 1 month ago
149
Ask Claude to Diagnose and Fix Flaky Tests That Pass Sometimes and Fail Randomly

Flaky tests are maddening — they pass locally, fail in CI, pass again when you retry. Tell Claude to read the test, identify the source of non-determinism — timing issues, shared state, date dependencies, or order-dependent setup — and fix the root cause so the test is reliably green or reliably red.

recombobulate @recombobulate · 1 month ago
148
Paste an Error Message or Stack Trace and Let Claude Trace It to the Root Cause

When your app throws an error, don't just Google the message — paste the full stack trace into Claude Code. It reads the trace, opens the referenced files in your codebase, follows the call chain, and pinpoints the actual root cause instead of just explaining the symptom.

recombobulate @recombobulate · 1 month ago