postgres-indexing
Skill1 starsChanged 2 months agoMITView on GitHub
Choose and verify Postgres indexes for real query shapes — index type (btree / GIN / GiST / BRIN), composite column order, partial / covering / expression indexes, reading EXPLAIN ANALYZE, adding them CONCURRENTLY, and knowing when NOT to index. Use when a query is slow, when reviewing a PR that adds a query, when asked "what index do I need", or "why is this doing a seq scan".
In this repository73 other files it gives its agents.
- AGENTS.mdAGENTS.md
- bigquery-analyticsSkill
- cache-invalidationSkill
- mongo-aggregationSkill
- mongo-modelingSkill
- postgres-aggregationSkill
- redis-coordinationSkill
- redis-patternsSkill
- review-querySkill
- code-migrationSkill
- cut-releaseSkill
- data-migrationSkill
- deploy-serviceSkill
- hotfixSkill
- rollbackSkill
- design-endpointSkill
- design-eventSkill
- design-schemaSkill
- evolve-contractSkill
- scaffold-nestjs-moduleSkill
- scaffold-projectSkill
- incident-responseSkill
- investigate-bugSkill
- on-callSkill
- postmortemSkill
- audit-skillsSkill
- distill-review-styleSkill
- write-skillSkill
- debug-with-tracesSkill
- define-alertsSkill
- instrument-serviceSkill
- evaluate-dependencySkill
- grillSkill
- handoffSkill
- orientSkill
- phased-deliverySkill
- spikeSkill
- to-questionnaireSkill
- write-adrSkill
- write-prdSkill
- devops-pr-reviewSkill
- go-backend-pr-reviewSkill
- nestjs-backend-pr-reviewSkill
- python-backend-pr-reviewSkill
- react-frontend-pr-reviewSkill
- bisectSkill
- break-couplingSkill
- dead-code-sweepSkill
- deslopifySkill
- extract-moduleSkill
- rebase-cleanSkill
- resolve-merge-conflictsSkill
- split-commitSkill
- tddSkill
- wait-whatSkill
- wide-renameSkill
- bullmqSkill
- kafkaSkill
- sqs-consumerSkill
- audit-dependenciesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
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
- Very specific: line 8
Start from the query, not the table.
- Distinctive: line 46
Every index is write amplification and bloat.
- Very specific: line 54
After: re-run EXPLAIN ANALYZE, confirm the plan uses it and is faster.
- Distinctive: line 55
Check for now-redundant indexes (a prefix of the new composite) and drop them.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Postgres indexing
Start from the query, not the table. For each slow or new query, get the plan
first: EXPLAIN (ANALYZE, BUFFERS) <query>.
Reading the plan
- Seq Scan on a large table with a selective
WHERE→ missing/unused index. - Rows estimate wildly off actual → stale stats (
ANALYZE <table>), or a correlation the planner can't see (consider extended statistics). - Filter removing most rows after an index scan → the index doesn't cover the predicate; add the column or use a partial index.
- Sort / Hash spilling to disk →
work_memtoo low, or an index could provide the order. - Nested Loop with high loop count → the join column isn't indexed on the inner side.
Index type
| Use | Type |
| equality, range, sort, most things | btree (default) |
@>, ?, full-text, jsonb containment, array membership | GIN |
| geometry, range types, exclusion constraints, nearest-neighbour | GiST |
| huge append-only table, naturally ordered column (time), tolerate imprecision | BRIN (tiny, cheap) |
| dedupe / uniqueness | btree UNIQUE |
Shaping the index
- Composite column order: equality predicates first, then the range / sort
column.
WHERE tenant_id = ? AND created_at > ? ORDER BY created_at→(tenant_id, created_at). - Partial index —
WHERE status = 'active'when you only ever query active rows. Smaller, faster, and it's the whole index for that query. - Covering index —
INCLUDE (col)so the query is an index-only scan, no heap fetch. - Expression index —
CREATE INDEX ON t (lower(email))if you queryWHERE lower(email) = ?. - Don't index: low-cardinality columns alone (a boolean), tiny tables, write-heavy tables where the read isn't hot, columns never in a predicate. Every index is write amplification and bloat.
Adding safely
CREATE INDEX CONCURRENTLYon any table with live writes — a plainCREATE INDEXtakes anACCESS EXCLUSIVE-ish lock and blocks writes.- Sequence it via
deployment/data-migration; it can't run inside a transaction block. - After: re-run
EXPLAIN ANALYZE, confirm the plan uses it and is faster. - Check for now-redundant indexes (a prefix of the new composite) and drop them.
Anti-patterns
- ❌ Adding an index without
EXPLAINbefore and after. - ❌ Plain
CREATE INDEXon a hot table. - ❌ One index per column instead of a composite matching the query.
- ❌ Indexing a boolean or a tiny table.
- ❌ Leaving redundant/duplicate indexes after adding a composite.
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
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.

