Académique Documents
Professionnel Documents
Culture Documents
} sector
Data transfer:
Move the r/w head to the appropriate track
• time needed - seek time – ~ 12 to 14 ms
Wait for the appropriate block to come under r/w head
• time needed - rotational delay - ~3 to 4ms (avg)
Record 2
1 2 3 3
1
File blocks:
sequence of blocks containing all the records of the file
Linked allocation
• each file block is assigned to some disk block
• each disk block has a pointer to next block of the sequence
• file expansion is easy; but scanning is slow
Mixed allocation
Heap file:
Records are appended to the file as they are inserted
Simplest organization
Insertion - Read the last file block, append the record and
write back the block - easy
Locating a record given values for any attribute
• requires scanning the entire file – very costly
Heap files are often used only along with other access structures.
Deleting a record
• deletion markers are used.
Prof P Sreenivasa Kumar 11
Department of CS&E, IITM
Hashed files
Very useful file organization, if quick access to the data record is
needed given the value of a single attribute.
Hash function h: maps the values from the domain of the hashing
attribute to bucket numbers
2
Search: Given the hash filed value
k, compute r= h(k). Get the bucket
r and search for the record. If not
found, search the overflow chain
of bucket r. M-1 Overflow
buckets
Main buckets
Locating a record
Match the d-bit sequence with an entry in the directory and go to
the corresponding bucket to find the record
Prof P Sreenivasa Kumar 18
Department of CS&E, IITM
Insertion in Extendible Hashing Scheme (1/2)
2 - bit sequence for the record to be inserted: 00
b0 b0
1
full
00 b3
00 b1
2 01
01
10 b1
10
b2 11
11
2 d=2
b2
d=2
all local
b0 Full: Bucket b0 is split depth = 2
Insert 11 1
1 22
0 12
1
1
45
11
Prof P Sreenivasa Kumar 21
Department of CS&E, IITM
Insert 15 1
22
12 Overflow occurs.
2 2 Global depth = local depth
00 45 Directory doubles and split occurs
01
10 45 101101
11 2
11 22 10110
15 12 1100
Insert 10 2 11 1011
12 15 1111
10 1010
2
45 Overflows occurs.
2
00 Since local depth < global depth
01 2 Split image is created
10 10
22
Directory is not doubled
11
2
11
15
Prof P Sreenivasa Kumar 22
Department of CS&E, IITM
Linear Hashing
Does not require a separate directory structure
.
When the first overflow in any bucket occurs: .
Say, overflow occurred in bucket s M-1
Insert the record in the overflow chain of bucket s
Create a new bucket M
M
Split the bucket 0 records by using h1 Split image
of bucket 0
Some records stay in bucket 0 and some
go to bucket M.
After M overflows, .
.
Split
ho h1 hi M+1
images
… …
h1 h2 hi+1
.
.
Since,
r – even – (M'2s + k) mod 2M' = k
r – odd – ( M'(2s + 1) + k ) mod 2M' = M' + k
Insert 12, 11
Insert 14 0 12 h0 = x mod 2
N N
0 12 14 h1 = x mod 4
11
B0 overflows
Bucket pointed by 1 11
N is split
Hash functions are
changed
Insert 10
N 0 12
0 12
Insert 18 1 9
N 13
1 11 9
overflow at B3
h1 is 13 2 14 18
split B1 10
applied here h0 = mod 4
2 14 h1 = mod 8 3 11
10
Primary Index:
Index built on ordering key field of a file
Clustering Index:
Index built on ordering non-key field of a file
Secondary Index:
Index built on any non-ordering field of a file
a block Bj .
.
.
.
. 129 2
.
Index file: ordered file (sorted on OKF) 130
.
.
240 b
- generally more than data file blocking factor 244
.
Insertions:
Handled using overflow chains at data file blocks
Deletions:
Handled using deletion markers
P1 K 1 P2 K 2 … Ki-1 Pi Ki … Kj-1 Pj …
Example
2 5 12 -
x≤ 2 x > 12
2 < x ≤ 5 5 < x ≤ 12
K1 Pr1 K2 Pr2 … K j Pj … P
… …
3 7
2 - 4 - 9 -
1 2 3 - 4 - 6 7 8 9 12 15 ^
3 4
Insert 25 Insert 30
14 - ^ 14 25
Inserted at Overflow.
11 14 20 25 ^ 11 14 20 25 30
leaf level split at 25.
25 is moved
up
Prof P Sreenivasa Kumar 51
Department of CS&E, IITM
Insert 12 Overflow at leaf level.
- Split at leaf level,
- Triggers overflow at internal node
- Split occurs at internal node
5 .
14 -
11 12 14 - 20 25 30 -
12 - ^ 22 25
11 12 14 20 22 25 30 -
Insert 23, 24 7
14 24
12 - ^ 22 25
11 12 14 20 22 23 24 25 30
12 22 25
11 12 14 20 22 23 24 25 30
Delete 20
14 24 Removed entry
from leaf here
12 22 25
11 12 14 22 23 24 25 30
11 12 14 23 24 25 30
Delete 24
14
12 23 25
11 12 14 23 25 30
11 23 25
11 12 23 25 30
Delete 12
23 25 Level drop has occurred
11 23 25 30
3) Height of the tree is less as only keys are used for indexing