Filtering Rows with Partial Indexes

Partial indexes are B-Tree indexes that have an expression baked into their definition. The expression can serve the purpose of restricting the rows that are included in the index.

We’ll apply that to soft deletes in a moment. Restricting the rows in an index provides multiple benefits but also trade-offs. Let’s consider the benefits. The index consumes less space. The index contributes less to write latency since entries are only maintained in the index when the expression matches a particular DML operation.

A partial index is a specialized type of index that’s optimized for specific queries by both providing efficient retrieval and efficient storage.

Let’s go back to the soft deletes example. Let’s mix ...

Get High Performance PostgreSQL for Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.