What are Indexes?
Indexes are data structures that improve query performance by creating optimized access paths to your data:- Speed up queries - Find data faster instead of scanning entire tables
- Enable advanced searches - Support complex search patterns and operations
- Optimize specific use cases - Different index types for different needs
- Trade-off storage for speed - Use extra storage to achieve faster queries
Index Types
Timbal supports several PostgreSQL index types, each optimized for different use cases:B-tree (btree)
Best for equality and range queries on sortable data, e.g. IDs, dates, names, prices.
Hash
Optimized for exact equality comparisons, e.g. status codes, categories.
GIN (Generalized Inverted Index)
Good for full-text search, arrays, and JSON data, e.g. long texts, tags, metadata.
GiST (Generalized Search Tree)
Good for geometric data, full-text search, and nearest-neighbor searches, e.g. locations, nearest neighbors.
BRIN (Block Range Index)
Efficient for very large tables where data has natural clustering, e.g. time series, log data.
Creating Indexes
Only create indexes for columns you actually query - unnecessary indexes waste storage and slow down writes
Index names must be unique across your entire knowledge base - two different tables cannot have indexes with the same name
Composite Indexes
- High selectivity = Many unique values (user_id, email, timestamps)
- Low selectivity = Few unique values (status, boolean flags, categories)
- Good Example
- Poor Example
user_id has thousands of unique values, so the database can quickly narrow down to just a few rows.Composite indexes can only be used from left to right - you can’t skip the first columns.Given an index These queries won’t be as efficient:
["customer_id", "order_date", "status"]:These queries work efficiently:See the API Reference for endpoints to list, delete, monitor, and configure indexes to help you manage them as your data grows.