DatabasesPostgreSQL Indexes Explained: Why Some Queries Are Faster Than OthersA database query can be perfectly correct and still perform badly. Consider an application that stores millions of orders and regularly retrieves an order using its customer ID, filters orders by status, or displays a customer's most recent purchases. Without a suitable access path, PostgreSQL may need to examine a large portion of the table to find the rows that satisfy a query. As the table grows, the work can grow with it.
An index gives PostgreSQL another way to locate data. Instead of searching every row in the table, the database can use an auxiliary data structure to identify promising row locations. For selective queries, that can substantially reduce the number of rows and data pages that must be examined.
However, indexes are not automatic performance improvements. They consume storage, require maintenance when data changes, and introduce additional work during inserts, updates, and deletes. An index can also be slower than a sequential scan when a query needs a large…
20 OCT 2026 • 4 MIN READ↗