agentleFS
shinzoxDshinzoxD/knackbox/skills/coding/database-indexing/SKILL.md

database-indexing

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Design and review database indexes and query plans — covering

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check existing indexes for redundancy, unused, or wrong column order.

    line 32
  2. Distinctive:

    Call out write cost, bloat, and CREATE INDEX CONCURRENTLY / ONLINE.

    line 33
  3. Very specific:

    Never invent table stats or existing indexes.

    line 65
  4. Distinctive:

    Do not recommend an index that the predicate cannot use (function on the column, leading wildcard, implicit cast).

    line 68
  5. Very specific:

    Already indexed and still slow: look at selectivity, heap fetches, mis-estimates, and whether the query should be rewritten …

    line 84

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Database Indexing

Indexes are a write tax you pay to make a specific read cheap. Name the query first. Do not spray indexes on every foreign key "just in case".

For rewriting one statement, use sql-query-review. For schema change safety, use database-migrations.

Workflow

  1. Dialect, table size (rows/bytes if known), write rate, and the exact query or EXPLAIN.
  2. Restate the access path: equality keys, range keys, ORDER BY, and covering columns.
  3. Propose the smallest index that serves that path (left-prefix, INCLUDE / covering, partial, expression).
  4. Check existing indexes for redundancy, unused, or wrong column order.
  5. Call out write cost, bloat, and CREATE INDEX CONCURRENTLY / ONLINE.
  6. Verification: what EXPLAIN node should disappear, and a rollback (DROP INDEX CONCURRENTLY).

Output format

## Indexing plan: <table / query>

**Dialect / size assumption:** …
**Target access path:** …

### Proposed indexes
```sql
-- CREATE INDEX …

Why this shape

leading columns, range, covering, partial predicate

Do not add

…

Apply / rollback

CONCURRENTLY, lock notes, DROP

Verify

EXPLAIN expectation


## Rules

1. Never invent table stats or existing indexes. If missing, say what
   you assumed or ask for `\d` / `SHOW INDEX` / EXPLAIN.
2. Equality columns before range columns in a B-tree.
3. Do not recommend an index that the predicate cannot use (function
   on the column, leading wildcard, implicit cast).
4. One new index per proven query until writes hurt. Composite beats
   three overlapping singles.
5. Unique constraints *are* indexes; do not duplicate them.
6. Warehouse engines: talk clustering/partition prune/clustering keys,
   not "add a B-tree on user_id", unless the engine has them.
7. `CREATE INDEX` on a large hot table without CONCURRENTLY/ONLINE is
   a finding.

## Edge cases

- **ORM-only:** infer the SQL, then index that SQL — not the object
  graph.
- **Many slow queries:** rank by frequency × latency; index the top
  two, not twenty.
- **Already indexed and still slow:** look at selectivity, heap
  fetches, mis-estimates, and whether the query should be rewritten
  (`sql-query-review`) instead of another index.
- **JSON / arrays:** expression or GIN only when the predicate matches
  the operator class.
---

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.