Linear hashing

From HandWiki

Linear hashing (LH) is a dynamic data structure which implements a hash table and grows or shrinks one bucket at a time. It was invented by Witold Litwin in 1980.[1] [2] It has been analyzed by Baeza-Yates and Soza-Pollman.[3] It is the first in a number of schemes known as dynamic hashing[3] [4] such as Larson's Linear Hashing with Partial Extensions, [5] Linear Hashing with Priority Splitting,[6] Linear Hashing with Partial Expansions and Priority Splitting,[7] or Recursive Linear Hashing.[8]

The file structure of a dynamic hashing data structure adapts itself to changes in the size of the file, so expensive periodic file reorganization is avoided.[4] A Linear Hashing file expands by splitting a pre-determined bucket into two and shrinks by merging two predetermined buckets into one. The trigger for a reconstruction depends on the flavor of the scheme; it could be an overflow at a bucket or load factor (i.e., the number of records divided by the number of buckets) moving outside of a predetermined range.[1] In Linear Hashing there are two types of buckets, those that are to be split and those already split. While extendible hashing splits only overflowing buckets, spiral hashing (a.k.a. spiral storage) distributes records unevenly over the buckets such that buckets with high costs of insertion, deletion, or retrieval are earliest in line for a split.[5]

Linear Hashing has also been made into a scalable distributed data structure, LH*. In LH*, each bucket resides at a different server.[9] LH* itself has been expanded to provide data availability in the presence of failed buckets.[10] Key based operations (inserts, deletes, updates, reads) in LH and LH* take maximum constant time independent of the number of buckets and hence of records.[1][10]

Algorithm details

Records in LH or LH* consists of a key and a content, the latter basically all the other attributes of the record.[1][10] They are stored in buckets. For example, in Ellis' implementation, a bucket is a linked list of records.[2] The file allows the key based CRUD operations create or insert, read, update, and delete as well as a scan operations that scans all records, for example to do a database select operation on a non-key attribute.[10] Records are stored in buckets whose numbering starts with 0.[10]

The key distinction from schemes such as Fagin's extendible hashing is that as the file expands due to insertions, only one bucket is split at a time, and the order in which buckets are split is already predetermined.[11]

Hash functions

The hash function [math]\displaystyle{ h_i(c) }[/math] returns the 0-based index of the bucket that contains the record with key [math]\displaystyle{ c }[/math]. When a bucket which uses the hash function [math]\displaystyle{ h_i }[/math] is split into two new buckets, the hash function [math]\displaystyle{ h_i }[/math] is replaced with [math]\displaystyle{ h_{i+1} }[/math] for both of those new buckets. At any time, at most two hash functions [math]\displaystyle{ h_l }[/math] and [math]\displaystyle{ h_{l+1} }[/math] are used; such that [math]\displaystyle{ l }[/math] corresponds to the current level. The family of hash functions [math]\displaystyle{ h_i(c) }[/math] is also referred to as the dynamic hash function.

Typically, the value of [math]\displaystyle{ i }[/math] in [math]\displaystyle{ h_i }[/math] corresponds to the number of rightmost binary digits of the key [math]\displaystyle{ c }[/math] that are used to segregate the buckets. This dynamic hash function can be expressed arithmetically as [math]\displaystyle{ h_i(c) \mapsto (c \bmod 2^i) }[/math]. Note that when the total number of buckets is equal to one, [math]\displaystyle{ i=0 }[/math].

Complete the calculations below to determine the correct hashing function for the given hashing key [math]\displaystyle{ c }[/math].[10]

# l represents the current level
# s represents the split pointer index
a = h_l(c)
if (a < s): a = h_{l+1}(c)

Split control

Linear hashing algorithms may use only controlled splits or both controlled and uncontrolled splits.

Controlled splitting occurs if a split is performed whenever the load factor, which is monitored by the file, exceeds a predetermined threshold.[10] If the hash index uses controlled splitting, the buckets are allowed to overflow by using linked overflow blocks. When the load factor surpasses a set threshold, the split pointer's designated bucket is split. Instead of using the load factor, this threshold can also be expressed as an occupancy percentage, in which case, the maximum number of records in the hash index equals (occupancy percentage)*(max records per non-overflowed bucket)*(number of buckets).[12]

An uncontrolled split occurs when a split is performed whenever a bucket overflows, in which case that bucket would be split into two separate buckets.

File contraction occurs in some LH algorithm implementations if a controlled split causes the load factor to sink below a threshold. In this case, a merge operation would be triggered which would undo the last split, and reset the file state.[10]

Split pointer

The index of the next bucket to be split is part of the file state and called the split pointer [math]\displaystyle{ s }[/math]. The split pointer corresponds to the first bucket that uses the hash function [math]\displaystyle{ h_l }[/math] instead of [math]\displaystyle{ h_{l+1} }[/math].[10]

For example, if numerical records are inserted into the hash index according to their farthest right binary digits, the bucket corresponding with the appended bucket will be split. Thus, if we have the buckets labelled as 000, 001, 10, 11, 100, 101, we would split the bucket 10 because we are appending and creating the next sequential bucket 110. This would give us the buckets 000, 001, 010, 11, 100, 101, 110.[12]

When a bucket is split, split pointer and possibly the level are updated according to the following, such that the level is 0 when the linear hashing index only has 1 bucket.[10]

