Overview

Range and hash partitioning are two strategies for splitting a table’s rows across multiple partitions or nodes based on a partition key. Range partitioning assigns rows to contiguous key intervals (like date ranges), preserving order for efficient range scans but risking uneven load. Hash partitioning runs the key through a hash function to scatter rows evenly, trading away ordering for balanced, predictable distribution.

Comparison Diagram

RANGE PARTITIONINGHASH PARTITIONINGincoming keysincoming keys1-3334-6667-1001-3334-6667-100hash(key)P1P2P3P1P2P3Ordered, contiguous rangesScattered, uniform spreadEasy to extend: add a boundaryCostly to resize: rehash keysRisk: skew on hot rangesRisk: no range pruning

Comparison Table

AspectRange PartitioningHash Partitioning
Partition key requirementNeeds an orderable key with defined boundaries (dates, IDs)Any key works; only needs to be hashable
Row-to-partition mappingExplicit boundary rules assign rows to intervalsHash function output (often mod N) selects the bucket
Data distributionCan be skewed if key values aren’t uniformly spreadNear-uniform if the hash function distributes well
Range/scan queriesPrunes to only the partitions covering the rangeMust fan out and scan every partition
Point/equality lookupsRequires a boundary search to find the right partitionDirect O(1) computation locates the partition
Adding or removing partitionsCheap: append or split a boundary at the edgeExpensive: reshuffles most existing keys unless using consistent hashing
Hotspot behaviorSequential writes (recent dates, auto-increment IDs) pile onto one partitionSpreads writes evenly but destroys any physical data locality

Key Differences

  • Range partitioning preserves order, letting the query planner prune partitions; hash partitioning optimizes purely for even distribution
  • Growing the partition count is a cheap boundary edit in range partitioning but forces a rehash of most keys in hash partitioning
  • Range schemes are exposed to skew when writes cluster in a narrow key window; hash schemes avoid this at the cost of locality
  • Point lookups under hashing are a direct hash computation, while range lookups need a boundary search through ordered intervals

When to Use Each

Range Partitioning

  • Time-series or log data: Partitioning by date range lets old partitions be dropped or archived wholesale and keeps recent-data queries fast.
  • Range-predicate heavy queries: Queries like “orders between March and June” prune directly to the relevant partitions instead of scanning everything.
  • Ordered retention or purging: Deleting expired data is a cheap drop-partition operation when partitions align with time or ID ranges.

Hash Partitioning

  • High-throughput writes: Spreading inserts evenly across nodes avoids the single hot partition that sequential keys create under range partitioning.
  • No natural ordering key: When rows have no meaningful sortable key (e.g., UUIDs), hashing still guarantees balanced placement.
  • Distributed key-value storage: Systems needing predictable, uniform shard sizing favor hashing over range boundaries that require ongoing rebalancing.