Hypothetical scenario. Northwind has chosen a relational starting model. The category page still needs its first twenty eligible products in the required order. Dev adds indexes to several columns; Priya asks him to trace the actual query through one of them.
Dev: “Each index might help some future request.”
Maya: “Show the read this structure helps and the work a price change must now maintain.”
Follow a declared access pattern into an ordered access path. Keep lookup work, returned rows and elapsed time distinct. The result should justify a particular index and account for its storage and update consequences, rather than prescribe an index for every field.
Which work does this extra structure avoid?
A table contains records. An index provides another organization of selected keys and references or included data that can help locate qualifying records. A B-tree index maintains an ordered search structure. It can support suitable equality and range conditions without inspecting every record, subject to the particular database’s capabilities and chosen plan.
The existence of an index does not force the optimizer to use it. A query returning much of a small table may be better served by a scan. Estimates, data distribution, ordering and required columns influence the decision. “Indexed” describes an available access structure, not a measured latency result.
PostgreSQL’s index documentation describes several index types and associated capabilities. Northwind’s first proposal uses an ordinary ordered index because its category read combines equality selection with ordered output. Do not transfer every B-tree statement to every specialized index type.
Follow the key order through the query
Consider membership records keyed for access by category, market, display rank and product identifier. With a suitable index in that order, a query fixing category and market can seek toward the corresponding group, then traverse entries in rank and identifier order. The product identifier breaks ties so that the requested ordering is complete.
The price still comes from the applicable price record. This index does not magically include every product field or establish its age. A plan may find membership identifiers efficiently and then fetch product and price records. That remaining work belongs in the request budget, even though the membership selection became cheaper.
If the query instead filters only by market, the same leading category organization may not provide the same efficient bounded path. Database-specific optimizations can alter the details, so inspect the actual plan. The general lesson is to match a proposed access structure to the actual predicate and ordering rather than treating column membership as enough.
Account for index work at the storage engine
Hypothetical scenario. Compare a B-tree access path with an LSM-backed alternative for the same category-and-order query. Keep the database implementation explicit: the existing PostgreSQL discussion is not a claim that its ordinary tables use an LSM engine.
| Access decision | Saved work | New cost |
|---|---|---|
| Composite key order | Narrow category then traverse order | Maintain key on relevant updates |
| Covering fields | Potentially fewer heap fetches | Larger index entries |
| LSM alternative | Batch sorted foreground writes | Runs, filters and compaction debt |
Choose eight leaf pages to inspect in one illustrative index path and three qualifying heap pages to fetch. Logical page visits are 8 + 3 = 11; this is not eleven disk reads or a latency estimate. Buffer residency, visibility checks and concurrent changes determine further work. An index-only plan also needs the engine's visibility conditions, not merely a covering list of columns.
An LSM design can batch sorted writes but eventually pays compaction work and may consult multiple sorted runs on reads. A B-tree maintains its own pages and splits. Neither structure eliminates write, read or space amplification. Compare them under the same update mix and free-space budget, and include background work in survivor capacity. A fast foreground benchmark that ignores deferred compaction debt can select an unsustainable design.
Primary mechanism reference: RocksDB compaction explanation. Use its implementation scope when evaluating this design.
Count selected page work without inventing timings
Hypothetical worked example. Choose a table containing 100,000 membership records and a simplified storage layout of one hundred records per data page. A full scan then visits 100,000 ÷ 100 = 1,000 data pages. This is a teaching layout, not an actual PostgreSQL row-size or page-occupancy claim.
Now choose an index path requiring three internal-page visits and one leaf-page visit to locate and hold the selected twenty entries. If their needed records reside on twenty distinct data pages, selected visits are 3 + 1 + 20 = 24 pages before any separately required price lookups. Relative to the selected scan, avoided visits are 1,000 − 24 = 976.
If those records instead share two data pages, the chosen count becomes 3 + 1 + 2 = 6. The difference between six and twenty-four demonstrates why physical locality and the required fields matter. Neither page count can be converted into milliseconds without additional evidence about caching, storage, concurrency and the actual execution path.
The earlier category request limit of twenty remains a result limit, not a guarantee of twenty inspected entries. If membership eligibility is filtered after index traversal, the engine may inspect more entries to find twenty eligible products. Move the relevant predicate into a usable access strategy where appropriate, or account for the additional inspection.
Count what each extra index stores and changes
For a separate simplified storage estimate, choose forty-eight bytes per index entry. Across 100,000 entries, that is 100,000 × 48 = 4,800,000 bytes of entry payload. Two equivalent-sized indexes contain 2 × 4,800,000 = 9,600,000 bytes before structural overhead, free space and database-specific representation. These are selected accounting inputs, not a storage benchmark.
An inserted membership record also needs entries in each applicable maintained index. With one table and three selected indexes, the logical structures touched are 1 + 3 = 4. This is not a claim of four physical disk writes: logging, buffering, page splits and other implementation work determine physical I/O.
Updates need more careful reasoning. Changing an unindexed field differs from changing an indexed key or a predicate controlling index membership. Adding every column to every index increases maintenance obligations and may enlarge the working set. Give each structure a concrete read requirement and remove one only after checking the workloads that depend on it.
In the wild: access structures are options, not promises
The PostgreSQL index chapter provides a real starting point for checking supported structures, multicolumn behavior and index-only access. Northwind should inspect an execution plan for its declared category query and compare observations under representative data and load. That is how the proposed index becomes evidence about this workload.
A covered or index-only path can reduce separate record access when its requirements are met. Do not infer that behavior solely because some requested fields appear in an index definition. Database-specific visibility and execution rules matter. The design should say what it expects and retain the plan evidence that confirms or challenges it.
When a fast query loses eligible results
Hypothetical failure scenario. Northwind retrieves the first twenty indexed category members, then removes withdrawn products in application code. Only twelve remain. The service reports that the category contains no more eligible results, even though later members qualify. The index made selection fast while the application changed the meaning of the requested page.
The repair is to define selection, eligibility and limit in the proper order, then support that contract with an access path. Fetching more candidates can be a deliberate bounded strategy, but its continuation and exhaustion behavior must be explicit. A quick incomplete answer is not evidence that the original query was satisfied.
Choose the smallest justified index proposal
Use indexes to support demonstrated selections, ordering and constraints. Avoid adding them just because a table may grow. For tiny or broadly scanned datasets, additional structures may offer little benefit. For frequently updated data, maintenance and working-set effects can outweigh a narrow read improvement.
Northwind’s next step is to inspect the category-and-market ordered path, retain the detail identity access and measure the remaining product/price retrieval. The next lesson adds replicas. That will move selected reads to another copy, introducing a new question the index cannot answer: which version is that copy allowed to show?
Challenge the proposed mechanism
The query is fast until a large update burst finishes. Which evidence should an engine comparison include?
Reveal the design reasoning
Observe background maintenance, backlog, read amplification and space during and after the burst. Check whether useful throughput recovers under continuing writes. Do not infer sustainable capacity from foreground acknowledgement speed alone.
Decision and reconsideration: Keep the smallest justified access structure. Reconsider on predicate, skew or maintenance-cost changes using the actual engine plan.
Explain the access path
The selected index path visits twenty-four pages instead of one thousand. Is the latency improvement known?
Keep page work separate from elapsed time
No. The selected model avoids 976 visits, but timing depends on cache state, storage and concurrent work. The page count motivates measurement without supplying a fabricated benchmark.
Does a twenty-item limit guarantee that only twenty membership entries are inspected?
Locate eligibility filtering
No. If some entries are ineligible, the system may need to inspect more to obtain twenty valid results. Applying the limit before required filtering can incorrectly truncate the page.
One table and three indexes are touched on insertion. Does that mean four disk writes?
Separate logical structures from physical I/O
No. Four counts the selected structures. Buffering, logging and page changes determine the physical operations, and must be inspected for the implementation and workload.
An index changes how records are located. Page 14 changes where they are read: another database copy can have an efficient access path while still exposing an older price.
Northwind decision log
Propose an index for the category, market and declared ordering together.
Keep result eligibility and record-fetch work visible after the index lookup.
Evaluate read benefit alongside entry storage and write maintenance before adding structures.
Go deeper: access paths and maintenance
- Book chapter: Use The Index, Luke!, Anatomy of an Index — Markus Winand. Follow the ordered structure before interpreting a query plan.
- Book chapter: The same online guide, Insert, Delete and Update — Markus Winand. Connect index choices to modification work.
- Video lecture: B-Tree vs B+Tree in Production Database Systems — Hussein Nasser. Compare structure and record access without substituting generic timings for measurements.
- Primary document: Indexes — PostgreSQL Global Development Group. Check the implementation’s actual index capabilities.