Hash equality and ordered access paths

Compare a hash access path with the retained B+ ordering contract, then choose an access method from equality, range and ordering needs. Access methods and index strategy · Databases.

An index is useful only when its organization matches the work the request asks it to do. The retained B+ lesson already shows an ordered path: separators route toward a leaf, the leaf confirms a key, and linked leaves continue a range. This lesson adds a different access structure. Use the comparison to state what equality access gives and what it leaves unspecified: an exact-key request can check bucket candidates, while a range request can use an ordered successor path or another way to enumerate its matches.

Hashing maps equality to a bucket

A hash access path applies a hash function to the lookup key and uses the resulting bucket as a starting point. The bucket does not make the key comparison unnecessary: a collision or multiple candidate entries can still require an equality check. The important teaching boundary is the access shape, not a fixed bucket count, collision rate or timing claim.

Compare request shape with access paths

Read the steps as text

  1. The account_id exact-key and created_at bounded-range requests are visible together. Both paths are named, but neither result is announced.
  2. Bucket selection narrows the equality lookup to candidate entries. The requested key still needs an equality comparison.
  3. The bounded request can use ordered continuation toward its upper bound. The retained B+ contract supplies that walk; hash grouping alone does not.
  4. Equality still needs candidate verification, while a bounded range can use ordered continuation. Planner choice and SQL output ordering remain separate questions.

The first scene holds one logical relation and two possible access paths. The equality request names one exact account_id; the range request names a lower and upper bound. The hash branch shows a bucket and candidate entries, while the B+ branch reuses the retained lesson's ordered contract. Compare the request shape before selecting a path: an exact key asks for equality confirmation, while bounds can use ordered continuation.

For equality, a hash path can narrow the lookup to the bucket associated with the key and then confirm the candidate entry. If two keys share a bucket, the bucket is not itself proof that the requested row matches. The B+ path can also answer equality, but its distinctive property here is that its entries have an order that can support neighbor traversal.

A range needs an ordered continuation

A request for [lower, upper] needs more than finding one matching key. An ordered range walk visits keys in the interval and stops when the upper boundary is passed. In the retained B+ convention, descent finds the lower-bound leaf and successor links continue through ordered leaves. A hash bucket has no equivalent key order, so a hash access path alone does not justify a bounded ordered walk or an ORDER BY result.

Equality checks candidate entries for the requested key; a range must also continue across interval keys.

The absence of ordered traversal does not mean a system can never answer a range predicate. It may use a different ordered index, scan the table, or apply another engine-specific strategy. The claim here is narrower: the hash organization by itself does not supply the B+ range continuation. The planner still compares legal paths against statistics, row retrieval and any ordering requirement.

An equality request looks for matching keys within its candidate bucket. A range request asks for a set of neighboring keys and a stopping boundary. Ordered leaves make that continuation explicit in the retained B+ model. Hash buckets group by a derived location instead, so they do not tell the executor which key comes next. This is a qualitative access-method boundary; it does not prescribe a vendor's implementation or a measured complexity.

Faded: choose from a new request set

In the faded scene, compare a fresh pair of requests: an exact lookup for device_id and a request for devices whose identifiers fall between two bounds. For the exact lookup, decide whether equality confirmation is available from the shown bucket, then decide whether the same hash organization supplies ordered continuation. Treat the bucket as a candidate locator, not as a match, and treat bounds as an ordering requirement rather than another equality lookup. The final frame reveals that the access-path choice follows the predicate and the required order, not the label “index.”

Trace a fresh device access review

Read the steps as text

  1. A new device relation supplies one exact request and one bounded request. The candidate entries are visible without a match or range verdict.
  2. The exact request reaches a candidate entry, but the requested device id must still be compared with that entry.
  3. The bounded request can use a path that continues through an ordered interval; the hash grouping remains an equality organization.
  4. The fresh case keeps equality verification and interval continuation separate; it does not promise a cost, plan, or output ordering.

Do not infer that the hash branch is always cheaper, that a B+ branch is always chosen, or that an observed leaf order becomes SQL result order. The existing index lesson's ORDER BY contract still applies. A plan may choose a sequential scan or another path when the workload and engine make it preferable.

Recap

  • A hash path uses a bucket for equality access and still requires candidate verification.
  • B+ ordering and leaf links support range continuation; a hash organization alone does not provide that order.
  • Access-path selection depends on request shape and planner evidence, and SQL output order still needs ORDER BY.

Next Index keys, coverage and workload fit: apply the access-shape test to composite order, returned data and maintenance cost.

For a related data-structure comparison, practise hash maps in Fundamentals: the map reinforces key association, while this lesson keeps database access paths tied to query and storage contracts.