# l represents the current level
# s represents the split pointer index
s = s + 1
if (s >= 2^l): 
    l = l + 1
    s = 0

LH*

The main contribution of LH* is to allow a client of an LH* file to find the bucket where the record resides even if the client does not know the file state. Clients in fact store their version of the file state, which is initially just the knowledge of the first bucket, namely Bucket 0. Based on their file state, a client calculates the address of a key and sends a request to that bucket. At the bucket, the request is checked and if the record is not at the bucket, it is forwarded. In a reasonably stable system, that is, if there is only one split or merge going on while the request is processed, it can be shown that there are at most two forwards. After a forward, the final bucket sends an Image Adjustment Message to the client whose state is now closer to the state of the distributed file.[10] While forwards are reasonably rare for active clients, their number can be even further reduced by additional information exchange between servers and clients [13]

Other properties

File state calculation

The file state consists of split pointer [math]\displaystyle{ s }[/math] and level [math]\displaystyle{ l }[/math]. If the original file started with [math]\displaystyle{ N=1 }[/math] buckets, then the number of buckets [math]\displaystyle{ n }[/math] and the file state are related via [13]

[math]\displaystyle{ n = 2^l+s }[/math].

Adoption in language systems

Griswold and Townsend [14] discussed the adoption of linear hashing in the Icon language. They discussed the implementation alternatives of dynamic array algorithm used in linear hashing, and presented performance comparisons using a list of Icon benchmark applications.

Adoption in database systems

Linear hashing is used in the Berkeley database system (BDB), which in turn is used by many software systems, using a C implementation derived from the CACM article and first published on the Usenet in 1988 by Esmond Pitt.

References

  1. 1.0 1.1 1.2 1.3 Litwin, Witold (1980), "Linear hashing: A new tool for file and table addressing", Proc. 6th Conference on Very Large Databases: 212–223, https://www.cs.cmu.edu/afs/cs.cmu.edu/user/christos/www/courses/826-resources/PAPERS+BOOK/linear-hashing.PDF 
  2. 2.0 2.1 Ellis, Carla Schlatter (June 1987), "Concurrency in Linear Hashing", ACM Transactions on Database Systems 12 (2): 195–217, doi:10.1145/22952.22954 
  3. 3.0 3.1 Baeza-Yates, Ricardo; Soza-Pollman, Hector (1998), "Analysis of Linear Hashing Revised", Nordic Journal of Computing: 70–85, http://pdfs.semanticscholar.org/e6cd/667fef7cd377ed8d417cc648d3d578675ad5.pdf 
  4. 4.0 4.1 Enbody, Richard; Du, HC (June 1988), "Dynamic hashing schemes", ACM Computing Surveys 20 (2): 85–113, doi:10.1145/46157.330532 
  5. 5.0 5.1 Larson, Per-Åke (April 1988), "Dynamic Hash Tables", Communications of the ACM 31 (4): 446–457, doi:10.1145/42404.42410 
  6. Ruchte, Willard; Tharp, Alan (Feb 1987), "Linear hashing with Priority Splitting: A method for improving the retrieval performance of linear hashing", IEEE Third International Conference on Data Engineering: 2–9 
  7. Manolopoulos, Yannis; Lorentzos, N. (1994), "Performance of linear hashing schemes for primary key retrieval", Information Systems 19 (5): 433–446, doi:10.1016/0306-4379(94)90005-1 
  8. Ramamohanarao, K.; Sacks-Davis, R. (Sep 1984), "Recursive linear hashing", ACM Transactions on Databases 9 (3): 369–391, doi:10.1145/1270.1285 
  9. Litwin, Witold; Neimat, Marie-Anne; Schneider, Donavan A. (1993), "LH: Linear Hashing for distributed files", ACM SIGMOD Record 22 (2): 327–336, doi:10.1145/170036.170084 
  10. 10.00 10.01 10.02 10.03 10.04 10.05 10.06 10.07 10.08 10.09 10.10 Litwin, Witold; Moussa, Rim; Schwarz, Thomas (Sep 2005), "LH*RS - a highly-available scalable distributed data structure", ACM Transactions on Database Systems 30 (3): 769–811, doi:10.1145/1093382.1093386, https://basepub.dauphine.fr/handle/123456789/15124 
  11. Fagin, Ronald; Nievergelt, Jurg; Pippenger, Nicholas; Strong, Raymond (Sep 1979), "Extendible Hashing - A Fast Access Method for Dynamic Files", ACM Transactions on Database Systems 4 (2): 315–344, doi:10.1145/320083.320092, http://dl.acm.org/citation.cfm?doid=320083.320092 
  12. 12.0 12.1 Silberschatz, Abraham; Korth, Henry F.; Sudarshan, S. (2020). Database system concepts (Seventh ed.). New York, NY: McGraw-Hill Education. ISBN 978-1-260-08450-4. 
  13. 13.0 13.1 Chabkinian, Juan; Schwarz, Thomas (2016), "Fast LH*", International Journal of Parallel Programming 44 (4): 709–734, doi:10.1007/s10766-015-0371-8 
  14. Griswold, William G.; Townsend, Gregg M. (April 1993), "The Design and Implementation of Dynamic Hashing for Sets and Tables in Icon", Software: Practice and Experience 23 (4): 351–367, doi:10.1002/spe.4380230402, http://citeseer.ist.psu.edu/griswold93design.html 

External links

See also