What is a partial index and when would you use one?
A partial index (also called a filtered index in SQL Server) is an index built only over the rows that satisfy a specified WHERE condition. Instead of indexing every row in a table, the index stores only entries for the rows matching the predicate, making it smaller, faster to scan, and cheaper to maintain on writes.
The canonical use case is a status column with extreme skew. Consider a `jobs` table with 10 million rows where 9.9 million have `status = 'completed'` and 100,000 have `status = 'pending'`. A full index on `status` is large and most of it is useless — queries almost always filter for `pending` jobs. A partial index `CREATE INDEX idx_jobs_pending ON jobs(created_at) WHERE status = 'pending'` covers only 100,000 rows. The index is 100x smaller, fits in cache, and queries for pending jobs execute dramatically faster.
Partial indexes also enforce conditional uniqueness. In PostgreSQL, you can create `CREATE UNIQUE INDEX idx_users_active_email ON users(email) WHERE deleted_at IS NULL` to enforce unique emails only among non-deleted users, allowing multiple soft-deleted rows with the same email without violating the constraint.
For the query optimizer to use a partial index, the query's WHERE clause must be logically compatible with the index predicate — the query's filter must be at least as restrictive. A query with `WHERE status = 'pending' AND created_at > now() - interval '1 day'` would use the partial index above. A query with `WHERE created_at > now() - interval '1 day'` (without the status filter) would not.
Write performance benefits from partial indexes: INSERT/UPDATE/DELETE only update the index when the row satisfies the index predicate. Rows outside the filter incur zero index maintenance cost. This makes partial indexes particularly valuable on append-heavy tables where new rows frequently fall outside the filtered subset.
Defines a partial index as filtering rows by a WHERE condition, gives a concrete skewed-status example, and explains why it's smaller and faster than a full index.
Explains conditional uniqueness enforcement, describes the optimizer compatibility requirement (query WHERE must be compatible with index predicate), and mentions the write-side benefit (index maintenance only for matching rows).
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment