Selection Queries. to answer a selection query (ssn=10) needs to traverse a full path.

Similar documents
Hash-Based Indexes. Chapter 11. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Hash-Based Indexes. Chapter 11

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

Hashed-Based Indexing

Hash-Based Indexing 1

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Spring

CSIT5300: Advanced Database Systems

Hash-Based Indexes. Chapter 11. Comp 521 Files and Databases Fall

Lecture 8 Index (B+-Tree and Hash)

Systems Infrastructure for Data Science. Web Science Group Uni Freiburg WS 2014/15

Database Applications (15-415)

Kathleen Durant PhD Northeastern University CS Indexes

Database Applications (15-415)

TUTORIAL ON INDEXING PART 2: HASH-BASED INDEXING

Introduction to Data Management. Lecture 15 (More About Indexing)

Material You Need to Know

Database Applications (15-415)

Chapter 6. Hash-Based Indexing. Efficient Support for Equality Search. Architecture and Implementation of Database Systems Summer 2014

Module 3: Hashing Lecture 9: Static and Dynamic Hashing. The Lecture Contains: Static hashing. Hashing. Dynamic hashing. Extendible hashing.

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking

4 Hash-Based Indexing

Introduction to Data Management. Lecture 21 (Indexing, cont.)

Hashing file organization

