Title: CS 245 Database System Principles
1CPSC-608 Database Systems
Fall 2009
Instructor Jianer Chen Office HRBB 309B Phone
845-4259 Email chen_at_cs.tamu.edu
Notes 9
2Linear hashing
- Another dynamic hashing scheme
3Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1111
1010
m 01 (max used block)
4Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1111
1010
m 01 (max used block)
4
5Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
m 01 (max used block)
6Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1111
1010
m 01 (max used block)
6
7Example b4 bits, i 2, 2 keys/bucket
0101
- can have overflow chains!
Future growth buckets
0101
0000
1111
1010
m 01 (max used block)
8Note
- In textbook, n is used instead of m
- nm1
n10
Future growth buckets
0101
0000
1111
1010
00 01 10 11
m 01 (max used block)
9Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1111
1010
m 01 (max used block)
10
10Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1010
1111
1010
m 01 (max used block)
10
11Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1010
1111
1010
m 01 (max used block)
10
12Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1010
1111
1010
m 01 (max used block)
10
11
13Example b4 bits, i 2, 2 keys/bucket
Future growth buckets
0101
0000
1010
1111
0101
1111
1010
m 01 (max used block)
10
11
14Example Continued How to grow beyond this?
i 2
1111
1010
0101
0000
0101
. . .
m 11 (max used block)
15Example Continued How to grow beyond this?
i 2
1111
1010
0101
0000
0101
0
0
0
0
100 101 110 111
m 11 (max used block)
16Example Continued How to grow beyond this?
i 2
1111
1010
0101
0000
0101
100
0
0
0
0
. . .
100 101 110 111
m 11 (max used block)
100
17Example Continued How to grow beyond this?
i 2
3
1111
1010
0101
0000
0101
100
0
0
0
0
. . .
100 101 110 111
m 11 (max used block)
100
17
18Example Continued How to grow beyond this?
i 2
3
0101
1111
1010
0101
0000
0101
0101
101
100
0
0
0
0
. . .
100 101 110 111
m 11 (max used block)
100
101
19? When do we expand file?
- Keep track of used slots
- total of slots
U
- If U gt threshold then increase m
- (and maybe i )
20 Linear Hashing
Summary
- Can handle growing files
- - with less wasted space
- - with no full reorganizations
-
- No indirection like extensible hashing
21Example BAD CASE
- Very full
- Very empty Need to move
- m here
- Would waste
- space
-
22Summary
- Hashing
- - How it works
- - Dynamic hashing
- - Extensible
- - Linear
23Next
- Indexing vs. hashing
- Index definition in SQL
- Multiple key access
24Indexing vs. Hashing
- Hashing good for probes given key
- e.g., SELECT
- FROM R
- WHERE R.A 5
25Indexing vs. Hashing
- INDEXING (including B-trees) good for
- range searches
- e.g., SELECT
- FROM R
- WHERE R.A gt 5
26Index definition in SQL
- Create index name on rel (attr)
27- CANNOT SPECIFY TYPE OF INDEX
- (e.g. B-tree, hashing, )
- OR PARAMETERS
- (e.g. load factor, size of hash, )
- at least not in SQL
Note