Dynamic Hashing (Chapter 12)

Slides:



Advertisements
Similar presentations
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part C Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Advertisements

Hashing Dashiell Fryer CS 157B Dr. Lee. Contents Static Hashing Static Hashing File OrganizationFile Organization Properties of the Hash FunctionProperties.
Hash-based Indexes CS 186, Spring 2006 Lecture 7 R &G Chapter 11 HASH, x. There is no definition for this word -- nobody knows what hash is. Ambrose Bierce,
1 Hash-Based Indexes Module 4, Lecture 3. 2 Introduction As for any index, 3 alternatives for data entries k* : – Data record with key value k – –Choice.
1 Linear Hashing Appendix for Chapter 1. 2 Linear Hashing Allow a hash file to expand and shrink dynamically without needing a directory. Suppose the.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11.
Quick Review of Apr 10 material B+-Tree File Organization –similar to B+-tree index –leaf nodes store records, not pointers to records stored in an original.
Department of Computer Science and Engineering, HKUST Slide 1 Dynamic Hashing Good for database that grows and shrinks in size Allows the hash function.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11.
Indexing (Cont.) These slides are a modified version of the slides of the book “Database System Concepts” (Chapter 12), 5th Ed., McGraw-Hill,McGraw-Hill.
Chapter 11 Indexing and Hashing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 11: Indexing.
Chapter 11 (3 rd Edition) Hash-Based Indexes Xuemin COMP9315: Database Systems Implementation.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
Dr. Kalpakis CMSC 661, Principles of Database Systems Index Structures [13]
Arch (A) Tented Arch (T) Whorl (W) Loop (U or R) The four main classes of fingerprints Loop (60%) Arch/Tented Arch (6%) Whorl (34%) Other (Less than 1%)
1 Indexing and Hashing Indexing and Hashing Basic Concepts Dense and Sparse Indices B+Trees, B-trees Dynamic Hashing Comparison of Ordered Indexing and.
1 Hash-Based Indexes Chapter Introduction  Hash-based indexes are best for equality selections. Cannot support range searches.  Static and dynamic.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
1 Hash-Based Indexes Chapter Introduction : Hash-based Indexes  Best for equality selections.  Cannot support range searches.  Static and dynamic.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Hashing.
Computing & Information Sciences Kansas State University Friday, 24 Oct 2008CIS 560: Database System Concepts Lecture 23 of 42 Friday, 24 October 2008.
12.1 Chapter 12: Indexing and Hashing Spring 2009 Sections , , Problems , 12.7, 12.8, 12.13, 12.15,
Hashing and Hash-Based Index. Selection Queries Yes! Hashing  static hashing  dynamic hashing B+-tree is perfect, but.... to answer a selection query.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11 Modified by Donghui Zhang Jan 30, 2006.
Introduction to Database, Fall 2004/Melikyan1 Hash-Based Indexes Chapter 10.
1.1 CS220 Database Systems Indexing: Hashing Slides courtesy G. Kollios Boston University via UC Berkeley.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Indexed Sequential Access Method.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 10.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module D: Hashing.
Chapter 5 Record Storage and Primary File Organizations
Azita Keshmiri CS 157B Ch 12 indexing and hashing
Hash-Based Indexes Chapter 11
Hashing CENG 351.
Chapter 12: Indexing and Hashing
Chapter 11: Indexing and Hashing
Database Management Systems (CS 564)
Dynamic Hashing.
Chapter 11: Indexing and Hashing
Extendible Indexing Dina Said
Chapter 12: Indexing and Hashing
Introduction to Database Systems
External Memory Hashing
CS222: Principles of Data Management Notes #8 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Hash-Based Indexes Chapter 10
Indexing and Hashing Basic Concepts Ordered Indices
CS222P: Principles of Data Management Notes #8 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Hashing.
Hash-Based Indexes Chapter 11
Index tuning Hash Index.
Advance Database System
Chapter 12: Indexing and Hashing
Chapter 12: Indexing and Hashing
Indexing and Hashing B.Ramamurthy Chapter 11 2/5/2019 B.Ramamurthy.
Database Systems (資料庫系統)
LINEAR HASHING E0 261 Jayant Haritsa Computer Science and Automation
2018, Spring Pusan National University Ki-Joune Li
Chapter 12: Indexing and Hashing
Chapter 12: Indexing and Hashing
Module 12a: Dynamic Hashing
Index tuning Hash Index.
Chapter 12: Indexing and Hashing
Hash-Based Indexes Chapter 11
Chapter 12: Indexing and Hashing
Chapter 12: Indexing and Hashing
Chapter 12: Indexing and Hashing
Chapter 11 Instructor: Xin Zhang
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #07 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Presentation transcript:

Dynamic Hashing (Chapter 12)

