Chapter 11 Indexing and Hashing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park.

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.
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.
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.
File Processing : Hash 2015, Spring Pusan National University Ki-Joune Li.
Chapter 12: Indexing and Hashing Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files B-Tree Index Files Static.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 11: Indexing.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
CIS552Indexing and Hashing1 Cost estimation Basic Concepts Ordered Indices B + - Tree Index Files B - Tree Index Files Static Hashing Dynamic Hashing Comparison.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
©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 Chapter 12: Indexing and.
CST203-2 Database Management Systems Lecture 7. Disadvantages on index structure: We must access an index structure to locate data, or must use binary.
INDEXING AND HASHING.
Dr. Kalpakis CMSC 661, Principles of Database Systems Index Structures [13]
BTrees & Bitmap Indexes
1 Indexing and Hashing Indexing and Hashing Basic Concepts Dense and Sparse Indices B+Trees, B-trees Dynamic Hashing Comparison of Ordered Indexing and.
Data Indexing Herbert A. Evans. Purposes of Data Indexing What is Data Indexing? Why is it important?
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part A Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
Quick Review of Apr 15 material Overflow –definition, why it happens –solutions: chaining, double hashing Hash file performance –loading factor –search.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Indexing and Hashing.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
Ch12: Indexing and Hashing  Basic Concepts  Ordered Indices B+-Tree Index Files B+-Tree Index Files B-Tree Index Files B-Tree Index Files  Hashing Static.
Indexing and Hashing.
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.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Indexing and.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
Chapter 12: Indexing and Hashing
1 Chapter 12: Indexing and Hashing Indexing Indexing Basic Concepts Basic Concepts Ordered Indices Ordered Indices B+-Tree Index Files B+-Tree Index Files.
Chapter 11 Indexing & Hashing. 2 n Sophisticated database access methods n Basic concerns: access/insertion/deletion time, space overhead n Indexing 
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B+-Tree Index Files B-Tree.
12.1 Chapter 12: Indexing and Hashing Spring 2009 Sections , , Problems , 12.7, 12.8, 12.13, 12.15,
Basic Concepts Indexing mechanisms used to speed up access to desired data. E.g., author catalog in library Search Key - attribute to set of attributes.
Indexing and hashing Azita Keshmiri CS 157B. Basic concept An index for a file in a database system works the same way as the index in text book. For.
Computing & Information Sciences Kansas State University Wednesday, 22 Oct 2008CIS 560: Database System Concepts Lecture 22 of 42 Wednesday, 22 October.
Indexing and Hashing By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 12: Indexing and Hashing.
Indexing Database Management Systems. Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files File Organization 2.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module D: Hashing.
Computing & Information Sciences Kansas State University Monday, 31 Mar 2008CIS 560: Database System Concepts Lecture 25 of 42 Monday, 31 March 2008 William.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Indexing and.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 11: Indexing.
Chapter 5 Record Storage and Primary File Organizations
Chapter 11 Indexing And Hashing (1) Yonsei University 1 st Semester, 2016 Sanghyun Park.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Indexing and Hashing.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Hash 2004, Spring Pusan National University Ki-Joune Li.
Dynamic Hashing (Chapter 12)
Hashing CENG 351.
Chapter 11: Indexing and Hashing
Database Management Systems (CS 564)
Module 12: Indexing.
Dynamic Hashing.
Hashing Chapter 11.
Extendible Indexing Dina Said
Chapter 11: Indexing and Hashing
Indexing and Hashing Basic Concepts Ordered Indices
Indexing and Hashing B.Ramamurthy Chapter 11 2/5/2019 B.Ramamurthy.
Chapter 11 Indexing And Hashing (1)
Database Design and Programming
2018, Spring Pusan National University Ki-Joune Li
Module 12a: Dynamic Hashing
Chapter 11: Indexing and Hashing
Chapter 11: Indexing and Hashing
Presentation transcript:

Chapter 11 Indexing and Hashing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park

Outline  Basic Concepts(already covered)  Ordered Indices(already covered)  B + -Tree Index Files(already covered)  B-Tree Index Files(already covered)  Static Hashing  Dynamic Hashing  Comparison of Ordered Indexing and Hashing  Multiple-Key Access  Bitmap Index

Static Hashing  A bucket is a unit of storage containing one or more records (a bucket is typically a disk block)  In a hash file organization, we obtain the bucket of a record directly from its search-key value using a hash function  Records with different search-key values may be mapped to the same bucket; thus entire bucket has to be searched sequentially to locate a record

Hash Organization of instructor File, with dept_name as Key

Handling of Bucket Overflows

Hash Indices  Hashing can be used not only for file organization, but also for index-structure creation  A hash index organizes the search keys, with their associated record pointers, into a hash file structure

Example of Hash Index hash index on instructor, on attribute ID

