SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
1
CS143: Hash Index
2
What is a Hash Table?
• Hash Table
– Hash function
• h(k): key ‡ integer [0…n]
• e.g., h(‘Susan’) = 7
– Array for keys: T[0…n]
– Given a key k, store it in
T[h(k)]
5
Susan4
James3
2
Neil1
0
h(Susan) = 4
h(James) = 3
h(Neil) = 1
3
Why Hash Table?
• Direct access
• Saved space
– Do not reserve a space for
every possible key
• How can we use this idea for
a record search in a DBMS?
4
Hashing for DBMS
(Static Hashing)
(key, record)
.
.
.
Disk blocks
(buckets)
search key Æ h(key)
0
1
2
3
4
5
Issues?
• What hash function?
• Overflow?
• How to store records?
6
Record storage
1. Whole record
2. Key and pointer
.
.
.
record
.
.
.
record
key 1
h(key)
h(key)
7
Overflow and Chaining
• Insert
h(a) = 1
h(b) = 2
h(c) = 1
h(d) = 0
h(e) = 1
• Delete
h(b) = 2
h(c) = 1
0
1
2
3
Do we keep keys sorted inside a block?
8
Questions
• Q: Do we keep keys sorted
inside a block?
• Q: How much space should
we use for “good”
performance?
9
What Hash Function?
• Example
– Key = ‘x1 x2 … xn’ n byte
character string
– Have b buckets
– h: (x1 + x2 + ….. xn) mod b
• Desired property
– Uniformity: same # of keys for
every bucket
• Reference
– “The Art of Computer
Programming Vol. 3” by Knuth
10
Major Problem of
Static Hashing
• How to cope with growth?
– Data tends to grow in size
– Overflow blocks unavoidable
10
20
30
40
50
60
70
80
90
39
31
35
36
32
38
34
33
overflow blocks
hash buckets
11
Idea 1
• Periodic reorganization
– New hash function
– Complete reassignment of records
– Very expensive
10
20
30
40
50
…
33
10
20
30
40
50
60
70
80
90
33
40
50
60
12
Idea 2
• Why don’t we split a bucket
when it overflows?
0 a
3 b
2 d
1 c
e
Insert: h(g) = 1
13
(a) Use i of b bits output by
hash function
Extendible Hashing
(two ideas)
00110101h(K) Æ
b
use i Æ grows over time
14
(b) Use directory that
maintains pointers to hash
buckets (indirection)
Extendible Hashing
(two ideas)
.
.
.
.
.
.
c
e
hash bucketdirectory
h(c)
15
Example
• h(k) is 4 bits; 2 keys/bucket
Insert 0111, 1010
1
1
1
0001
1001
1100
0
1
i =
16
Example continued
Insert 0000
1
0001
2
1001
1010
2
1100
00
01
10
11
2i =
0111
17
Example continued
Insert 1011
00
01
10
11
2i =
21001
1010
21100
20111
20000
0001
18
Questions on
Extendible Hashing
• Q: What will happen if we
have a lot of duplicate search
keys?
19
Duplicate keys
• Insert 0001
1
1
1
0001
0
1
i =
0001
20
Questions on
Extendible Hashing
• Can we provide minimum
space guarantee?
21
Space Waste
2
1
40001
40000
0000
4i =
3
22
Extendible Hashing:
Deletion
• Two options
a) No merging of buckets
b) Merge buckets and shrink
directory if possible
23
Bucket Merge Example
Can we merge a and b? b and c?
Can we shrink the directory?
1
0001
2
1001
2
1100
00
01
10
11
2i =
a
b
c
24
Bucket Merge
Condition
• Bucket merge condition
– Bucket i’s are the same
– First (i-1) bits of the hash key
are the same
• Directory shrink condition
– All bucket i’s are smaller than
the directory i
25
Summary of
Extendible Hashing
• Can handle growing files
– No periodic reorganizations
• Indirection
– Up to 2 disk accesses to
access a key
• Directory doubles in size
– Not too bad if the data is not
too large
26
Hashing vs. Tree
• Can an extendible-hash index
support?
SELECT
FROM R
WHERE R.A > 5
• Which one is better, B+tree
or Extendible hashing?
SELECT
FROM R
WHERE R.A = 5

Mais conteúdo relacionado

Mais procurados

Bloom filter
Bloom filterBloom filter
Bloom filter
feng lee
 
June Overview SN5 Math
June Overview SN5 MathJune Overview SN5 Math
June Overview SN5 Math
amcsquared
 

Mais procurados (19)

Bloom filter
Bloom filterBloom filter
Bloom filter
 
Heaps 4up
Heaps 4upHeaps 4up
Heaps 4up
 
Statistics - ArgMax Equation
Statistics - ArgMax EquationStatistics - ArgMax Equation
Statistics - ArgMax Equation
 
関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡
 
The simplest existential graph system
The simplest existential graph systemThe simplest existential graph system
The simplest existential graph system
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Secure and privacy-preserving data transmission and processing using homomorp...
Secure and privacy-preserving data transmission and processing using homomorp...Secure and privacy-preserving data transmission and processing using homomorp...
Secure and privacy-preserving data transmission and processing using homomorp...
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel Summit
 
Algebra 2 Lesson 5-6
Algebra 2 Lesson 5-6Algebra 2 Lesson 5-6
Algebra 2 Lesson 5-6
 
Excel
ExcelExcel
Excel
 
June Overview SN5 Math
June Overview SN5 MathJune Overview SN5 Math
June Overview SN5 Math
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#
 
k-means Clustering and Custergram with R
k-means Clustering and Custergram with Rk-means Clustering and Custergram with R
k-means Clustering and Custergram with R
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
 
関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Megadata With Python and Hadoop
Megadata With Python and HadoopMegadata With Python and Hadoop
Megadata With Python and Hadoop
 
CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
New day 3 examples
New day 3 examplesNew day 3 examples
New day 3 examples
 

Destaque

Hash mac algorithms
Hash mac algorithmsHash mac algorithms
Hash mac algorithms
Fraboni Ec
 

Destaque (13)

Hash mac algorithms
Hash mac algorithmsHash mac algorithms
Hash mac algorithms
 
Hash algorithms in IT security
Hash algorithms in IT securityHash algorithms in IT security
Hash algorithms in IT security
 
Keccak
KeccakKeccak
Keccak
 
Ds 8
Ds 8Ds 8
Ds 8
 
Doan P. Sinaga, Alex F. Manihuruk, Kevin G.A.T. Pardosi - Securing SCADA Syst...
Doan P. Sinaga, Alex F. Manihuruk, Kevin G.A.T. Pardosi - Securing SCADA Syst...Doan P. Sinaga, Alex F. Manihuruk, Kevin G.A.T. Pardosi - Securing SCADA Syst...
Doan P. Sinaga, Alex F. Manihuruk, Kevin G.A.T. Pardosi - Securing SCADA Syst...
 
18 hashing
18 hashing18 hashing
18 hashing
 
Cryptography Ashik
Cryptography AshikCryptography Ashik
Cryptography Ashik
 
Cryprography Assignment
Cryprography AssignmentCryprography Assignment
Cryprography Assignment
 
Hashing
HashingHashing
Hashing
 
Secure Hash Algorithm (SHA-512)
Secure Hash Algorithm (SHA-512)Secure Hash Algorithm (SHA-512)
Secure Hash Algorithm (SHA-512)
 
Secure Hash Algorithm
Secure Hash AlgorithmSecure Hash Algorithm
Secure Hash Algorithm
 
Hash Function & Analysis
Hash Function & AnalysisHash Function & Analysis
Hash Function & Analysis
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 

Semelhante a Hash

Semelhante a Hash (20)

Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
Hashing
HashingHashing
Hashing
 
Basic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and programBasic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and program
 
[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
Data Structures- Hashing
Data Structures- Hashing Data Structures- Hashing
Data Structures- Hashing
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
session 15 hashing.pptx
session 15   hashing.pptxsession 15   hashing.pptx
session 15 hashing.pptx
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
Indexing
IndexingIndexing
Indexing
 
lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
 
Hash Functions FTW
Hash Functions FTWHash Functions FTW
Hash Functions FTW
 
Hash tables
Hash tablesHash tables
Hash tables
 
Strata NYC 2015: Sketching Big Data with Spark: randomized algorithms for lar...
Strata NYC 2015: Sketching Big Data with Spark: randomized algorithms for lar...Strata NYC 2015: Sketching Big Data with Spark: randomized algorithms for lar...
Strata NYC 2015: Sketching Big Data with Spark: randomized algorithms for lar...
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
 
Hash table
Hash tableHash table
Hash table
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
 
Hash table
Hash tableHash table
Hash table
 

Mais de zhaolinjnu (8)

MySQL aio
MySQL aioMySQL aio
MySQL aio
 
Redis介绍
Redis介绍Redis介绍
Redis介绍
 
Hbase源码初探
Hbase源码初探Hbase源码初探
Hbase源码初探
 
淘宝数据库架构演进历程
淘宝数据库架构演进历程淘宝数据库架构演进历程
淘宝数据库架构演进历程
 
Mysql参数-GDB
Mysql参数-GDBMysql参数-GDB
Mysql参数-GDB
 
Inno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structureInno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structure
 
Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应
 
2010丹臣的思考
2010丹臣的思考2010丹臣的思考
2010丹臣的思考
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Hash