Notes05 - CS 245 Notes 5 1 CS 245 Database System...

Info iconThis preview shows pages 1–22. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 245 Notes 5 1 CS 245: Database System Principles Hector Garcia-Molina Notes 5: Hashing and More CS 245 Notes 5 2 key → h(key) Hashing <key> . . . Buckets (typically 1 disk block) CS 245 Notes 5 3 . . . Two alternatives records . . . (1) key → h(key) CS 245 Notes 5 4 (2) key → h(key) Index record key 1 Two alternatives CS 245 Notes 5 5 (2) key → h(key) Index record key 1 Two alternatives • Alt (2) for “secondary” search key CS 245 Notes 5 6 Example hash function • Key = ‘x 1 x 2 … x n ’ n byte character string • Have b buckets • h: add x 1 + x 2 + ….. x n – compute sum modulo b CS 245 Notes 5 7 ➽ This may not be best function … ➽ Read Knuth Vol. 3 if you really need to select a good function. CS 245 Notes 5 8 ➽ This may not be best function … ➽ Read Knuth Vol. 3 if you really need to select a good function. Good hash Expected number of function: keys/bucket is the same for all buckets CS 245 Notes 5 9 Within a bucket: • Do we keep keys sorted? • Yes, if CPU time critical & Inserts/Deletes not too frequent CS 245 Notes 5 10 Next: example to illustrate inserts, overflows, deletes h(K) CS 245 Notes 5 11 EXAMPLE 2 records/bucket INSERT: h(a) = 1 h(b) = 2 h(c) = 1 h(d) = 0 1 2 3 CS 245 Notes 5 12 EXAMPLE 2 records/bucket INSERT: h(a) = 1 h(b) = 2 h(c) = 1 h(d) = 0 1 2 3 d a c b h(e) = 1 CS 245 Notes 5 13 EXAMPLE 2 records/bucket INSERT: h(a) = 1 h(b) = 2 h(c) = 1 h(d) = 0 1 2 3 d a c b h(e) = 1 e CS 245 Notes 5 14 1 2 3 a b c e d EXAMPLE: deletion Delete: e f f g CS 245 Notes 5 15 1 2 3 a b c e d EXAMPLE: deletion Delete: e f f g maybe move “g” up c CS 245 Notes 5 16 1 2 3 a b c e d EXAMPLE: deletion Delete: e f f g maybe move “g” up c d CS 245 Notes 5 17 Rule of thumb: • Try to keep space utilization between 50% and 80% Utilization = # keys used total # keys that fit CS 245 Notes 5 18 Rule of thumb: • Try to keep space utilization between 50% and 80% Utilization = # keys used total # keys that fit • If < 50%, wasting space • If > 80%, overflows significant depends on how good hash function is & on # keys/bucket CS 245 Notes 5 19 How do we cope with growth? • Overflows and reorganizations • Dynamic hashing CS 245 Notes 5 20 How do we cope with growth? • Overflows and reorganizations • Dynamic hashing • Extensible • Linear CS 245 Notes 5 21 Extensible hashing: two ideas (a) Use i of b bits output by hash function b h(K) → use i → grows over time…....
View Full Document

This note was uploaded on 02/21/2011 for the course CS 245 taught by Professor Dr.hector during the Winter '02 term at SUNY Buffalo.

Page1 / 102

Notes05 - CS 245 Notes 5 1 CS 245 Database System...

This preview shows document pages 1 - 22. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online