Hash-Based Indexes. Chapter 11

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

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

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

Hash-Based Indexing 1

Hashed-Based Indexing

Lecture 8 Index (B+-Tree and Hash)

CSIT5300: Advanced Database Systems

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

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

Kathleen Durant PhD Northeastern University CS Indexes

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

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

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

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

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

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

Database Applications (15-415)

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

Hashing file organization

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

TUTORIAL ON INDEXING PART 2: HASH-BASED INDEXING

Database Applications (15-415)

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

4 Hash-Based Indexing

5. Hashing. 5.1 General Idea. 5.2 Hash Function. 5.3 Separate Chaining. 5.4 Open Addressing. 5.5 Rehashing. 5.6 Extendible Hashing. 5.

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

CARNEGIE MELLON UNIVERSITY DEPT. OF COMPUTER SCIENCE DATABASE APPLICATIONS

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

Database Applications (15-415)

Hashing. Data organization in main memory or disk

Indexing: Overview & Hashing. CS 377: Database Systems

Chapter 12: Indexing and Hashing (Cnt(

Material You Need to Know

Module 5: Hash-Based Indexing

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

Data and File Structures Chapter 11. Hashing

Tree-Structured Indexes. Chapter 10

Tree-Structured Indexes

Fundamentals of Database Systems Prof. Arnab Bhattacharya Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Module 5: Hashing. CS Data Structures and Data Management. Reza Dorrigiv, Daniel Roche. School of Computer Science, University of Waterloo

Chapter 12: Indexing and Hashing. Basic Concepts

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

Tree-Structured Indexes

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

Hashing Techniques. Material based on slides by George Bebis

Chapter 12: Indexing and Hashing

Intro to DB CHAPTER 12 INDEXING & HASHING

Introduction. Choice orthogonal to indexing technique used to locate entries K.

Indexing. vanilladb.org

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

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

COMP 430 Intro. to Database Systems. Indexing

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

Chapter 11: Indexing and Hashing

SUMMARY OF DATABASE STORAGE AND QUERYING

else // m + 1 = d + }{{} 1 + d

CSC 261/461 Database Systems Lecture 17. Fall 2017

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

Introduction to Hashing

Tree-Structured Indexes

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

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

Tree-Structured Indexes

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

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

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

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

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

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

Hashing. 1. Introduction. 2. Direct-address tables. CmSc 250 Introduction to Algorithms

BBM371& Data*Management. Lecture 6: Hash Tables

Open Addressing: Linear Probing (cont.)

Hashing IV and Course Overview

Chapter 12: Indexing and Hashing

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

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

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

Indexing. Announcements. Basics. CPS 116 Introduction to Database Systems

CS122 Lecture 3 Winter Term,

Tree-Structured Indexes

Some Practice Problems on Hardware, File Organization and Indexing

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

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

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

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

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

Tree-Structured Indexes

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

Chapter 11: Indexing and Hashing

! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function.

Chapter 11: Indexing and Hashing

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

Comp 335 File Structures. Hashing

File Organization and Storage Structures

Hashing. Hashing Procedures

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

Understand how to deal with collisions

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

Algorithms and Data Structures

20-EECE-4029 Operating Systems Spring, 2013 John Franco

Transcription:

Hash-Based Indexes Chapter 11 1

Introduction : Hash-based Indexes Best for equality selections. Cannot support range searches. Static and dynamic hashing techniques exist: Trade-offs similar to ISAM vs. B+ trees.

Static Hashing h(k) mod N = bucket to which data entry with key k belongs. (N = # of buckets) h(key) mod N key h 0 N-1 Primary bucket pages Overflow pages 3

Static Hashing : h(k) mod N # primary pages fixed (N = # of buckets) allocated sequentially never de-allocated overflow pages if needed. h(key) mod N key h 0 N-1 Primary bucket pages Overflow pages 4

Static Hashing h(k) mod N = bucket to which data entry with key k belongs with N = # of buckets Hash function works on search key of record r. h() must distribute values over range [0... N-1]. For example, h(key) = (a * key + b) a and b are constants lots known about how to tune h. 5

Static Hashing Cons Primary pages fixed space static structure. Fixed # buckets is the problem: Rehashing can be done Not good for search. In practice, instead use overflow chains. Long overflow chains degrade performance. Solution: Employ dynamic techniques : Extendible hashing, or Linear Hashing 6

Extendible Hashing Problem: Bucket (primary page) becomes full. Solution: Re-organize file by doubling # of buckets? But Reading and writing all pages is expensive! 8

Extendible Hashing Ideas : Use directory of pointers to buckets instead of buckets Details : Double # of buckets by doubling the directory Split just the bucket that overflowed! Trick : How hash function is adjusted! 9

Example Directory : array[4] LOCAL DEPTH GLOBAL DEPTH 4* 1* 3* 16* Bucket A To find bucket for r, take last `global depth # bits of function h(r) 00 1* 5* 1* 13* Bucket B 01 10 11 10* Bucket C DIRECTORY 15* 7* 19* Bucket D DATA PAGES 10

Example LOCAL DEPTH GLOBAL DEPTH 4* 1* 3* 16* Bucket A If h(r) = 5 = 101, it is in bucket pointed to by 01. 00 01 1* 5* 1* 13* Bucket B If h(r) = 4 = 100, 10 11 10* Bucket C it is in bucket pointed to by 00. DIRECTORY 15* 7* 19* Bucket D DATA PAGES 11

Insertion LOCAL DEPTH GLOBAL DEPTH 4* 1* 3* 16* Bucket A Insert: If bucket is full, split it (allocate new page, re-distribute content). 00 01 10 11 1* 5* 1* 10* 13* Bucket B Bucket C DIRECTORY 15* 7* 19* Bucket D Splitting may : double the directory, or simply link in a new page. DATA PAGES To tell what to do : Compare global depth with local depth for split bucket. 1

Insert h(r)= 6 = binary 110 LOCAL DEPTH GLOBAL DEPTH Bucket A 4* 1* 3* 16* Bucket B 00 1* 5* 1* 13* 01 10 11 10* Bucket C DIRECTORY 15* 7* 19* Bucket D DATA PAGES 13

Insert h(r)= 6 = binary 110 LOCAL DEPTH Bucket A LOCAL DEPTH Bucket A GLOBAL DEPTH 4* 1* 3* 16* GLOBAL DEPTH 4* 1* 3* 16* Bucket B Bucket B 00 1* 5* 1* 13* 00 1* 5* 1* 13* 01 01 10 11 10* Bucket C 10 11 Bucket C 10* 6* DIRECTORY 15* 7* 19* Bucket D DIRECTORY 15* 7* 19* Bucket D DATA PAGES DATA PAGES 14

Insert h(r)=0 = binary 10100 LOCAL DEPTH GLOBAL DEPTH Bucket A 4* 1* 3* 16* Bucket B 00 1* 5* 1* 13* 01 10 11 10* Bucket C DIRECTORY 15* 7* 19* Bucket D DATA PAGES 15

Insert h(r)=0 LOCAL DEPTH GLOBAL DEPTH Bucket A 4* 1* 3* 16* Split Bucket A into two buckets A1 and A Bucket B 00 01 10 1* 5* 1* 13* Bucket C 3 4* 1* 0* Bucket A 11 10* 3 DIRECTORY Bucket D 15* 7* 19* 16* 3* Bucket A1 DATA PAGES 16

Insert h(r)=0 3 LOCAL DEPTH Bucket A 4* 1* 0* Bucket A GLOBAL DEPTH 4* 1* 3* 16* 3 Bucket B 3* 16* Bucket A1 00 1* 5* 1* 13* 01 10 11 10* Bucket C DIRECTORY 15* 7* 19* Bucket D DATA PAGES 17

Insert h(r)=0 LOCAL DEPTH GLOBAL DEPTH 3*16* Bucket A LOCAL DEPTH GLOBAL DEPTH 3 3* 16* Bucket A 00 01 10 11 1* 5* 1*13* 10* Bucket B Bucket C 000 001 010 011 3 1* 5* 1* 13* 10* Bucket B Bucket C DIRECTORY 15* 7* 19* Bucket D 100 101 110 15* 7* 19* Bucket D 4* 1* 0* Bucket A (`split image' of Bucket A) 111 DIRECTORY 3 4* 1* 0* Bucket A (`split image' of Bucket A) 18

Points to Note 0 = binary 10100. Last bits (00) tell us if r belongs in A Last 3 bits needed to tell if r belongs into A1 or A 19

Bits: More Points to Note Global depth of directory: Max # of bits needed to tell which bucket an entry belongs to Local depth of a bucket: Actual # 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 the one over-full page. 0

Extendible Hashing : Delete 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.

Comments on Extendible Hashing If directory fits in memory, then equality search answered with one disk access; else with two. 100MB file, 100 bytes/rec, 4K pages contain 1,000,000 records (as data entries) and 5,000 directory elements; chances are high that directory will fit in memory. Directory grows in spurts. If the distribution of hash values is skewed, directory can grow large. 3

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 full bucket when new data to be added Directory to keep track of buckets, doubles periodically 4