CPSC 404, Laks V.S. Lakshmanan1 Hash-Based Indexes Chapter 11 Ramakrishnan & Gehrke (Sections 11.1-11.4)

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.
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.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 11 – Hash-based Indexing.
Access Methods for Advanced Database Applications.
Advanced Data Structures NTUA Spring 2007 B+-trees and External memory Hashing.
Chapter 11 (3 rd Edition) Hash-Based Indexes Xuemin COMP9315: Database Systems Implementation.
Copyright 2003Curt Hill Hash indexes Are they better or worse than a B+Tree?
Hash Indexes: Chap. 11 CS634 Lecture 6, Feb
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.
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%)
B-trees - Hashing. 11.2Database System Concepts Review: B-trees and B+-trees Multilevel, disk-aware, balanced index methods primary or secondary dense.
1 Hash-Based Indexes Yanlei Diao UMass Amherst Feb 22, 2006 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
B+-tree and Hashing.
B+-tree and Hash Indexes
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.
Chapter 10,11 Indexes 11. Hash-based Indexes
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 9.
CPSC 404, Laks V.S. Lakshmanan1 Tree-Structured Indexes BTrees -- ISAM Chapter 10 – Ramakrishnan & Gehrke (Sections )
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 ( 資料庫系統 ) December 6/7, 2006 Lecture #9.
1 Database Systems ( 資料庫系統 ) November 8, 2004 Lecture #9 By Hao-hua Chu ( 朱浩華 )
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Tree- and Hash-Structured Indexes Selected Sections of Chapters 10 & 11.
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.
B+-Trees and Hashing, R. Ramakrishnan and J. Gehrke; extended and significantly revised by Ch. Eick 1 B+-Trees and Hashing Techniques for Storage and Index.
B-Trees, Part 2 Hash-Based Indexes R&G Chapter 10 Lecture 10.
1 Database Systems ( 資料庫系統 ) November 28, 2005 Lecture #9.
Chapter 5 Record Storage and Primary File Organizations
Hash-Based Indexes. Introduction uAs for any index, 3 alternatives for data entries k*: w Data record with key value k w w Choice orthogonal to the indexing.
Database Applications (15-415) DBMS Internals- Part IV Lecture 15, March 13, 2016 Mohammad Hammoud.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
COP Introduction to Database Structures
Hash-Based Indexes Chapter 11
Hashing CENG 351.
Database Management Systems (CS 564)
Introduction to Database Systems
B+-Trees and Static Hashing
External Memory Hashing
Tree- and Hash-Structured Indexes
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
B-Trees, Part 2 Hash-Based Indexes
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 (資料庫系統)
LINEAR HASHING E0 261 Jayant Haritsa Computer Science and Automation
Index tuning Hash Index.
Database Systems (資料庫系統)
Hash-Based Indexes Chapter 11
Chapter 11 Instructor: Xin Zhang
Tree- and Hash-Structured Indexes
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #07 Static Hashing, Extendible Hashing, Linear Hashing Instructor: Chen Li.
Presentation transcript:

CPSC 404, Laks V.S. Lakshmanan1 Hash-Based Indexes Chapter 11 Ramakrishnan & Gehrke (Sections )

CPSC 404, Laks V.S. Lakshmanan2 What you will learn from this set of lectures v Review of static hashing v How to adjust hash structure dynamically against inserts and deletes? –Extendible hashing –Linear hashing. –Relative strengths of B+trees and Hashing: when to use what.

CPSC 404, Laks V.S. Lakshmanan3 Introduction v Hash-based indexes are best for equality selections –no traversal; direct computation of where k* should be –cannot support range searches. v Static and dynamic hashing techniques exist; trade-offs similar to ISAM vs. B+ trees, on a certain level.

CPSC 404, Laks V.S. Lakshmanan4 Static Hashing v # primary pages fixed, allocated sequentially, never de-allocated; overflow pages if needed. v h(k) mod M = bucket to which data entry with key k (i.e., k*) belongs. (M = # of buckets) h(key) mod M h key Primary bucket pages Overflow pages 1 0 M-1

CPSC 404, Laks V.S. Lakshmanan5 Static Hashing (Contd.) v Buckets contain data entries. v Bucket size could be more than 1 block. v Hash fn works on search key field of record r. Must distribute values over range 0... M-1. – h(key) = (key mod M) usually works well for prime M. – lots known about how to tune h. v Long overflow chains can develop and degrade performance (when there are updates). – Extendible and Linear Hashing: two major dynamic techniques to fix this problem.

CPSC 404, Laks V.S. Lakshmanan6 Extendible Hashing v Situation: Bucket (primary page) becomes full. Why not re-organize file by doubling # of buckets? – Reading and writing all pages is expensive! u and is needlessly prodigal on resource use. – Idea: Use directory of pointers to buckets, double # of buckets by doubling the directory †, splitting just the bucket that overflowed! – Directory much smaller than file, so doubling it is much cheaper. Only one page of data entries is split. No overflow page! – Trick lies in how hash function is adjusted! † Not always necessary!

CPSC 404, Laks V.S. Lakshmanan7 Example v Directory is array of size 4. v To find bucket for r, take last `global depth’ # bits of h(r) – e.g., h(r) = 5 = binary 101, it is in bucket pointed to by 01. v hash fn used: h(k) = k (for illustration only). v Insert : If bucket is full, split it ( allocate new page, re-distribute data entries ). E.g., consider insert 20*. v If necessary, double the directory. (As we will see, splitting a bucket does not always require doubling; we can tell by comparing global depth with local depth for the split bucket.) 13* LOCAL DEPTH GLOBAL DEPTH DIRECTORY Bucket A Bucket B Bucket C Bucket D DATA PAGES 10* 1*21* 4*12*32* 16* 15*7*19* 5*

CPSC 404, Laks V.S. Lakshmanan8 Example – Remarks. v Depth – deals with how many bits from the hash address suffix we examine at a given time. v Global depth = what’s the #bits needed to correctly find the home bucket for an arbitrary data entry, in general? v Local depth of bkt B = how many bits did I really need to look at to get to bucket B? v Global depth >= local depth. v Check this on examples. v Is this possible: GD > all LDs?

CPSC 404, Laks V.S. Lakshmanan9 Insert h(r)=20 - Part 1 20* LOCAL DEPTH 2 2 DIRECTORY GLOBAL DEPTH Bucket A Bucket B Bucket C Bucket D Bucket A2 (`split image' of Bucket A) 1* 5*21*13* 32* 16* 10* 15*7*19* 4*12* Suppose h(k) = k for this example. Bucket A split into 2 using an extra bit, i.e., 3 bits A divisible by 8, i.e., 1000 A2 divisible by 4, i.e., 100 note that only one bucket needs to be re-distributed, i.e., re-hashed B, C, D remain unchanged Where to link A2?

CPSC 404, Laks V.S. Lakshmanan10 Insert h(r)=20 – Part 2 19* DIRECTORY Bucket A Bucket B Bucket C Bucket D Bucket A2 (`split image' of Bucket A) 32* 1*5*21*13* 16* 10* 15* 7* 4* 20* 12* LOCAL DEPTH GLOBAL DEPTH double the directory add 1 to global depth & to local depth of A/A2. now can distinguish between A and A2 notice the difference in local depth between buckets multiple pointers to the same bucket Review properties of LD & GD.

CPSC 404, Laks V.S. Lakshmanan11 Points to Note v 20 = binary Last 2 bits (00) tell us r belongs in A or A2. Last 3 bits needed to tell which. – Global depth of directory: min # of bits needed to tell which bucket an entry belongs to = max{local depths}. – Local depth of a bucket: # of bits used to determine if an entry belongs to this bucket. v When does bucket split cause directory doubling? – Before insert, local depth of bucket = global depth. Insert causes local depth to become > global depth; directory is doubled by copying it over and `fixing’ pointer to split image page. (Use of least significant bits enables efficient doubling via copying of directory!) v What happens when 9* is inserted?

CPSC 404, Laks V.S. Lakshmanan12 Comments on Extendible Hashing v If directory fits in memory, equality search answered with one disk access; else two. – 100MB file, 100 bytes/rec, 4K page; contains 1,000,000 records (as data entries); 40 records/page  10 6 /40 = 25,000 pages of data entries; as many directory elements; can handle using 15bit addresses; chances are high that directory will fit in memory. – Directory grows in spurts, and, if the distribution of hash values is skewed, directory can grow large. v Delete: If removal of data entry makes bucket empty, –check to see whether all `split images’ can be merged – if each directory element points to the same bucket as its split image, can halve directory –rarely done in practice (e.g., leave room for future insertions).

CPSC 404, Laks V.S. Lakshmanan13 Linear Hashing v An extension to Extendible Hashing, in spirit. v LH tries to avoid the creation/maintenance of a directory. v Idea: Use a family of hash functions h 0, h 1, h 2,... – N = initial # buckets = 2 d0 – h is some hash function (range is not 0 to N-1) – h i consists of applying h and looking at the last di bits, where di = d0 + i. – h i+1 doubles the range of h i (similar to directory doubling) – e.g., h = binary representation, d0 = 2, d1 = 3, d2 = 4,...

CPSC 404, Laks V.S. Lakshmanan14 Overview of LH File v Note: bucket split need not be bucket where insertion and/or overflow occurred. v Directory avoided in LH by using overflow pages, and choosing bucket to split round-robin. –Next – pointer to current bucket, i.e., next bucket likely to be split. – Splitting proceeds in `rounds’. Round ends when all N R initial (for round R) buckets are split. Buckets 0 to Next-1 have been split; Next to N R -1 yet to be split. – Current round number is Level. – Level and R used interchangeably.

CPSC 404, Laks V.S. Lakshmanan15 Overview of LH File (Contd.) v In the middle of a round. Level h Buckets that existed at the beginning of this round: this is the range of Next Buckets to be split of other buckets) in this round Level hsearch key value) ( )( Buckets split in this round: If is in this range, must use h Level+1 `split image' bucket. to decide if entry is in created (through splitting `split image' buckets: Level = R.

CPSC 404, Laks V.S. Lakshmanan16 Example of Linear Hashing starts with 4 buckets all buckets to be split in a round-robin fashion, starting from the first one 0 h h 1 ( This info is for illustration only!) Level=0, N= (The actual contents of the linear hashed file) Next= 0 PRIMARY PAGES Data entry r with h(r)=5 Primary bucket page 44* 36* 32* 25* 9*5* 14*18* 10* 30* 31*35* 11* 7*

CPSC 404, Laks V.S. Lakshmanan17 Example – Inserting 43* h 0 (43) = 11 => overflow overflow page exists! splitting occurs but to the Next bucket 0 h h 1 Level= Next= 1 PRIMARY PAGES 44* 36* 32* 25* 9*5* 14*18* 10* 30* 31*35* 11* 7* OVERFLOW PAGES 43*

CPSC 404, Laks V.S. Lakshmanan18 Linear Hashing - insertions v Insert: Find bucket by applying h Level / h Level+1 : – If bucket to insert into is full: u Add overflow page and insert data entry. u (Maybe) Split Next bucket and increment Next. v Can choose any criterion to `trigger’ split. v Since buckets are split round-robin, long overflow chains don’t develop!

CPSC 404, Laks V.S. Lakshmanan19 Example: End of a Round (Inserting 37*,29*, 22*,66*,34*,50*) 0 h h 1 22* Next= Level=0 PRIMARY PAGES OVERFLOW PAGES 32* 9* 5* 14* 25* 66* 10* 18* 34* 35*31* 7* 11* 43* 44*36* 37*29* 30* 0 h h 1 37* Next=0 Level= PRIMARY PAGES OVERFLOW PAGES 11 32* 9*25* 66* 18* 10* 34* 35* 11* 44* 36* 5* 29* 43* 14* 30* 22* 31*7* 50* back to deletion

CPSC 404, Laks V.S. Lakshmanan20 Linear Hashing - Searching v Search: To find bucket for data entry r, find h Level (r): u If h Level (r) in range `Next to N R -1’, r belongs here. u Else, r could belong to bucket h Level (r) or bucket h Level (r) + N R ; must apply h Level+1 (r) to find out.

CPSC 404, Laks V.S. Lakshmanan21 LH – Deletion v Inverse of insertion. v If last bkt is empty, remove it and decrement Next. v More generally, can combine last bkt with its split image even if non-empty. Criterion may be based on bkt occupancy level.

CPSC 404, Laks V.S. Lakshmanan22 LH – Deletion (example)(example) 0 h h Next= Level=0 PRIMARY PAGES OVERFLOW PAGES 32* 9* 5* 25* 66* 10* 18* 34* 35*31* 7* 11* 43* 44*36* 37*29* 30* After deleting 14*, 22* Delete 30* 0 h h Next= Level=0 32* 9* 5* 25* 66* 10* 18* 34* 35*31* 7* 11* 43* 44*36* 37*29* 30* Next=2

CPSC 404, Laks V.S. Lakshmanan23 Summary vHvHash-based indexes: best for equality searches. vSvStatic Hashing can lead to long overflow chains. vEvEH avoids overflow pages by splitting a full bucket when a new data entry is to be added to it. –D–Directory to keep track of buckets, doubles periodically. –C–Can get large with skewed data; additional I/O if this does not fit in main memory. vLvLH avoids directory by splitting buckets round-robin, and using overflow pages. –O–Overflow pages not likely to be long.