Deficiencies of Static Hashing  In static hashing, hash function maps search-key values to a fixed set of bucket addresses  Databases grow with time. If initial number of buckets is too small, performance will degrade due to too many overflows  If file size 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 index 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 bucket address table  Let the length of the prefix be i bits, 0 ≤ i ≤ 32  Bucket address table size = 2 i. Initially i = 0  Value of i grows or shrinks as the size of the database changes  Multiple entries in the bucket address table may point to a same bucket  Thus, actual number of buckets is ≤ 2 i ; the number of buckets also changes dynamically due to coalescing and splitting of buckets

Extendable Hash Structure In this structure, i 2 = i 3 = i, whereas i 1 = i – 1

Use of Extendable Hash Structure  Each bucket j stores a value i j ; all the entries that point to the same bucket have the same hash values on the first i j bits  To locate the bucket containing search-key k  Compute h(k) = X  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 k  Follow the 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 (1/2) To split a bucket j when inserting record with search-key value k  If i > i j (more than one pointer to bucket j)  Allocate a new bucket z and set i j and i z to the old i j + 1  Make the second half of the bucket address table entries pointing to j point to z  Remove and reinsert each record in bucket j  Recompute new bucket for k and insert record in the bucket (further splitting is required if the bucket is still full)  If i = i j (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 k; Now i > i j so use the first case above

Updates in Extendable Hash Structure (2/2)  When inserting a value, if the bucket is full after several splits (that is, i reaches some limit b), create an overflow bucket  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 i j and same i j -1 prefix)  Decreasing bucket address table size is also possible

Use of Extendable Hash Structure: Example (1/7) Initial hash structure, bucket size = 2

Use of Extendable Hash Structure: Example (2/7)  Hash structure after insertion of “Mozart” (Music), “Srinivasan” (Comp. Sci.), and “Wu” (Finance) records

Use of Extendable Hash Structure: Example (3/7)  Hash structure after insertion of “Einstein” (Physics) record

Use of Extendable Hash Structure: Example (4/7)  Hash structure after insertion of “Gold” (Physics) and “El Said” (History) records

Use of Extendable Hash Structure: Example (5/7)  Hash structure after insertion of “Katz” (Comp. Sci.) record

Use of Extendable Hash Structure: Example (6/7) And after insertion of eleven records

Use of Extendable Hash Structure: Example (7/7) And after insertion of “Kim” (Elec. Eng.) record in previous hash structure

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)  Changing size of bucket address table is an expensive operation

Ordered Indexing vs. Hashing  Hashing is generally better at retrieving records having a specified value of the key SELECTA 1, A 2, …, A n FROMr WHEREA i = c  If range queries are common, ordered indices are to be preferred SELECTA 1, A 2, …, A n FROMr WHEREA i ≤ c 2 and A i ≥ c 1

Multiple-Key Access  Use multiple indices for certain types of queries SELECTID FROMinstructor WHEREdept_name = “Finance” and salary =  Possible strategies using indices on single attributes: 1. Use index on dept_name to find all instructors in the Finance department; test salary = Use index on salary to find all instructors with salary of $80000; test dept_name = “Finance” 3.Use dept_name index to find pointers to all records pertaining to the Finance department. Similarly use index on salary. Take intersection of both sets of pointers obtained

Indices on Multiple Attributes Suppose we have an index on combined search-key (dept_name, salary)  The index on the combined search-key will fetch only records that satisfy both conditions  Using separate indices is less efficient — we may fetch many records (or pointers) that satisfy only one of the conditions  Can also efficiently handle where dept_name = “Finance” and salary <  But cannot efficiently handle where dept_name < “Finance” and salary = Each record is likely to be in a different disk block, because of the ordering of records in the file, leading to many I/O operations

Bitmap Indices  Bitmap indices are a special type of index designed for efficient querying on multiple keys  Records in a relation are assumed to be numbered sequentially  Given a number n it must be easy to retrieve record n (Particularly easy if records are of fixed size)  Applicable on attributes that take on a relatively small number of distinct values  E.g. gender, country, state, …  E.g. income-level (income broken up into a small number of levels such as , , , infinity)  A bitmap is simply an array of bits

Use of Bitmap Indices: Example  In its simplest form, a bitmap index on an attribute has a bitmap for each value of the attribute  Bitmap has as many bits as records  In a bitmap for value v, the bit for a record is 1 if the record has the value v for the attribute, and is 0 otherwise

Bitmap Indices  Bitmap indices are useful for queries on multiple attributes  Queries are answered using bitmap operations  Intersection (and)  Union (or)  Complementation (not)  Each operation takes two bitmaps of the same size and applies the operation on corresponding bits to get the result bitmap  Males with income level L1  AND =  Can then retrieve required tuples  Counting number of matching tuples is even faster