What is the difference between range partitioning and hash partitioning?
Sketch your own answer first, then compare it with the one below.
A strong answer
Range partitioning sorts the keys and gives each partition a contiguous stretch of the order. Hash partitioning applies a hash function to the key and uses the result to choose the partition.
Range keeps neighbouring keys together, so a scan over a key range reads from one or two partitions. It can create hot spots when traffic follows the key order, as with timestamps. Hash scatters neighbouring keys, which spreads that kind of traffic evenly, but a scan has to ask many or all partitions.
Rule of thumb: hash when lookups by exact key dominate and even load matters, range when ordered scans matter and the hot ends can be managed.
Sources
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- David DeWitt, Jim Gray (1992). Parallel Database Systems: The Future of High Performance Database Systems.