Deficiencies of Static Hashing In static hashing, function h maps search-key values to a fixed set of B of bucket addresses. Databases grow with time. If initial number of buckets is too small, performance will degrade due to too much overflows. If file size at some point in the future is anticipated and number of buckets allocated accordingly, significant amount of space will be wasted initially. If database shrinks, again space will be wasted. One option is periodic re-organization of the file with a new hash function, but it is very expensive. These problems can be avoided by using techniques that allow the number of buckets to be modified dynamically.

Dynamic Hashing Good for database that grows and shrinks in size Allows the hash function to be modified dynamically Extendable hashing – one form of dynamic hashing Hash function generates values over a large range — typically b-bit integers, with b = 32. At any time use only a prefix of the hash function to index into a table of bucket addresses. Let the length of the prefix be i bits, 0  i  32. (global depth) Bucket address table size = 2i. Initially i = 0 Value of i grows and shrinks as the size of the database grows and shrinks. Multiple entries in the bucket address table may point to a bucket. Thus, actual number of buckets is < 2i The number of buckets also changes dynamically due to coalescing and splitting of buckets.

General Extendable Hash Structure In this structure, i2 = i3 = i, whereas i1 = i – 1 (see next slide for details)

Use of Extendable Hash Structure Each bucket j stores a value ij(local depth); all the entries that point to the same bucket have the same values on the first ij bits. To locate the bucket containing search-key Kj: 1. Compute h(Kj) = X 2. Use the first i high order bits of X as a displacement into bucket address table, and follow the pointer to appropriate bucket To insert a record with search-key value Kj follow same procedure as look-up and locate the bucket, say j. If there is room in the bucket j insert record in the bucket. Else the bucket must be split and insertion re-attempted (next slide.) Overflow buckets used instead in some cases (will see shortly)

Updates in Extendable Hash Structure To split a bucket j when inserting record with search-key value Kj: If i > ij (more than one pointer to bucket j) allocate a new bucket z, and set ij and iz to the old ij -+ 1. make the second half of the bucket address table entries pointing to j to point to z remove and reinsert each record in bucket j. recompute new bucket for Kj and insert record in the bucket (further splitting is required if the bucket is still full) If i = ij (only one pointer to bucket j) increment i and double the size of the bucket address table. replace each entry in the table by two entries that point to the same bucket. recompute new bucket address table entry for Kj Now i > ij so use the first case above.

Updates in Extendable Hash Structure (Cont.) When inserting a value, if the bucket is full after several splits (that is, i reaches some limit b) create an overflow bucket instead of splitting bucket entry table further. To delete a key value, locate it in its bucket and remove it. The bucket itself can be removed if it becomes empty (with appropriate updates to the bucket address table). Coalescing of buckets can be done (can coalesce only with a “buddy” bucket having same value of ij and same ij –1 prefix, if it is present) Decreasing bucket address table size is also possible Note: decreasing bucket address table size is an expensive operation and should be done only if number of buckets becomes much smaller than the size of the table

Use of Extendable Hash Structure: Example Initial Hash structure, bucket size = 2

Example (Cont.) Hash structure after insertion of one Brighton and two Downtown records Sample account file

Hash structure after insertion of Mianus record Example (Cont.) Hash structure after insertion of Mianus record Sample account File

Hash structure after insertion of three Perryridge records Example (Cont.) Sample account File Hash structure after insertion of three Perryridge records

Example (Cont.) Sample account File Hash structure after insertion of Redwood and Round Hill records Sample account File

Extendable Hashing vs. Other Schemes Benefits of extendable hashing: Hash performance does not degrade with growth of file Minimal space overhead Disadvantages of extendable hashing Extra level of indirection to find desired record Bucket address table may itself become very big (larger than memory) Need a tree structure to locate desired record in the structure! Changing size of bucket address table is an expensive operation Linear hashing is an alternative mechanism which avoids these disadvantages at the possible cost of more bucket overflows

Linear Hashing Allow a hash file to expand and shrink its number of buckets dynamically without needing a directory Uses a initial hash function hi(K) = K mod M with M buckets numbered 0, 1, 2, …M-1 Collisions are handled by maintaining individual overflow chains for each bucket. When a collision leads to an overflow in any bucket, the first bucket, bucket 0, is split into two buckets – the original bucket 0 and and a new bucket M at the end of the file. The records originally in bucket 0 are distributed between the two buckets based on a different hash function hi+1(K) = K mod 2M. As further collisions lead to overflow records, additional buckets are split in linear order 1, 2, 3, ….(a value n is used to keep track of it) When all the M buckets are split into 2M buckets, all buckets use the hash function hi+1 and n is reset 0.

Linear Hashing (Contd.) Any new collisions which cause overflow lead to the use of a new has function hi+2(K) = K mod 4M. In general, s sequence of hashing functions hi+j(K)=K mod (2jM) is used. Splitting can be controlled by monitoring the file load factor, l=r/(bfr*N), r is the current number of records, instead of by splitting whenever an overflow occurs. Buckets that have been split can be recombined if the load of the file falls bellow a certain threshold.

Sample account File Slide 4 Slide 17 Slide 18 Slide 19 Slide 20