Basic indexes
Single column index
Create an index on a single column:- PostgreSQL
- MySQL
- SQLite
Composite index
Index multiple columns together for queries filtering on those columns:Column order matters in composite indexes. Place the most selective columns first.
Auto-generated index names
Omit the name to let Drizzle generate one:Unique indexes
Create a unique index to enforce uniqueness and improve lookup performance:PostgreSQL-specific features
Index methods
PostgreSQL supports multiple index methods:'btree'- Default, good for most use cases'hash'- Equality comparisons only'gin'- JSON, arrays, full-text search'gist'- Geometric data, full-text search'spgist'- Space-partitioned data'brin'- Block range indexes for large tables
Partial indexes
Index only rows matching a condition:Concurrent index creation
Create indexes without blocking writes:Concurrent index creation takes longer but doesn’t lock the table.
Index with storage parameters
Specify storage parameters for fine-tuning:Expression indexes
Index computed values:pgvector indexes
For vector similarity search with the pgvector extension:Operator classes
Specify how columns should be indexed:MySQL-specific features
Index types
Index length prefix
For long text columns, index only a prefix:SQLite-specific features
Partial indexes
Expression indexes
Performance tips
1
Index columns used in WHERE clauses
Create indexes on columns frequently used for filtering:
2
Use composite indexes wisely
Put the most selective column first in composite indexes:
3
Consider partial indexes
Index only the data you query:
4
Don't over-index
Each index adds overhead to INSERT/UPDATE operations. Only create indexes you need.
5
Monitor index usage
Use database tools to identify unused indexes and remove them.