Posts

Showing posts from July, 2024

Partial Indexes - Postgres

What is a Partial Index? A partial index is an index that is built on a subset of rows in a database table. This subset is defined by a conditional expression, also known as a predicate. By indexing only the rows that meet specific criteria, partial indexes can significantly improve query performance and reduce storage requirements. Why Use a Partial Index? Partial indexes are particularly useful in scenarios where only a limited number of rows are frequently accessed or queried. This is often the case with datasets that exhibit a long-tail distribution , where a small subset of data is accessed much more frequently than the rest. By creating an index only on the frequently accessed rows, you can: Improve query performance by reducing the number of rows scanned. Save storage space since the index is smaller. Reduce maintenance overhead because fewer rows need to be updated in the index when the table is modified. Example Consider a table candidates with a column pr...