0% found this document useful (0 votes)
3 views

7_DataStorageIndexingStructures

Chapter 7 discusses data storage and indexing structures for files, covering topics such as disk storage devices, file operations, and various file types including unordered, ordered, and hashed files. It also delves into RAID technology, which enhances disk performance through data striping and redundancy, and introduces Storage Area Networks (SANs) for flexible data management. The chapter emphasizes the importance of efficient data storage and retrieval methods in database design.

Uploaded by

van.dothithuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

7_DataStorageIndexingStructures

Chapter 7 discusses data storage and indexing structures for files, covering topics such as disk storage devices, file operations, and various file types including unordered, ordered, and hashed files. It also delves into RAID technology, which enhances disk performance through data striping and redundancy, and introduces Storage Area Networks (SANs) for flexible data management. The chapter emphasizes the importance of efficient data storage and retrieval methods in database design.

Uploaded by

van.dothithuy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Data Storage, Indexing Structures

for Files
Chapter 7
Overview of Database Miniworld
Design Process
REQUIREMENTS - COLLECTION & ANALYSIS

Functional requirements Data requirements


DBMS–independent

FUNCTIONAL ANALYSIS
CONCEPTUAL DESIGN

High-level transaction Conceptual schema


specification
LOGICAL DESIGN
(DATA MODEL MAPPING)
DBMS–specific

APPLICATION PROGRAM Database schema


DESIGN
PHYSICAL DESIGN

TRANSACTION
Internal schema
IMPLEMENTATION

Application program
2
Application Design Database Design
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
3
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
4
Disk Storage Devices
 Preferred secondary storage device for high storage
capacity and low cost.
 Data stored as magnetized areas on magnetic disk
surfaces.
 A disk pack contains several magnetic disks connected
to a rotating spindle.
 Disks are divided into concentric circular tracks on
each disk surface .
 Track capacities vary typically from 4 to 50 Kbytes.

5
Disk Storage Devices (cont.)

6
Disk Storage Devices (cont.)

Track
Sector

Spindle

7
Disk Storage Devices (cont.)
 A track is divided into smaller blocks or sectors.
 because a track usually contains a large amount of
information .
 A track is divided into blocks.
 The block size B is fixed for each system.
 Typical block sizes range from B=512 bytes to B=4096
bytes.
 Whole blocks are transferred between disk and main
memory for processing.

8
Disk Storage Devices (cont.)
 A read-write head moves to the track that contains the
block to be transferred.
 Disk rotation moves the block under the read-write head for
reading or writing.
 A physical disk block (hardware) address consists of:
 a cylinder number (imaginary collection of tracks of same
radius from all recorded surfaces)
 the track number or surface number (within the cylinder)
 and block number (within track).
 Reading or writing a disk block is time consuming because
of the seek time s and rotational delay (latency) rd.
 Double buffering can be used to speed up the transfer of
contiguous disk blocks.

9
Disk storage devices (cont.)

10
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
11
Records
 Fixed and variable length records.
 Records contain fields which have values of a
particular type.
 E.g., amount, date, time, age.
 Fields themselves may be fixed length or variable
length.
 Variable length fields can be mixed into one record:
 Separator characters or length fields are needed so that
the record can be “parsed”.

12
Records (cont.)

(a)A fixed-length record with 6 fields and size of 71 bytes.


(b)A record with 2 variable-length fields and 3 fixed-length fields.
(c)A variable-field record with 3 types of separator characters.
13
Blocking
 Blocking: refers to storing a number of records in one
block on the disk.
 Blocking factor (bfr): refers to the number of records
per block.
 There may be empty space in a block if an integral
number of records do not fit in one block.
 Spanned Records: refer to records that exceed the
size of one or more blocks and hence span a number of
blocks.

14
Blocking (cont.)

(a)Unspanned records
(b)Spanned records
15
Files of Records
 A file is a sequence of records, where each record is a
collection of data values (or data items).
 A file descriptor (or file header) includes
information that describes the file, such as the field
names and their data types, and the addresses of the
file blocks on disk.
 Records are stored on disk blocks.
 The blocking factor bfr for a file is the (average)
number of file records stored in a disk block.
 A file can have fixed-length records or variable-
length records.

16
Files of Records (cont.)
 File records can be unspanned or spanned:
 Unspanned: no record can span two blocks
 Spanned: a record can be stored in more than one block
 The physical disk blocks that are allocated to hold the
records of a file can be contiguous, linked, or indexed.
 In a file of fixed-length records, all records have the same
format. Usually, unspanned blocking is used with such files.
 Files of variable-length records require additional
information to be stored in each record, such as separator
characters and field types.
 Usually spanned blocking is used with such files.

17
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
18
Operation on Files
 OPEN: Reads the file for access, and associates a
pointer that will refer to a current file record at each point
in time.
 FIND: Searches for the first file record that satisfies a
certain condition, and makes it the current file record.
 FINDNEXT: Searches for the next file record (from the
current record) that satisfies a certain condition, and makes
it the current file record.
 READ: Reads the current file record into a program
variable.
 INSERT: Inserts a new record into the file, and makes it
the current file record.

19
Operation on Files (cont.)
 DELETE: Removes the current file record from
the file, usually by marking the record to indicate that
it is no longer valid.
 MODIFY: Changes the values of some fields of
the current file record.
 CLOSE: Terminates access to the file.
 REORGANIZE: Reorganizes the file records. For
example, the records marked deleted are physically
removed from the file or a new organization of the file
records is created.
 READ_ORDERED: Read the file blocks in order of a
specific field of the file.

20
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
21
Unordered Files
 Also called a heap or a pile file.
 New records are inserted at the end of the file.
 A linear search through the file records is
necessary to search for a record.
 This requires reading and searching half the file blocks on
the average, and is hence quite expensive.
 Record insertion is quite efficient.
 Reading the records in order of a particular field
requires sorting the file records.

22
Ordered Files
 Also called a sequential file.
 File records are kept sorted by the values of an ordering
field.
 Insertion is expensive: records must be inserted in the
correct order.
 It is common to keep a separate unordered overflow (or transaction)
file for new records to improve insertion efficiency; this is
periodically merged with the main ordered file.
 A binary search can be used to search for a record on its
ordering field value.
 This requires reading and searching log2 of the file blocks on the
average, an improvement over linear search.
 Reading the records in order of the ordering field is quite
efficient.
23
Ordered Files
(cont.)

24
Average Access Times
 The following table shows the average access time to
access a specific record for a given type of file:

25
Hashed Files
 Hashing for disk files is called External Hashing.
 The file blocks are divided into M equal-sized buckets,
numbered bucket0, bucket1, ..., bucketM-1.
 Typically, a bucket corresponds to one (or a fixed number of) disk
block.
 One of the file fields is designated to be the hash key of the
file.
 The record with hash key value K is stored in bucket i,
where i=h(K), and h is the hashing function.
 Search is very efficient on the hash key.
 Collisions occur when a new record hashes to a bucket that
is already full.
 An overflow file is kept for storing such records.
 Overflow records that hash to each bucket can be linked together

26
Hashed Files (cont.)

27
Hashed Files (cont.)
 There are numerous methods for collision resolution,
including the following:
 Open addressing: Proceeding from the occupied position specified by
the hash address, the program checks the subsequent positions in
order until an unused (empty) position is found.

0 1 2 3 4 5 6
 h(K) = K mod 7
1 3 11 6

 Insert 8 1 8 3 11 6

 Insert 15 1 8 3 11 15 6

 Insert 13 13 1 8 3 11 15 6

28
Hashed Files (cont.)
 There are numerous methods for collision resolution,
including the following:
 Chaining:
 Various overflow locations are kept: extending the array with a number of
overflow positions.
 A pointer field is added to each record location.
 A collision is resolved by placing the new record in an unused overflow
location and setting the pointer of the occupied hash address location to
the address of that overflow location.

 Multiple hashing:
 The program applies a second hash function if the first results in a
collision.
 If another collision results, the program uses open addressing or applies a
third hash function and then uses open addressing if necessary.

29
Hashed Files (cont.) - Overflow
handling

30
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
31
Parallelizing Disk Access using RAID
Technology
 Secondary storage technology must take steps to keep
up in performance and reliability with processor
technology.
 A major advance in secondary storage technology is
represented by the development of RAID, which
originally stood for Redundant Arrays of Inexpensive
Disks.
 The main goal of RAID is to even out the widely
different rates of performance improvement of disks
against those in memory and microprocessors.

32
RAID Technology (cont.)
 A natural solution is a large array of small independent
disks acting as a single higher-performance logical disk.
 A concept called data striping is used, which utilizes
parallelism to improve disk performance.
 Data striping distributes data transparently over multiple
disks to make them appear as a single large, fast disk.

33
RAID Technology (cont.)
 Different raid organizations were defined based on
different combinations of the two factors of granularity of
data interleaving (striping) and pattern used to compute
redundant information.
 Raid level 0 has no redundant data and hence has the best write
performance.
 Raid level 1 uses mirrored disks.
 Raid level 2 uses memory-style redundancy by using Hamming
codes, which contain parity bits for distinct overlapping subsets of
components. Level 2 includes both error detection and correction.

34
RAID Technology (cont.)
 Raid level 3 uses a single parity disk relying on the disk
controller to figure out which disk has failed.
 Raid levels 4 and 5 use block-level data striping, with
level 5 distributing data and parity information across all
disks.

35
RAID Technology (cont.)
 Raid level 6 applies the so-called P + Q redundancy
scheme using Reed-Soloman codes to protect against up
to two disk failures by using just two redundant disks.

36
Use of RAID Technology (cont.)
 Different raid organizations are being used under different
situations:
 Raid level 1 (mirrored disks)is the easiest for rebuild of a disk from
other disks
 It is used for critical applications like logs.
 Raid level 2 uses memory-style redundancy by using Hamming
codes, which contain parity bits for distinct overlapping subsets of
components. Level 2 includes both error detection and correction.
 Raid level 3 ( single parity disks relying on the disk controller to
figure out which disk has failed) and level 5 (block-level data
striping) are preferred for large volume storage, with level 3 giving
higher transfer rates.
 Most popular uses of the RAID technology currently are: Level 0
(with striping), Level 1 (with mirroring) and Level 5 with an extra
drive for parity.
 Design decisions for RAID include – level of RAID, number of disks,
choice of parity schemes, and grouping of disks for block-level
striping.

37
Storage Area Networks
 The demand for higher storage has risen considerably
in recent times.
 Organizations have a need to move from a static fixed
data center oriented operation to a more flexible and
dynamic infrastructure for information processing.
 Thus they are moving to a concept of Storage Area
Networks (SANs).
 In a SAN, online storage peripherals are configured as nodes
on a high-speed network and can be attached and detached
from servers in a very flexible manner.
 This allows storage systems to be placed at longer
distances from the servers and provide different
performance and connectivity options.

38
Storage Area Networks (cont.)
 Advantages of SANs are:
 Flexible many-to-many connectivity among servers and
storage devices using fiber channel hubs and switches.
 Up to 10km separation between a server and a storage system
using appropriate fiber optic cables.
 Better isolation capabilities allowing nondisruptive addition of
new peripherals and servers.
 SANs face the problem of combining storage options
from multiple vendors and dealing with evolving
standards of storage management software and
hardware.

39
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
40
Indexes as Access Paths
 A single-level index is an auxiliary file that makes it
more efficient to search for a record in the data file.
 The index is usually specified on one field of the file
(although it could be specified on several fields)
 One form of an index is a file of entries <field
value, pointer to record>, which is ordered by
field value
 The index is called an access path on the field.

41
Indexes as Access Paths (cont.)
 The index file usually occupies considerably less
disk blocks than the data file because its entries are
much smaller.
 A binary search on the index yields a pointer to the
file record.
 Indexes can also be characterized as dense or
sparse:
 A dense index has an index entry for every search key value
(and hence every record) in the data file.
 A sparse (or nondense) index, on the other hand, has index
entries for only some of the search values

42
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
43
Types of Single-level Ordered Indexes
 Primary Indexes

 Clustering Indexes

 Secondary Indexes

44
Primary Index
 Defined on an ordered data file.
 The data file is ordered on a key field.

 One index entry for each block in the data file


 First record in the block, which is called the block anchor

 A similar scheme can use the last record in a block.

45
Primary key field
ID Name DoB Salary Sex
1
2
Index file 3
(<K(i), P(i)> entries)
4
Primary Block 6
key value pointer
7
1
4 8
8 9
12 10

12
13
15
46
Primary Index
 Number of index entries?
 Number of blocks in data file.

 Dense or Nondense?
 Nondense

 Search/ Insert/ Update/ Delete?

