Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

Hash Indexes vs. B-Trees: Which Queries Each Index Supports

In PostgreSQL 17, B-trees handle equality, ranges, and sorted output; hash indexes are for equality only and have schema and scan trade-offs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In PostgreSQL 17, both B-tree and hash indexes can support equality lookups, but only B-trees support range predicates and sorted output. Hash indexes are limited to equality comparisons, so the right choice depends on the query, schema requirements, and database system—not simply on whether a query uses =. Exact behavior varies by database and version.

PostgreSQL 17: which queries can each index support?

PostgreSQL 17 lists B-tree as its default index type for common situations. It supports equality and range searches when the indexed data has a sortable ordering. A hash index supports equality checks only, using the = operator.

As an Amazon Associate I earn from qualifying purchases.

Query need B-tree (PostgreSQL 17) Hash (PostgreSQL 17)
Equality, such as column = value Supported Supported for =
Range predicates: <, <=, >=, > Supported Not supported
BETWEEN or IN Can be implemented with B-tree searches Not supported as range or set searches
Sorted output by the indexed key Can return rows in sorted order Cannot provide ordering by the indexed key

These are capabilities, not guarantees that PostgreSQL will choose an index for every query. The planner decides whether an available index is useful for the particular query and data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What PostgreSQL 17 hash indexes trade away

PostgreSQL hash indexes are persistent, on-disk indexes, but they store a hash value rather than the original column value. Each index tuple stores a four-byte hash value. Because different values can produce the same hash, a hash-index scan is lossy: PostgreSQL may need to visit matching table rows and recheck the original condition.

  • One column: PostgreSQL 17 hash indexes are single-column.
  • No uniqueness enforcement: They cannot perform uniqueness checking. If the schema requires a unique constraint, a hash index is not a substitute.
  • Potentially smaller for long keys: Storing hash values may make an index smaller than a B-tree for longer data such as UUIDs or URLs. This is a possibility, not a universal size or speed advantage.

When a PostgreSQL 17 hash index is worth evaluating

PostgreSQL documentation describes hash indexes as best optimized for equality scans on larger tables in SELECT- and UPDATE-heavy workloads. The rationale is that a B-tree search descends to a leaf, while a hash index accesses the relevant bucket page. Actual benefit depends on the workload and data: overflow pages can chain off a bucket and require additional scanning, and an unbalanced hash index can take more block accesses than a B-tree for some data.

Use a hash index only when equality lookups dominate and the index’s constraints fit the schema. Compare it with a B-tree using the actual query plans and measurements for your application; the documentation does not promise a performance win, and no general speedup follows from choosing hash.

How to choose for a query or schema

  1. Check the predicate. If queries need only equality comparisons, either index type may be eligible in PostgreSQL 17. If they need ranges, BETWEEN, or IN, choose B-tree among these two.
  2. Check ordering needs. If the query needs rows ordered by the indexed key, use B-tree; hash cannot supply that ordering.
  3. Check schema requirements. If uniqueness must be enforced or the index must cover multiple columns, PostgreSQL 17 hash indexes do not meet that requirement.
  4. Evaluate the workload. For long keys and large tables with equality-heavy SELECT and UPDATE activity, test whether hash’s possible space or access tradeoff helps. Include rechecks and any overflow-page work in the evaluation.
  5. Verify planner behavior. Inspect plans and measure representative queries; support for a predicate does not mean the planner will always choose that index.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

MySQL behavior is engine-specific

Oracle’s MySQL 26.7 documentation discusses hash indexes in the context of the MEMORY storage engine. There, hash indexes support equality comparisons with = or the null-safe equality operator <=>, and cannot speed up ORDER BY. Treat this as guidance for that documented engine, not a universal description of every MySQL index configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3

Official documentation

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.