You are on page 1of 29

Sequential File

10
20
30
40
50
60
70
80
90
100

CS 245 Notes 4 1
Dense Index Sequential File

10 10
20 20
30
40
30
40
50
60 50
70 60
80
70
90 80
100 90
110 100
120

CS 245 Notes 4 2
Sparse Index Sequential File

10 10
30 20
50
70
30
40
90
110 50
130 60
150
70
170 80
190 90
210 100
230

CS 245 Notes 4 3
Sparse 2nd level Sequential File

10 10 10
90 30 20
170 50
250 70
30
40
90
330 50
110
410 60
130
490
150
570 70
170 80
190 90
210 100
230

CS 245 Notes 4 4
Notes on pointers:
(2) If file is contiguous, then we can omit
pointers (i.e., compute them)

CS 245 Notes 4 5
R1

K1 R2 say:
K2 1024 B
per block
K3 R3

K4
R4

• if we want K3 block:
get it at offset
(3-1)1024
= 2048 bytes

CS 245 Notes 4 6
Duplicate keys

10
10
10
20
20
30
30
30
40
45
CS 245 Notes 4 7
Duplicate keys
Dense index, one way to implement?
10
10 10
10
10 10
20 20

20 20
30 30
30 30
30 30
40
45
CS 245 Notes 4 8
Duplicate keys
Dense index, better way?
10
10 10
20
30 10
40 20
20
30
30
30
40
45
CS 245 Notes 4 9
Duplicate keys
Sparse index, one way?
10
careful if looking

10 10
for 20 or 30!

10
20 10
30 20
20
30
30
30
40
45
CS 245 Notes 4 10
Duplicate keys
Sparse index, another way?
– place first new key from block
10
should 10 10
20
this be 30 10
40? 30 20
20
30
30
30
40
45
CS 245 Notes 4 11
Deletion from sparse index

10
10 20
30
50 30
70 40

90 50
110 60
130 70
150 80

CS 245 Notes 4 12
Deletion from sparse index
– delete record 40
10
10 20
30
50 30
70 40

90 50
110 60
130 70
150 80

CS 245 Notes 4 13
Deletion from sparse index
– delete record 30
10
10 20
40 30
50 30 40
70 40

90 50
110 60
130 70
150 80

CS 245 Notes 4 14
Deletion from sparse index
– delete records 30 & 40
10
10 20
50 30
70 50 30
70 40

90 50
110 60
130 70
150 80

CS 245 Notes 4 15
Deletion from dense index

10
10 20
20
30 30
40 40

50 50
60 60
70 70
80 80

CS 245 Notes 4 16
Deletion from dense index
– delete record 30
10
10 20
20
40 30 30 40
40 40

50 50
60 60
70 70
80 80

CS 245 Notes 4 17
Insertion, sparse index case

10
10 20
30
40 30
60

40
50
60

CS 245 Notes 4 18
Insertion, sparse index case
– insert record 34
10
10 20
30
40 30
60 34
40
50
• our lucky day! 60
we have free space
where we need it!

CS 245 Notes 4 19
Insertion, sparse index case
– insert record 15
10
10 20 15
20 30
40 30 20
60 30
40
50
• Illustrated: Immediate reorganization 60
• Variation:
– insert new block (chained file)
– update index

CS 245 Notes 4 20
Insertion, sparse index case
– insert record 25
10 25
10 20
30
40 30 overflow blocks
60 (reorganize later...)
40
50
60

CS 245 Notes 4 21
Secondary indexes
Sequence
field

30
50
20
70
80
40
100
10
90
60

CS 245 Notes 4 22
Secondary indexes
Sequence
• Sparse index field

30
30
20
50
80 20
100 70
90 80
... 40
100
10
does not make sense! 90
60

CS 245 Notes 4 23
Secondary indexes
Sequence
• Dense index field

10 30
20 50
10 30
40 20
50
90
70
... 50
60 80
sparse 70 40
high ... 100
level 10
90
60

CS 245 Notes 4 24
Duplicate values & secondary indexes
20
10
20
40
10
40
10
40
30
40

CS 245 Notes 4 25
Duplicate values & secondary indexes
one option...
10 20
10 10
10
20
Problem: 20
40
20
excess overhead! 30 10
• disk space 40 40
40
• search time 10
40 40
40
... 30
40

CS 245 Notes 4 26
Duplicate values & secondary indexes
another option...
10 20
10
20
Problem: 20
40
variable size 10
records in 30
40
index! 40 10
40
30
40

CS 245 Notes 4 27
Duplicate values & secondary indexes
20 
10 10
20
30 20
40 40

50 10
60 40
...
10 
40
Another idea (suggested in class): 30 
Chain records with same key?
40 
Problems:
• Need to add fields to records
• Need to follow chain to know records

CS 245 Notes 4 28
Duplicate values & secondary indexes
20
10 10
20
30 20
40 40
50 10
60 40
...
10
40
30
40
buckets
CS 245 Notes 4 29

You might also like