47
Example
Given the following data file: EMPLOYEE(NAME, SSN, ADDRESS,
JOB, SAL, ... )
Suppose that:
 record size R = 150 bytes
 block size B = 512 bytes
 Number of records r = 30.000 records
 SSN Field size VSSN = 9 bytes,
 record pointer size PR = 7 bytes
 block pointer size PB = 6 bytes

Then, we get:
 blocking factor: bfr = B/R = 512/150 = 3 records/block
 number of blocks needed for the file: b = r/bfr= 30.000/3  =
10.000 blocks

48
Example
For a dense index on the SSN field:
 index entry size: Ri = (VSSN+ PR)=(9+7)=16 bytes
 index blocking factor bfri = B/RI = 512/16 = 32 entries/block
 number of blocks for index file: bi = r/bfri= (30000/32)= 938
blocks
 binary search to retrieve a record in index file needs: log2bi  =
log2938  = 10 block accesses
 To search for a record using the index, we need one additional
block access to the data file for a total of 10 + 1 = 11 block
accesses

This is compared to an average linear search cost of:


(b/2)= 10000/2 = 5000 block accesses
If the file records are ordered, the binary search cost would be:
 log2b  =  log210000  = 14 block accesses
49
Example
For a primary index on the ordering key field SSN : (using block
pointer)
 index entry size: Ri =(VSSN+ PB)=(9+6)=15 bytes
 index blocking factor bfri = B/RI = 512/15 = 34 entries/block
 number of blocks for index file: bi= r/bfri= (10000/34)= 295
blocks
 binary search to retrieve a record in index file needs: log2bi  =
log2295  = 9 block accesses
 To search for a record using the index, we need one additional
block access to the data file for a total of 9 + 1 = 10 block
accesses

This is compared to an average linear search cost of:


(b/2)= 10000/2 = 5000 block accesses
If the file records are ordered, the binary search cost would be:
 log2b  =  log210000  = 14 block accesses
50
Clustering Index
 Defined on an ordered data file.
 The data file is ordered on a non-key field.

 One index entry each distinct value of the field.


 The index entry points to the first data block that contains
records with that field value

51
Clustering field

Dept_No Name DoB Salary Sex


1
1
Index file 2
(<K(i), P(i)> entries)
2
Clustering Block
field value pointer 2
1 2
2
2
3
3
4
3
5
4
4
5
52
Clustering field Dept_No Name DoB Salary Sex
1
1

Index file 2
2
(<K(i), P(i)> entries)
2
Clustering Block
field value pointer 2

1
2 3
3
3
4
4
5
4

53
Clustering Index
 Number of index entries?
 Number of distinct indexing field values in data file.

 Dense or Nondense?
 Nondense

 Search/ Insert/ Update/ Delete?


 At most one primary index or one clustering
index but not both.

54
Secondary index
 A secondary index provides a secondary means of accessing
a file.
 The data file is unordered on indexing field.
 Indexing field:
 secondary key (unique value)
 nonkey (duplicate values)

 The index is an ordered file with two fields.


 The first field: indexing field.
 The second field: block pointer or record pointer.

 There can be many secondary indexes for the same file.

55
Index file Secondary
(<K(i), P(i)> entries) key field
Index field Block 5
value pointer
13
3
8
4
5 6
6 15
8 3
9
9
11
21
13 … 11
15
18 4
21 23
23 18

Secondary index on key field


56
Secondary index on key field
 Number of index entries?
 Number of record in data file

 Dense or Nondense?
 Dense

 Search/ Insert/ Update/ Delete?

57
Secondary index on non-key field
 Discussion: Structure of Secondary index on non-key
field?
 Option 1: include duplicate index entries with the
same K(i) value - one for each record.

 Option 2: keep a list of pointers <P(i, 1), ..., P(i, k)> in


the index entry for K(i).

 Option 3:
 more commonly used.
 one entry for each distinct index field value + an extra
level of indirection to handle the multiple pointers.

58
 Secondary
Index on
non-key
field:
option 3

59
Secondary index on nonkey field
 Number of index entries?
 Number of records in data file
 Number of distinct index field values

 Dense or Nondense?
 Dense/ nondense

 Search/ Insert/ Update/ Delete?

