A feature-extraction query on a table with 200 million events rows is slow. A teammate says "add an index".
Task
Found a mistake in this question?
Report a problemWhat it is. A sorted lookup structure, usually a B-tree, that lets the database find rows without scanning the whole table.
Index types to know
| Type | Good for |
|---|---|
| B-tree (default) | Equality, ranges, ORDER BY |
| Hash | Equality only |
| Bitmap | Low-cardinality columns in analytic databases |
| GIN / full-text | Text search, arrays, JSON |
| Vector (HNSW, IVFFlat) | Approximate similarity search on embeddings (pgvector) |
Cost
INSERT, UPDATE and DELETE, plus extra storage.WHERE, JOIN and ORDER BY. A column with few distinct values rarely helps.Where it matters in ML
CREATE INDEX idx_events_user_time ON events (user_id, event_time);
Interview line: index for the read path you actually run, then confirm with EXPLAIN.
Log in to mark questions completed and keep your streak.
Log inSpotted a mistake in these answers?
Report a problem