Why are range queries expensive under hash partitioning?
Sketch your own answer first, then compare it with the one below.
A strong answer
A range query asks for all keys between two bounds. Under hash partitioning, those keys have unrelated hashes, so they are spread over all the partitions. The query has to be sent to every partition that might hold a match, usually all of them, and the results merged.
The cost is the fan-out, since latency is set by the slowest partition, and the total work is multiplied by the number of partitions. Under range partitioning the same query touches one or two partitions.
Single-key lookups are unaffected. Some stores keep scans affordable by hashing only a prefix of the key and sorting by the rest, so a scan within one prefix stays on one partition.
Sources
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- David DeWitt, Jim Gray (1992). Parallel Database Systems: The Future of High Performance Database Systems.