docs: add database indexing best practices guide#126
Merged
Conversation
Add docs/api-development/database-indexing.md, a reference for index design in the Drizzle + PostgreSQL stack. The pipeline generates a baseline (B-tree on foreign keys and created_at); this guide covers everything past that: - Defining indexes in Drizzle schema files (pgTable index callback, naming, the generate/migrate workflow, the CONCURRENTLY caveat) - Single-column vs. composite indexes and the leftmost-prefix rule - Unique indexes and constraints (.unique() vs. uniqueIndex(), expression/case-insensitive uniqueness, NULL handling) - Partial indexes for the soft-delete pattern (WHERE deleted_at IS NULL), including partial unique indexes for email reuse - Choosing B-tree vs. GIN vs. GiST (and BRIN), with trigram search and jsonb containment - Index-only scans and covering indexes, noting drizzle-orm 0.45.2 has no .include() so true INCLUDE indexes need a custom migration - Anti-patterns: over-indexing, redundant indexes, low-cardinality columns, unindexed foreign keys, functions over indexed columns - Validating index usage with EXPLAIN ANALYZE All Drizzle examples are verified against the installed drizzle-orm@0.45.2 index API. References the performance-benchmarker agent for automated profiling and links the guide from the API development standards index. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
docs/api-development/database-indexing.md, a reference guide for index design in the Nerva (Drizzle ORM + PostgreSQL) stack. Poor indexing is the most common cause of slow APIs in production. The pipeline generates a baseline (a B-tree on each foreign key and oncreated_at); this guide is the reference for going beyond it.Topics covered
pgTableindex callback, naming convention, the generate/migrate workflow, and theCREATE INDEX CONCURRENTLYcaveat.unique()vs.uniqueIndex(), expression/case-insensitive uniqueness, and NULL handlingWHERE deleted_at IS NULL, tied to the existingnotDeleted()helper, including partial unique indexes so a deleted user's email can be reusedjsonbcontainment andpg_trgmtrigram search examplesdrizzle-orm@0.45.2exposes no.include(), so a trueINCLUDEcovering index needs a custom-SQL migrationEXPLAIN ANALYZE— reading the plan, a before/after, and testing at realistic data volumeEvery Drizzle code example is verified against the installed
drizzle-orm@0.45.2index-builder API.Wiring
performance-benchmarkeragent for automated profiling and index recommendationsdocs/api-development/README.md(Performance section)Notes
200and all internal link targets were verified to exist.Closes #22
🤖 Generated with Claude Code