Chapter 12: Indexing and Hashing (Cnt(

Chapter 11: Indexing and Hashing

Chapter 12: Indexing and Hashing. Basic Concepts

Module 5: Hash-Based Indexing

Chapter 12: Indexing and Hashing

key h(key) Hash Indexing Friday, April 09, 2004 Disadvantages of Sequential File Organization Must use an index and/or binary search to locate data

CS698F Advanced Data Management. Instructor: Medha Atre. Aug 11, 2017 CS698F Adv Data Mgmt 1

Announcements. Reading Material. Recap. Today 9/17/17. Storage (contd. from Lecture 6)

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Chapter 1 Disk Storage, Basic File Structures, and Hashing.

Tree-Structured Indexes

Indexing: Overview & Hashing. CS 377: Database Systems

Chapter 12: Indexing and Hashing

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Intro to DB CHAPTER 12 INDEXING & HASHING

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management

Chapter 11: Indexing and Hashing

Chapter 11: Indexing and Hashing

Physical Disk Structure. Physical Data Organization and Indexing. Pages and Blocks. Access Path. I/O Time to Access a Page. Disks.

CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE DATABASE APPLICATIONS

CS143: Index. Book Chapters: (4 th ) , (5 th ) , , 12.10

Topics to Learn. Important concepts. Tree-based index. Hash-based index

Principles of Data Management. Lecture #5 (Tree-Based Index Structures)

Tree-Structured Indexes

Spring 2017 B-TREES (LOOSELY BASED ON THE COW BOOK: CH. 10) 1/29/17 CS 564: Database Management Systems, Jignesh M. Patel 1

Final Exam Review. Kathleen Durant CS 3200 Northeastern University Lecture 22

Chapter 11: Indexing and Hashing" Chapter 11: Indexing and Hashing"

CSC 261/461 Database Systems Lecture 17. Fall 2017

Data Management for Data Science

Storage hierarchy. Textbook: chapters 11, 12, and 13

Indexing and Hashing

Chapter 13 Disk Storage, Basic File Structures, and Hashing.

The physical database. Contents - physical database design DATABASE DESIGN I - 1DL300. Introduction to Physical Database Design

Tree-Structured Indexes. Chapter 10

Why Is This Important? Overview of Storage and Indexing. Components of a Disk. Data on External Storage. Accessing a Disk Page. Records on a Disk Page

Tree-Structured Indexes

Tree-Structured Indexes. A Note of Caution. Range Searches ISAM. Example ISAM Tree. Introduction

Data and File Structures Chapter 11. Hashing

Data Storage and Query Answering. Indexing and Hashing (5)

Indexing. vanilladb.org

Parallel DBMS. Parallel Database Systems. PDBS vs Distributed DBS. Types of Parallelism. Goals and Metrics Speedup. Types of Parallelism

Tree-Structured Indexes ISAM. Range Searches. Comments on ISAM. Example ISAM Tree. Introduction. As for any index, 3 alternatives for data entries k*:

THE B+ TREE INDEX. CS 564- Spring ACKs: Jignesh Patel, AnHai Doan

Administrivia. Tree-Structured Indexes. Review. Today: B-Tree Indexes. A Note of Caution. Introduction

Tree-Structured Indexes

Chapter 11: Indexing and Hashing

Some Practice Problems on Hardware, File Organization and Indexing

Hashing. Data organization in main memory or disk

2, 3, 5, 7, 11, 17, 19, 23, 29, 31

Overview of Storage and Indexing

Indexing. Week 14, Spring Edited by M. Naci Akkøk, , Contains slides from 8-9. April 2002 by Hector Garcia-Molina, Vera Goebel

Access Methods. Basic Concepts. Index Evaluation Metrics. search key pointer. record. value. Value

Tree-Structured Indexes

COMP 430 Intro. to Database Systems. Indexing

CS 525: Advanced Database Organization 04: Indexing

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far

HW 2 Bench Table. Hash Indexes: Chap. 11. Table Bench is in tablespace setq. Loading table bench. Then a bulk load

Advanced Database Systems

Find the block in which the tuple should be! If there is free space, insert it! Otherwise, must create overflow pages!

Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Tree-Structured Indexes

Chapter 12: Query Processing. Chapter 12: Query Processing

Physical Level of Databases: B+-Trees

Advances in Data Management Principles of Database Systems - 2 A.Poulovassilis

Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University

Indexing. Chapter 8, 10, 11. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

(2,4) Trees Goodrich, Tamassia. (2,4) Trees 1

More B-trees, Hash Tables, etc. CS157B Chris Pollett Feb 21, 2005.

! Parallel machines are becoming quite common and affordable. ! Databases are growing increasingly large

Chapter 20: Parallel Databases

Chapter 20: Parallel Databases. Introduction

Midterm Review CS634. Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke

Data Organization B trees

LH*Algorithm: Scalable Distributed Data Structure (SDDS) and its implementation on Switched Multicomputers

CS 245: Database System Principles

Lecture 13. Lecture 13: B+ Tree

Chapter 18: Parallel Databases

Transcription:

Hashing

B+-tree is perfect, but... Selection Queries to answer a selection query (ssn=) needs to traverse a full path. In practice, 3-4 block accesses (depending on the height of the tree, buffering) Any better approach? Yes! Hashing static hashing dynamic hashing.

Hashing Hash-based indexes are best for equality selections. Cannot support range searches. Static and dynamic hashing techniques exist; trade-offs similar to ISAM vs. B+ trees..3

Static Hashing # primary bucket pages is fixed, allocated sequentially, never deallocated; overflow pages if needed. h(k) MOD N= bucket to which data entry with key k belongs. (N = # of buckets) h(key) mod N key h 0 1 N-1 Primary bucket pages Overflow pages.4

Buckets contain data entries. Static Hashing (Cont.) Hash fn works on search key field of record r. Use its value MOD N to distribute values over range 0... N-1. h(key) = (a * key + b) usually works well. a and b are constants; lots known about how to tune h. Long overflow chains can develop and thus degrade performance. Extendible Hashing and Linear Hashing Dynamic techniques to fix this problem..5

Extendible Hashing Suppose a bucket (primary page) becomes full. Why not re-organize file by doubling # of buckets? Reading and writing all pages is expensive! 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!.6

Directory is array of size 4. Example Bucket for record r has entry with index = `global depth of = least significant bits of h(r); If h(r) = 5 = binary 1, it is in bucket pointed to by 01. If h(r) = 7 = binary 1, it is in bucket pointed to by. GLOBAL DEPTH LOCAL DEPTH 4* 1* 3* 16* Bucket A 1 1* 5* 7* 13* Bucket B 01 * Bucket C DIRECTORY * we denote r by h(r)..7

Find bucket where record belongs. If there s room, put it there. else, if bucket is full, split it: Handling Inserts 1. increment local depth of original page. allocate new page with new local depth 3. re-distribute records from original page. 4. add entry for the new page to the directory.8

Example: Insert 1, then 19, 15 1 = 1 19 = 1 15 = 0 GLOBAL DEPTH LOCAL DEPTH 01 4* 1* 3* 16* 1 1* 5* 1* 7* * 13* Bucket A Bucket B Bucket C DIRECTORY 7* 19* 15* Bucket D DATA PAGES.9

Insert h(r)=0 (Causes Doubling) 0 = 1 LOCAL DEPTH GLOBAL DEPTH 3 4* 1* 3*16* 3*16* Bucket A LOCAL DEPTH GLOBAL DEPTH 3 3* 16* 01 1* 5* 1*13* * Bucket B Bucket C 0 1 0 0 3 1* 5* 1* 13* * Bucket B Bucket C 15* 7* 19* Bucket D 1 1 1 15* 7* 19* Bucket D 3 4* 1* 0* Bucket A (`split image' of Bucket A) 1 3 4* 1* 0* Bucket A (`split image' of Bucket A).

Points to Note 0 = binary 1. Last bits () tell us r belongs in either A or A. Last 3 bits needed to tell which. Global depth of directory: Max # of bits needed to tell which bucket an entry belongs to. Local depth of a bucket: # of bits used to determine if an entry belongs to this bucket. 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..

Directory Doubling Why use least significant bits in directory? Allows for doubling via copying! 6 = 1 0 3 6 = 1 0 3 0 1 1 6* 01 6* 1 0 0 1 1 1 6* 0 1 1 6* 01 6* 1 0 1 1 1 0 6* 1 1 Least Significant vs. Most Significant.1

Comments on Extendible Hashing If directory fits in memory, equality search answered with one disk access; else two. 1MB file, 1 bytes/rec, 4K pages contains 1,0,0 records (as data entries) and 5,0 directory elements; 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. Multiple entries with same hash value cause problems! Delete: If removal of data entry makes bucket empty, can be merged with `split image. If each directory element points to same bucket as its split image, can halve directory..13

Linear Hashing A dynamic hashing scheme that handles the problem of long overflow chains without using a directory. Directory avoided in LH by using temporary overflow pages, and choosing the bucket to split in a round-robin fashion. When any bucket overflows split the bucket that is currently pointed to by the Next pointer and then increment that pointer to the next bucket..14

Linear Hashing The Main Idea Use a family of hash functions h 0, h 1, h,... h i (key) = h(key) mod( i N) N = initial # buckets h is some hash function h i+1 doubles the range of h i (similar to directory doubling).15

Linear Hashing (Contd.) Algorithm proceeds in `rounds. Current round number is called Level. There are N Level a round Next points to the current bucket. (= N * Level ) buckets at the beginning of Buckets 0 to Next-1 have been split; Next to N Level have not been split yet this round. Round ends when all initial buckets have been split (i.e. Next = N Level ). To start next round: Level++; Next = 0;.16

LH Search Algorithm To find bucket for data entry r, find h Level (r): If h Level (r) Next (i.e., h Level (r) is a bucket that hasn t been involved in a split this round) then r belongs in that bucket for sure. Else, r could belong to bucket h Level (r) or bucket h Level (r) + N Level must apply h Level+1 (r) to find out. i.e., look in two places.17

Example: Search 44 (1), 9 (0) Level=0, Next=0, N=4 h 1 0 h 0 3*44* 36* Next 1 01 9* 5* 5* 0 14* 18** 30* 0 31* 35* 7* * (This info is for illustration only!) PRIMARY PAGES.18

Linear Hashing - Insert Find appropriate bucket using h LEVEL (or h LEVEL+1 ) If bucket to insert into is full: Add overflow page and insert data entry. Split Next bucket and increment Next. Note: This is likely NOT the bucket being inserted into!!! to split a bucket, create a new bucket and use h Level+1 to redistribute entries. Since buckets are split round-robin, long overflow chains don t develop!.19

h 1 h 0 Example: Insert 43 () Level=0, N=4 Next=0 0 1 01 3*44* 36* 9* 5* 5* Level=0 Next=1 0 14* 18** 30* h 1 h 0 PRIMARY PAGES OVERFLOW PAGES 0 31* 35* 7* * 0 3* (This info is for illustration only!) PRIMARY PAGES (This info is for illustration only!) 1 0 0 1 01 9* 5* 5* 14*18**30* 44* 36* Next 31*35* 7* * 43*.0

Level=0, Next = 3 h 1 0 1 0 0 1 h0 01 PRIMARY PAGES Example: End of a Round Insert 50 () 3* 9* 5* 66* 18* * 34* Next=3 31* 35* 7* * 43* 44*36* OVERFLOW PAGES h 1 0 1 0 0 1 1 h0 01 Level=1, Next = 0 Next=0 PRIMARY PAGES 3* 9* 5* 66* 18* * 34* 43* 44* 36* 35* * 5* 37* 9* OVERFLOW PAGES 50* 1 01 5* 37*9* 1 14* 30* * 1 14* 30* * 1 31*7*.1

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. (Duplicates may require overflow pages.) 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..3

Summary (Contd.) Linear Hashing avoids directory by splitting buckets round-robin, and using overflow pages. Overflow page chains are not likely to be long. Space utilization could be lower than Extendible Hashing, since splits are not concentrated on `dense data areas. Can tune criterion for triggering splits to trade-off slightly longer chains for better space utilization. For hash-based indexes, a skewed data distribution is one in which the hash values of data entries are not uniformly distributed!.4