FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.

Slides:



Advertisements
Similar presentations
External Memory Hashing. Model of Computation Data stored on disk(s) Minimum transfer unit: a page = b bytes or B records (or block) N records -> N/B.
Advertisements

CS4432: Database Systems II Hash Indexing 1. Hash-Based Indexes Adaptation of main memory hash tables Support equality searches No range searches 2.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part C Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Hash-Based Indexes Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
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.
Hashing. CENG 3512 Motivation The primary goal is to locate the desired record in a single access of disk. – Sequential search: O(N) – B+ trees: O(log.
Hash-Based Indexes The slides for this text are organized into chapters. This lecture covers Chapter 10. Chapter 1: Introduction to Database Systems Chapter.
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.
CPSC 404, Laks V.S. Lakshmanan1 Hash-Based Indexes Chapter 11 Ramakrishnan & Gehrke (Sections )
Chapter 11 Indexing and Hashing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 11 – Hash-based 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.
File Processing - Indirect Address Translation MVNC1 Hashing Indirect Address Translation Chapter 11.
What we learn with pleasure we never forget. Alfred Mercier Smitha N Pai.
Index tuning Hash Index. overview Introduction Hash-based indexes are best for equality selections. –Can efficiently support index nested joins –Cannot.
ICS 421 Spring 2010 Indexing (2) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 2/23/20101Lipyeow Lim.
1 Hash-Based Indexes Yanlei Diao UMass Amherst Feb 22, 2006 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
B+-tree and Hashing.
1 Hash-Based Indexes Chapter Introduction  Hash-based indexes are best for equality selections. Cannot support range searches.  Static and dynamic.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Disk Storage, Basic File Structures, and Hashing by Pinar Senkul resources: mostly froom.
1 Hash-Based Indexes Chapter Introduction : Hash-based Indexes  Best for equality selections.  Cannot support range searches.  Static and dynamic.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
Hashing General idea: Get a large array
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
Chapter 11 Indexing & Hashing. 2 n Sophisticated database access methods n Basic concerns: access/insertion/deletion time, space overhead n Indexing 
Hashing and Hash-Based Index. Selection Queries Yes! Hashing  static hashing  dynamic hashing B+-tree is perfect, but.... to answer a selection query.
1 Database Systems ( 資料庫系統 ) November 8, 2004 Lecture #9 By Hao-hua Chu ( 朱浩華 )
FALL 2005 CENG 351 Data Management and File Structures 1 Hashing.
March 23 & 28, Csci 2111: Data and File Structures Week 10, Lectures 1 & 2 Hashing.
March 23 & 28, Hashing. 2 What is Hashing? A Hash function is a function h(K) which transforms a key K into an address. Hashing is like indexing.
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
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.
Static Hashing (using overflow for collision managment e.g., h(key) mod M h key Primary bucket pages 1 0 M-1 Overflow pages(as separate link list) Overflow.
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.
Copyright © Curt Hill Hashing A quick lookup strategy.
1 Database Systems ( 資料庫系統 ) November 28, 2005 Lecture #9.
Chapter 5 Record Storage and Primary File Organizations
CENG Hashing for files. CENG 3512 Introduction Idea: to reference items in a table directly by doing arithmetic operations to transform keys into.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
Data Structures Using C++ 2E
Dynamic Hashing (Chapter 12)
Hash-Based Indexes Chapter 11
Hashing CENG 351.
Subject Name: File Structures
Database Management Systems (CS 564)
Data Structures Using C++ 2E
Introduction to Database Systems
CS222: Principles of Data Management Notes #8 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Hash-Based Indexes R&G Chapter 10 Lecture 18
Hash-Based Indexes Chapter 10
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.
Database Systems (資料庫系統)
Hash-Based Indexes Chapter 11
Chapter 11 Instructor: Xin Zhang
What we learn with pleasure we never forget. Alfred Mercier
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #07 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Presentation transcript:

FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12

FALL 2004CENG 3512 Motivation The primary goal is to locate the desired record in a single access of disk. –Sequential search: O(N) –B+ trees: O(log k N) –Hashing: O(1) In hashing, the key of a record is transformed into an address and the record is stored at that address. Hash-based indexes are best for equality selections. Cannot support range searches. Static and dynamic hashing techniques exist.

FALL 2004CENG 3513 Hash-based Index Data entries are kept in buckets (an abstract term) Each bucket is a collection of one primary page and zero or more overflow pages. Given a search key value, k, we can find the bucket where the data entry k* is stored as follows: –Use a hash function, denoted by h –The value of h(k) is the address for the desired bucket. h(k) should distribute the search key values uniformly over the collection of buckets

FALL 2004CENG 3514 Design Factors Bucket size: the number of records that can be held at the same address. Loading factor: the ratio of the number of records put in the file to the total capacity of the buckets. Hash function: should evenly distribute the keys among the addresses. Overflow resolution technique.

FALL 2004CENG 3515 Hash Functions Key mod N: –N is the size of the table, better if it is prime. Folding: –e.g. 123|456|789: add them and take mod. Truncation: –e.g map to a table of 1000 addresses by picking 3 digits of the key. Squaring: –Square the key and then truncate Radix conversion: –e.g treat it to be base 11, truncate if necessary.

FALL 2004CENG 3516 Static Hashing Primary Area: # primary pages fixed, allocated sequentially, never de-allocated; (say M buckets). –A simple hash function: h(k) = f(k) mod M Overflow area: disjoint from the primary area. It keeps buckets which hold records whose key maps to a full bucket. –Adding the address of an overflow bucket to a primary area bucket is called chaining. Collision does not cause a problem as long as there is still room in the mapped bucket. Overflow occurs during insertion when a record is hashed to the bucket that is already full.

FALL 2004CENG 3517 Example Assume f(k) = k. Let M = 5. So, h(k) = k mod 5 Bucket factor = 3 records Primary areaoverflow

FALL 2004CENG 3518 Load Factor (Packing density) To limit the amount of overflow we allocate more space to the primary area than we need (i.e. the primary area will be, say, 70% full) Load Factor = => Lf = # of records in the file # of spaces in primary area n M * Bkfr

FALL 2004CENG 3519 Effects of Lf and Bkfr Performance can be enhanced by the choice of bucket size and load factor. In general, a smaller load factor means –less overflow and a faster fetch time; –but more wasted space. A larger Bkfr means –less overflow in general, –but slower fetch.

FALL 2004CENG Insertion and Deletion Insertion: New records are inserted at the end of the chain. Deletion: Two ways are possible: 1.Mark the record to be deleted 2.Consolidate sparse buckets when deleting records. –In the 2 nd approach: When a record is deleted, fill its place with the last record in the chain of the current bucket. Deallocate the last bucket when it becomes empty.

FALL 2004CENG Problem of Static Hashing The main problem with static hashing: the number of buckets is fixed: –Long overflow chains can develop and degrade performance. –On the other hand, if a file shrinks greatly, a lot of bucket space will be wasted. There are some other hashing techniques that allow dynamically growing and shrinking hash index. These include: –linear hashing –extendible hashing

FALL 2004CENG Linear Hashing It maintains a constant load factor. Thus avoids reorganization. It does so, by incrementally adding new buckets to the primary area. In linear hashing the last bits in the hash number are used for placing the records.

FALL 2004CENG Example Last 3 bits e.g. 34: : : : Insert: 13, 21, 37 Lf = 15/24 = 63%

FALL 2004CENG Insertion of records To expand the table: split an existing bucket denoted by k digits into two buckets using the last k+1 digits. e.g

FALL 2004CENG Expanding the table Boundary value

FALL 2004CENG Boundary value 37 k = 3 Hash # 1000: uses last 4 digits Hash # 1101: uses last 3 digits

FALL 2004CENG Fetching a record Calculate the hash function. Look at the last k digits. –If it’s less than the boundary value, the location is in the bucket labeled with the last k+1 digits. –Otherwise it is in the bucket labeled with the last k digits. Follow overflow chains as with static hashing.

FALL 2004CENG Insertion Search for the correct bucket into which to place the new record. If the bucket is full, allocate a new overflow bucket. If there are now Lf*Bkfr records more than needed for the given Lf, –Add one more bucket to the primary area. –Distribute the records from the bucket chain at the boundary value between the original area and the new primary area buckets –Add 1 to the boundary value.

FALL 2004CENG Deletion Read in a chain of records. Replace the deleted record with the last record in the chain. –If the last overflow bucket becomes empty, deallocate it. When the number of records is Lf * Bkfr less than the number needed for Lf, contract the primary area by one bucket. Compressing the table is exact opposite of expanding it: Keep the total # of records in the file and buckets in primary area. When we have Lf * Bkfr fewer records than needed, consolidate the last bucket with the bucket which shares the same last k digits.

FALL 2004CENG Extendible Hashing Hash function returns b bits Only the prefix i bits are used to hash the item There are 2 i entries in the bucket address table Let i j be the length of the common hash prefix for data bucket j, there is 2 (i-i j ) entries in bucket address table points to j Extendable Hashing i i2 bucket2 i3 bucket3 i1 bucket1 Data bucket Bucket address table Length of common hash prefixHash prefix

FALL 2004CENG Splitting a bucket: Case 1 Splitting (Case 1: i j =i) –Only one entry in bucket address table points to data bucket j –i++; split data bucket j to j, z; i j =i z =i; rehash all items previously in j; Extendable Hashing

FALL 2004CENG Splitting: Case 2 Splitting (Case 2: i j < i) –More than one entry in bucket address table point to data bucket j –split data bucket j to j, z; i j = i z = i j +1; Adjust the pointers previously point to j to j and z; rehash all items previously in j; Extendable Hashing

FALL 2004CENG Example Suppose the hash function is h(x) = x mod 8 and each bucket can hold at most two records. Show the extendable hash structure after inserting 1, 4, 5, 7, 8, 2, 20. Extendable Hashing

FALL 2004CENG Example inserting 1, 4, 5, 7, 8, 2, Extendable Hashing

FALL 2004CENG Comments on Extendible Hashing If directory fits in memory, equality search answered with one disk access. – A typical example: a100MB file with 100 bytes/entry and a page size of 4K contains 1,000,000 records (as data entries) but only about 25,000 directory elements  chances are high that directory will fit in memory. If the distribution of hash values is skewed (e.g., a large number of search key values all are hashed to the same bucket ), directory can grow large. –But this kind of skew can be avoided with a well-tuned hashing function

FALL 2004CENG Comments on Extendible Hashing Delete: If removal of data entry makes bucket empty, can be merged with a “ buddy ” bucket. If each directory element points to same bucket as its split image, can halve directory.

FALL 2004CENG Summary Hash-based indexes: best for equality searches, cannot support range searches. Static Hashing can lead to long overflow chains. Extendible Hashing avoids overflow pages by splitting a full bucket when a new data entry is to be added to it. – Directory to keep track of buckets, doubles periodically. – Can get large with skewed data; additional I/O if this does not fit in main memory.