Database index 2026-11-05
A database index is an auxiliary data structure that helps a database management system locate records satisfying selected conditions. It stores information organized for an access pattern, such as searching a column value, without requiring every database tuple to be inspected. The database query still specifies the result; the index supplies a possible route to it.[ref]
Introduction to Indexes in the PostgreSQL documentation. §11.1, indexed lookup example and maintenance costs
For example, a database relation with a million samples can have an index on
sample_id. Looking for one identifier can follow a search structure instead of scanning all rows. A condition matching most rows may still favor a scan, since many separate lookups and row fetches can cost more. The index occupies storage and must be maintained on relevant updates. These costs explain why indexing every column is not automatically the best design. Database query optimization 2026-11-05
Database query optimization chooses a database query plan for a database query by comparing ways to obtain the required result. The choice includes the order of relational joins, use of a database index, and the algorithms implementing those relational joins. A cost model estimates work from quantities such as input sizes and storage accesses. The selected plan minimizes estimated cost among considered alternatives; this need not be the fastest possible plan in reality.[ref]
Planner and Optimizer in the PostgreSQL documentation. Section 51.5, opening paragraphs and Generating Possible Plans
Consider a relational join of one million orders with customers, followed by a condition selecting ten customers. Applying the customer condition first can greatly shrink a join input. If a suitable database index locates those customers' orders, the engine may avoid scanning all orders. If almost all customers qualify, a sequential scan can instead be cheaper than many scattered index accesses. These are alternative ways of computing the same answer, not different meanings of the query.
Join order also matters with three or more inputs: an early join that creates a huge intermediate result can dominate the total work. Exhaustive search itself becomes expensive as the number of inputs grows. PostgreSQL therefore switches to a heuristic search above a configurable threshold. Inaccurate size estimates can favor a poor plan even when the search algorithm correctly minimizes its cost model.[ref]
Planner and Optimizer in the PostgreSQL documentation. Section 51.5.1, scan alternatives, join sequences and heuristic search
Database query processing 2026-11-05
Database query processing is the sequence that turns a database query into returned results. In a typical SQL system, it includes parsing the text, checking names and types, rewriting the query when appropriate, database query optimization, and executing the chosen database query plan. Planning chooses operations; execution actually performs storage accesses, relational joins, filtering and aggregation.[ref]
For a request for each customer's total order value, the engine might scan orders, group their database tuples by customer identifier, sum the values and return one result per customer. An alternative plan can first restrict the orders using a database index. The result specification alone does not prescribe which access method performs the work.
A query against a stored database view illustrates why processing has more than a text-to-loop step. PostgreSQL can rewrite the reference into a query on the underlying tables before planning. The executor then walks the resulting plan and obtains rows from its operations. The distinction is useful when diagnosing a slow query: excessive planning work, a poor plan, and unexpectedly expensive execution are different causes even if the same statement triggered them.[ref]
PostgreSQL 2026-11-05
PostgreSQL is an open-source object-relational database management system supporting SQL, database transactions, constraints and extensible data types. It manages stored relations and concurrent access through a server, rather than merely defining a database query language. The project descends from the Berkeley POSTGRES system.[ref]
What Is PostgreSQL? in the PostgreSQL documentation. Preface §1, origins and supported features
For example,
SELECT name FROM samples WHERE reading > 5 requests selected rows without prescribing their physical access path. A database index can accelerate retrieval, while database transactions govern the visibility and consistency of related updates. A database relation has no implicit presentation order: a caller needing sorted rows must request an ordering.[ref]Concepts in the PostgreSQL documentation. §2.2, relations, columns and unspecified row order
These distinctions separate logical results from storage organization and display.