/polymath-database:index-strategyfrom polymath-database
Design or prune indexes from the query workload — column order, covering, partial, type, write cost, unused cleanup. Not plan reading.
Ships in polymath-database. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
An index is a trade: faster reads for slower writes, more storage, and more maintenance. Design the smallest set that serves the workload's actual predicates and sorts.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
Not this when: you have a single slow query and want the plan read — polymath-data:sql-optimize. The migration mechanics of shipping the index — polymath-backend:migration-plan.
ORDER BY, and calls/sec (from polymath-database:db-performance-triage or the statements view). Without a workload, say so — an index designed without queries is a guess.pg_stats, INFORMATION_SCHEMA.STATISTICS, or the engine equivalent).INCLUDE, partial/expression support, and online-build options differ.Read-only. Never create or drop an index on a live system from this skill. Recommend the DDL; creation goes through a reviewed migration (online build: CREATE INDEX CONCURRENTLY on Postgres, ALGORITHM=INPLACE, LOCK=NONE on MySQL, ONLINE = ON on SQL Server Enterprise).
table · filter predicates (= / range / IN / LIKE) · join keys · sort · limit · calls/sec. Group patterns that share a prefix — one index often serves several.(a, b) serves a = ? and a = ? AND b …; it does not serve b = ? alone.ORDER BY free: if the sort follows the equality prefix (WHERE customer_id = ? ORDER BY created_at DESC LIMIT 20), (customer_id, created_at DESC) returns rows pre-sorted and stops after 20 — no sort node.INCLUDE (cols) (Postgres 11+, SQL Server) or trailing columns so the query is index-only — but only for hot, narrow reads; wide covering indexes cost more than they save. Index-only scans in Postgres also need a recently vacuumed visibility map.WHERE status = 'pending' indexes only the rows the queue query touches; a fraction of the size and write cost. The query's predicate must imply the index predicate.(lower(email)) when queries use the function; the query must use the identical expression.INSERT, to UPDATEs that touch indexed columns (and in Postgres defeats HOT updates), and to DELETE; also storage and replication/WAL volume. Tables with >5–6 indexes and high write rates need a justification per index.pg_stat_user_indexes.idx_scan, MySQL sys.schema_unused_indexes, SQL Server sys.dm_db_index_usage_stats) after checking stats weren't recently reset and it doesn't enforce a constraint or serve a rare-but-critical job (month-end, failover); exact duplicates; strict prefixes of another index ((a) when (a, b) exists — unless the shorter one is UNIQUE or much smaller matters). Drop one at a time, keep the DDL to recreate it, watch for plan regressions.EXPLAIN (ANALYZE, BUFFERS) — the planner may still prefer a scan if the predicate matches a large fraction of the table, if statistics are stale (ANALYZE), or if a cast/function defeats the index.polymath-backend:migration-plan / review-migration (concurrent build, invalid-index cleanup, disk headroom for the build, replica lag).Index plan: orders (214M rows, 1.8k writes/s, 9 indexes)
Access patterns
P1 WHERE customer_id=? ORDER BY created_at DESC LIMIT 20 18k/s 41% of DB time
P2 WHERE status='pending' AND created_at < now()-interval '15m' 40/s queue sweeper
P3 WHERE lower(email)=? 300/s login lookup
Add
orders_cust_created btree (customer_id, created_at DESC) serves P1; removes the sort; replaces orders_customer_idx
orders_pending_part btree (created_at) WHERE status='pending' serves P2; ~0.3% of rows → a small fraction of a full index's size
users_email_lower btree (lower(email)) — UNIQUE serves P3; also enforces case-insensitive uniqueness
Drop (after review window)
orders_customer_idx strict prefix of orders_cust_created
orders_status_idx 0 scans in 90 d (stats last reset 2025-05-02); not a constraint
orders_created_idx_old identical definition to orders_created_idx (btree created_at)
Write-cost delta: net −1 index on orders → inserts ≈ 8% cheaper [VERIFY: measure insert p95 before/after].
Expected plan change: P1 Seq Scan → Index Scan, no Sort node; verify with EXPLAIN (ANALYZE, BUFFERS) on the replica.
Rollout: CREATE INDEX CONCURRENTLY; 38 GB free disk needed; check pg_index.indisvalid after; drop old indexes in a later migration.
Unknowns: [TBD: month-end reporting query set — confirm orders_status_idx isn't used by it before dropping].
WHERE created_at::date = …, WHERE varchar_col = 123) and then blaming the index.LIKE '%x' expecting a B-tree to help — use trigram (pg_trgm GIN) or full-text search.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub mohammadbafkar/polymath --plugin polymath-database8 skills in this plugin
/data-retention-archivingDesign retention and archiving — tiers, partition-drop purges, legal hold, deletion requests, restore tests — for DBs, event logs, lakes./db-io-tuningCut database IO — cache and working set, read/write amplification, WAL/fsync, checkpoints, bloat, volume IOPS limits. Not plans or indexes./db-performance-triageTriage a slow or saturated database top-down (workload, waits, plans, IO, locks, pools) to ONE bottleneck. Engine-agnostic; not one query plan.Other plugins' skills for the same job