



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























Disk Storage, Basic File Structures, and
Hashing. Copyright © 2004 Pearson Education, Inc.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
z
The division of a track into
sectors
is hard-coded on
the disk surface and cannot be changed. One type ofsector organization calls a portion of a track thatsubtends a fixed angle at the center as a sector. z
A track is divided into
blocks
. The block size B is
fixed for each system. Typical block sizes range fromB=512 bytes to B=4096 bytes. Whole blocks aretransferred between disk and main memory forprocessing.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
z^
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. z^
A physical disk block (hardware) address consists of a cylindernumber (imaginery collection of tracks of same radius from allrecoreded surfaces), the track number or surface number (withinthe cylinder), and block number (within track). z^
Reading or writing a disk block is time consuming because of theseek time s and rotational delay (latency)
rd
.
z^
Double buffering can be used to speed up the transfer ofcontiguous disk blocks.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z
Fixed and variable length records z
Records contain fields which have values of a particulartype (e.g., amount, date, time, age) z
Fields themselves may be fixed length or variable length z
Variable length fields can be mixed into one record:separator characters or length fields are needed so that therecord can be “parsed”.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z
Blocking: refers to storing a number of records in one block on the disk. z
Blocking factor (
bfr
) refers to the number of records per
block. z
There may be empty space in a block if an integralnumber of records do not fit in one block. z
Spanned Records
: refer to records that exceed the size of
one or more blocks and hence span a number of blocks.
Chapter 13-
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z
File records can be
unspanned
(no record can span two
blocks) or
spanned
(a record can be stored in more than
one block). z
The physical disk blocks that are allocated to hold therecords of a file can be
contiguous
,^ linked
, or
indexed
z
In a file of fixed-length records, all records have thesame format. Usually, unspanned blocking is used withsuch files. z
Files of variable-length records require additionalinformation to be stored in each record, such as separator characters
and
field types
. Usually spanned
blocking is used with such files.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Typical file operations include: z
Readies the file for access, and associates a
pointer that will refer to a
current
file record at each
point in time. z
Searches for the first file record that satisfies a
certain condition, and makes it the current file record. z
Searches for the next file record (from
the current record) that satisfies a certain condition, andmakes it the current file record. z
Reads the current file record into a program
variable. z
Inserts a new record into the file, and makes
it the current file record.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z
Also called a
heap
or a
pile
file.
z
New records are inserted at the end of the file. z
To search for a record, a
linear search
through the file
records is necessary. This requires reading andsearching half the file blocks on the average, and ishence quite expensive. z
Record insertion is quite efficient. z
Reading the records in order of a particular fieldrequires sorting the file records.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z
Also called a
sequential file
z
File records are kept sorted by the values of an
ordering
field
z
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 mergedwith the main ordered file. z
binary search
can be used to search for a record on its
ordering field value
. This requires reading and searching
log
of the file blocks on the average, an improvement 2 over linear search. z
Reading the records in order of the ordering field is quiteefficient.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
The following table shows the average access time to
access a specific record for a given type of file
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
z^
Hashing for disk files is called
External Hashing
z^
The file blocks are divided into M equal-sized
buckets
, numbered
bucket
, bucket 0
, ..., bucket 1
M-
. Typically, a bucket corresponds to
one (or a fixed number of) disk block. z^
One of the file fields is designated to be the hash key of the file. z^
The record with hash key value K is stored in bucket i, wherei=h(K), and h is the
hashing function
.
z^
Search is very efficient on the hash key. z^
Collisions occur when a new record hashes to a bucket that isalready full. An overflow file is kept for storing such records.Overflow records that hash to each bucket can be linked together.