60
Summary of Single-level indexes
 Ordered file on indexing field?
 Primary index
 Clustering index
 Indexing field is Key?
 Primary index
 Secondary index
 Indexing field is not Key?
 Clustering index
 Secondary index

61
Summary of Single-level indexes
 Dense index?
 Secondary index

 Nondense index?
 Primary index
 Clustering index
 Secondary index

62
Summary of Single-level indexes

63
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
64
Multi-Level Indexes
 Because a single-level index is an ordered file, we can
create a primary index to the index itself.
 The original index file is called the first-level index and the
index to the index is called the second-level index.
 We can repeat the process, creating a third, fourth, ...,
top level until all entries of the top level fit in one
disk block.
 A multi-level index can be created for any type of first-
level index (primary, secondary, clustering) as long as
the first-level index consists of more than one disk
block.

65
A two-level primary
index resembling
ISAM (Indexed
Sequential Access
Method)
organization.

66
Multi-Level Indexes
 Such a multi-level index is a form of search tree.
 However, insertion and deletion of new index entries is
a severe problem because every level of the index is an
ordered file.

67
A Node in a Search Tree with Pointers to
Subtrees below It

68
A search tree of order p = 3

69
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
Dynamic Multilevel Indexes Using B-Trees and B+-
2.3
70 Trees
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees
 Most multi-level indexes use B-tree or B+-tree data
structures because of the insertion and deletion
problem.
 This leaves space in each tree node (disk block) to allow for
new index entries
 These data structures are variations of search trees
that allow efficient insertion and deletion of new
search values.
 In B-Tree and B+-Tree data structures, each node
corresponds to a disk block.
 Each node is kept between half-full and completely full.

71
Dynamic Multilevel Indexes Using B-
Trees and B+-Trees (cont.)
 An insertion into a node that is not full is quite
efficient.
 If a node is full, the insertion causes a split into two
nodes.
 Splitting may propagate to other tree levels.
 A deletion is quite efficient if a node does not
become less than half full.
 If a deletion causes a node to become less than half
full, it must be merged with neighboring nodes.

72
Difference between B-tree and B+-tree
 In a B-Tree, pointers to data records exist at all levels of
the tree.
 In a B+-Tree, all pointers to data records exist at the
leaf-level nodes.
 A B+-Tree can have less levels (or higher capacity of
search values) than the corresponding B-tree.

73
B-tree Structures

74
The Nodes of a B+-Tree

75
Contents
1 Data Storage
1.1 Disk Storage Devices
1.2 Files of Records
1.3 Operations on Files
1.4 Unordered Files & Ordered Files & Hashed Files
1.5 RAID Technology and Storage Area Networks
2 Indexing Structures for Files
2.1 Types of Single-level Ordered Indexes
2.2 Multilevel Indexes
2.3 Dynamic Multilevel Indexes Using B-Trees and B+-Trees
76
77
Exercise
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.
1. Calculate the record size R in bytes.
2. Calculate the blocking factor bfr and the number of
file blocks b, assuming an unspanned organization.

78
Exercise (cont.)
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.

3. This file is ordered by the key field SSN. Calculate the


number of block accesses needed to search for and
retrieve a record from the file - given its SSN value.

79
Exercise (cont.)
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.

4. This file is ordered by the key field SSN and we want


to construct a primary index on SSN. Calculate:
a) the index blocking factor bfri
b) the number of index entries and the number of
index blocks
80
Exercise (cont.)
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.

4. This file is ordered by the key field SSN and we want


to construct a primary index on SSN. Calculate:
c) the number of block accesses needed to search
for and retrieve a record from the file - given its
SSN value
81
Exercise (cont.)
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.
5. If we make it into a multilevel index .
a) Calculate the total number of blocks required by
the second index
b) the number of block accesses needed to search
for and retrieve a record from the file - given its
SSN value
86
Exercise (cont.)
 A file has r = 30,000 EMPLOYEE records of fixed length.
 Each record has the following fields: Name (30 bytes),
SSN (9 bytes), Department_code (9 bytes), Address (40
bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1
byte), Job_code (4 bytes), and Salary (4 bytes). An
additional byte is used as a deletion marker.
 Block size B = 512 bytes, block pointer P = 6 bytes, record
pointer PR = 7 bytes.
6. If we make it into a multilevel index.
a) the number of block accesses needed to search
for and retrieve a record from the file - given its
SSN value

88

You might also like