Hashing and B-Tree File Organization: Overflow, Performance, Dynamic & Extendable Hashing, Study notes of Principles of Database Management

An overview of b+-tree file organization and its relation to b-trees, as well as an in-depth analysis of hashing, including hash functions, overflow handling, hashed file performance metrics, static and dynamic hashing, and extendable hashing. Topics covered include hash file organization, hash indices, static hashing disadvantages, and dynamic hashing benefits.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-7qo-1
koofers-user-7qo-1 🇺🇸

5

(1)

9 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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 file
leaf and interior nodes are different
B-trees
search key values appear only once
pointer to record/bucket for that search key value always stored
with the search key itself, even in interior nodes
Hashing Overview
Hash functions
ideally uniform, random, easy to compute
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Hashing and B-Tree File Organization: Overflow, Performance, Dynamic & Extendable Hashing and more Study notes Principles of Database Management in PDF only on Docsity!

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 file
    • leaf and interior nodes are different
  • B-trees
    • search key values appear only once
    • pointer to record/bucket for that search key value always stored with the search key itself, even in interior nodes
  • Hashing Overview
    • Hash functions
      • ideally uniform, random, easy to compute

Today

  • Overflow
  • Hash file performance
  • Hash indices
  • Dynamic Hashing (Extendable Hashing)
  • Note: HW#3 due next class (April 17)
  • HW #4: due Thursday April 24 (9 days from now)
    • Questions: 12.11, 12.12, 12.13, 12.

Overflow (2)

  • Overflow is handled by one of two methods
    • chaining of multiple blocks in a bucket, by attaching a number of overflow buckets together in a linked list
    • double hashing : use a second hash function to find another (hopefully non-full) bucket
    • in theory we could use the next bucket that had space; this is often called open hashing or linear probing. This is often used to construct symbol tables for compilers - useful where deletion does not occur - deletion is very awkward with linear probing, so it isn’t useful in most database applications

Hashed File Performance Metrics

  • An important performance measure is the loading factor

(number of records)/(B*f)

B is the number of buckets

f is the number of records that will fit in a single bucket

  • when loading factor too high (file becomes too full),

double the number of buckets and rehash

Hash Indices

  • Hashing can be used for index-structure creation as well as

for file organization

  • A hash index organizes the search keys (and their record

pointers) into a hash file structure

  • strictly speaking, a hash index is always a secondary index
    • if the primary file was stored using the same hash function, an additional, separate primary hash index would be unnecessary
    • We use the term hash index to refer both to secondary hash indices and to files organized using hashing file structures

Example of a Hash Index

Hash index into file

account, on search key

account-number ;

Hash function computes

sum of digits in account

number modulo 7.

Bucket size is 2

Dynamic Hashing

  • One form of dynamic hashing is extendable hashing
    • hash function generates values over a large range -- typically b-bit integers, with b being something like 32
    • At any given moment, only a prefix of the hash function is used to index into a table of bucket addresses
    • With the prefix at a given moment being j, with 0<=j<=32, the bucket address table size is 2j
    • Value of j grows and shrinks as the size of the database grows and shrinks
    • Multiple entries in the bucket address table may point to a bucket
    • Thus the actual number of buckets is < 2j
    • the number of buckets also changes dynamically due to coalescing and splitting of buckets

General Extendable Hash Structure

Splitting in Extendable Hash Structure

To split a bucket j when inserting a record with search-key value Kj

  • if i> ij (more than one pointer in to bucket j)
    • allocate a new bucket z
    • set ij and iz to the old value ij incremented by one
    • update the bucket address table (change the second half of the set of entries pointing to j so that they now point to z)
    • remove all the entries in j and rehash them so that they either fall in z or j
    • reattempt the insert (Kj). If the bucket is still full, repeat the above.

Splitting in Extendable Hash Structure

To split a bucket j when inserting a record with search-key value Kj

  • if i= ij (only one pointer in to bucket j)
    • increment i and double the size of the bucket address table
    • replace each entry in the bucket address table with two entries that point to the same bucket
    • recompute new bucket address table entry for Kj
    • now i> ij so use the first case described earlier
  • When inserting a value, if the bucket is still full after several splits (that is, i reaches some preset value b), give up and create an overflow bucket rather than splitting the bucket entry table further - how might this occur?

Extendable Hash Structure Example

Hash function

on branch name

Initial hash table

(empty)

Extendable Hash Structure Example (2)

Hash structure after insertion of one Brighton and two Downtown records

Extendable Hash Structure Example (4)

Hash structure after insertion of three Perryridge records

Extendable Hash Structure Example (5)

Hash structure after insertion of Redwood and Round Hill records