Hash-Based Indexes

 
Hash-Based Indexes
 
Credits: Ramakrishnan & Gehrke
 
What you will learn from this lecture
 
Review of static hashing
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
 
Introduction
 
Hash-based
 indexes are best for 
equality
selections
n
o
 
t
r
a
v
e
r
s
a
l
;
 
d
i
r
e
c
t
 
c
o
m
p
u
t
a
t
i
o
n
 
o
f
 
w
h
e
r
e
 
k
e
y
s
h
o
u
l
d
 
b
e
c
a
n
n
o
t
 
s
u
p
p
o
r
t
 
r
a
n
g
e
 
s
e
a
r
c
h
e
s
Static and dynamic hashing techniques exist;
trade-offs similar to ISAM vs. B+ trees, on a
certain level.
 
Direct Mapping Table
 
# 
primary/home buckets
 fixed, allocated sequentially,
never de-allocated
h
(
k
)
 
=
 
k
 
=
 
b
u
c
k
e
t
 
t
o
 
w
h
i
c
h
 
d
a
t
a
 
e
n
t
r
y
 
w
i
t
h
 
k
e
y
 
k
 
b
e
l
o
n
g
s
.
(
M
 
=
 
#
 
o
f
 
b
u
c
k
e
t
s
)
#slots per bucket s, let s = 1 here
 
h(key) mod M
 
h
 
key
 
P
r
i
m
a
r
y
 
b
u
c
k
e
t
 
p
a
g
e
s
 
1
 
0
 
M-1
 
Direct Mapping Table Bucket
 
    private class Bucket
    {
        int     nKeys = 0;                        // 0 or 1
        Integer key   = null;
        V       value = null;
        Bucket  next  = null;
 
        V find (Integer k)
        {
            if (key != null && key.equals (k)) return value;
            return null;
        } // find
 
        void add (Integer k, V v) { nKeys = 1; key = k; value = v; }
 
        void print () { out.println ("[ " + key + " . ]" ); }
 
    } // Bucket inner class
 
Direct Mapping Table
 
Hash Function
 
   private int h (Object key) { return (int) key; }
 
get Method
 
 
    @SuppressWarnings("unchecked")
    public V get (Object key)
    {
        var i  = h (key);
        var bh = hTable.get (i);
        return bh.find ((Integer) key);
    } // get
 
Static Hashing
 
# 
primary/home buckets
 fixed, allocated sequentially,
never de-allocated; 
overflow buckets
 if needed.
h
(
k
)
 
m
o
d
 
M
 
=
 
b
u
c
k
e
t
 
t
o
 
w
h
i
c
h
 
d
a
t
a
 
e
n
t
r
y
 
w
i
t
h
 
k
e
y
 
k
b
e
l
o
n
g
s
.
 
(
M
 
=
 
#
 
o
f
 
b
u
c
k
e
t
s
)
 
h(key) mod M
 
h
 
key
 
P
r
i
m
a
r
y
 
b
u
c
k
e
t
 
p
a
g
e
s
 
O
v
e
r
f
l
o
w
 
p
a
g
e
s
 
1
 
0
 
M-1
 
Static Hashing (Contd.)
 
Buckets may contain 
data entries 
or
 references
.
Hash function works on 
search key 
field of record 
r.  
Must
distribute values over range 0 ... M-1.
h
(
k
e
y
)
 
=
 
 
(
k
e
y
 
m
o
d
 
M
)
 
u
s
u
a
l
l
y
 
w
o
r
k
s
 
w
e
l
l
 
f
o
r
 
p
r
i
m
e
 
M
.
l
o
t
s
 
k
n
o
w
n
 
a
b
o
u
t
 
h
o
w
 
t
o
 
t
u
n
e
 
h
.
Long overflow chains 
can develop and degrade
performance (when there are updates).
Extendible
 and 
Linear
 
Hashing
: two major dynamic techniques to fix
this problem.
Slide Note
Embed
Share

In this lecture, you will delve into hash-based indexes, exploring their application in database management. Topics covered include static and dynamic hashing techniques, review of hashing structures, adjustments against inserts and deletes, extendible hashing, linear hashing, and the relative strengths of B+trees compared to hashing methods. Discover the primary characteristics and advantages of hash-based indexes for equality selections and learn about direct mapping tables and hash functions. Join the discussion on when to utilize hash-based indexes effectively within the context of database management.

  • Hash-Based Indexes
  • Database Management
  • Indexing Techniques
  • Hashing Structures
  • B+ Trees

Uploaded on Feb 18, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Hash-Based Indexes Credits: Ramakrishnan & Gehrke Textbook to be published by Pearson Ed in early 2014 CSCIX370: Database Management http://www.funwebdev.com

  2. What you will learn from this lecture Review of static hashing 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 CSCIX370: Database Management

  3. Introduction Hash-based indexes are best for equality selections no traversal; direct computation of where key should be cannot support range searches Static and dynamic hashing techniques exist; trade-offs similar to ISAM vs. B+ trees, on a certain level. CSCIX370: Database Management

  4. Direct Mapping Table # primary/home buckets fixed, allocated sequentially, never de-allocated h(k) = k = bucket to which data entry with key k belongs. (M = # of buckets) #slots per bucket s, let s = 1 here 0 h(key) mod M 1 key h M-1 Primary bucket pages CSCIX370: Database Management

  5. Direct Mapping Table Bucket private class Bucket { int nKeys = 0; // 0 or 1 Integer key = null; V value = null; Bucket next = null; V find (Integer k) { if (key != null && key.equals (k)) return value; return null; } // find void add (Integer k, V v) { nKeys = 1; key = k; value = v; } void print () { out.println ("[ " + key + " . ]" ); } } // Bucket inner class CSCIX370: Database Management

  6. Direct Mapping Table Hash Function private int h (Object key) { return (int) key; } get Method @SuppressWarnings("unchecked") public V get (Object key) { var i = h (key); var bh = hTable.get (i); return bh.find ((Integer) key); } // get CSCIX370: Database Management

  7. Static Hashing # primary/home buckets fixed, allocated sequentially, never de-allocated; overflow buckets if needed. h(k) mod M = bucket to which data entry with key k belongs. (M = # of buckets) 0 h(key) mod M 1 key h M-1 Primary bucket pages Overflow pages CSCIX370: Database Management

  8. Static Hashing (Contd.) Buckets may contain data entries or references. Hash function 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. Long overflow chains can develop and degrade performance (when there are updates). Extendible and Linear Hashing: two major dynamic techniques to fix this problem. CSCIX370: Database Management

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#