Dbms 5th Unit
Dbms 5th Unit
Magnetic disk
Data is stored on spinning disk, and read/written magnetically
Primary medium for the long term storage of data; typically stores entire database.
Data must be moved from disk to main memory for access, and written back for storage
directaccess
possible to read data on disk in any order, unlike magnetic tape
Storage Hierarchy
primary storage: Fastest media but volatile (cache, main memory).
secondary storage: next level in hierarchy, nonvolatile, moderately fast access time
also called online storage
E.g. flash memory, magnetic disks
tertiary storage: lowest level in hierarchy, nonvolatile, slow access time
also called offline storage
E.g. magnetic tape, optical storage
Storage Hierarchy
NOTE: Diagram is schematic, and simplifies the structure of actual disk drives
Magnetic Disks
Readwrite head
Positioned very close to the platter surface (almost touching it)
Reads or writes magnetically encoded information.
Surface of platter divided into circular tracks
Over 50K100K tracks per platter on typical hard disks
Each track is divided into sectors.
Sector size typically 512 bytes
Typical sectors per track: 500 (on inner tracks) to 1000 (on outer tracks)
To read/write a sector
disk arm swings to position head on right track
platter spins continually; data is read/written as sector passes under head
Headdisk assemblies
multiple disk platters on a single spindle (1 to 5 usually)
one head per platter, mounted on a common arm.
Cylinder i consists of i track of all the platters
Earlier generation disks were susceptible to head crashes leading to loss of all
data on disk
Current generation disks are less susceptible to such disastrous failures, but
individual sectors may get corrupted
th
Disk Controller
Disk controller interfaces between the computer system and the disk drive hardware.
accepts highlevel commands to read or write a sector
initiates actions such as moving the disk arm to the right track and actually
reading or writing the data
Computes and attaches checksums to each sector to verify that data is read back
correctly
If data is corrupted, with very high probability stored checksum wont
match recomputed checksum
Ensures successful writing by reading back sector after writing it
Performs remapping of bad sectors
Disk Subsystem
RAID
RAID: Redundant Arrays of Independent Disks
disk organization techniques that manage a large numbers of disks, providing a view of
a single disk of
high capacity and high speed by using multiple disks in parallel, and
high reliability by storing data redundantly, so that data can be recovered even
if a disk fails
The chance that some disk out of a set of N disks will fail is much higher than the
chance that a specific single disk will fail.
E.g., a system with 100 disks, each with MTTF of 100,000 hours (approx. 11 years),
will have a system MTTF of 1000 hours (approx. 41 days)
RAID Levels
RAID organizations, or RAID levels, have differing cost, performance and reliability
characteristics
RAID Level 0: Block striping; nonredundant.
Used in high performance applications where data lost is not critical.
RAID Level 1: Mirrored disks with block striping
Offers best write performance.
Popular for applications such as storing log files in a database system.
RAID Level 2: MemoryStyle ErrorCorrectingCodes (ECC) with bit striping.
RAID Level 3: BitInterleaved Parity
a single parity bit is enough for error correction, not just detection
When writing data, corresponding parity bits must also be computed
and written to a parity bit disk
To recover data in a damaged disk, compute XOR of bits from other
disks (including parity bit disk) n RAID Level 3 (Cont.)
Faster data transfer than with a single disk, but fewer I/Os per second since
every disk has to participate in every I/O.
RAID Level 4: Block Interleaved Parity; uses blocklevel striping, and keeps a parity
block on a separate disk for corresponding blocks from N other disks.
When writing data block, corresponding block of parity bits must also be
computed and written to parity disk
disk drive capacities increasing rapidly (50%/year) whereas disk access times
have decreased much less (x 3 in 10 years)
I/O requirements have increased greatly, e.g. for Web servers
When enough disks have been bought to satisfy required rate of I/ O, they often
have spare storage capacity so there is often no extra monetary cost for Level 1!
Level 5 is preferred for applications with low update rate, and large amounts of data
Level 1 is preferred for all other applications
Hardware Issues
Software RAID: RAID implementations done entirely in software, with no special
hardware support
Hardware RAID: RAID implementations with special hardware
Use nonvolatile RAM to record writes that are being executed
Beware: power failure during write can result in corrupted disk
E.g. failure after writing one block but before writing the second in a
mirrored system
Such corrupted data must be detected when power is restored
Recovery from corruption is similar to recovery from failed
disk
NVRAM helps to efficiently detected potentially corrupted
blocks
Otherwise all blocks of disk must be read and compared with
mirror/parity block
Hot swapping: replacement of disk while system is running, without power down
Supported by some hardware RAID systems,
reduces time to recovery, and improves availability greatly
Many systems maintain spare disks which are kept online, and used as replacements for
failed disks immediately on detection of failure
Reduces time to recovery greatly
Many hardware RAID systems ensure that a single point of failure will not stop the
functioning of the system by using
Redundant power supplies with battery backup
Multiple controllers and multiple interconnections to guard against
controller/interconnection failures
Optical Disks
Compact diskread only memory (CDROM)
Seek time about 100 msec (optical read head is heavier and slower)
Higher latency (3000 RPM) and lower data transfer rates (36 MB/s) compared
to magnetic disks
Digital Video Disk (DVD)
DVD5 holds 4.7 GB , variants up to 17 GB
Slow seek time, for same reasons as CDROM
Record once versions (CDR and DVDR)
Magnetic Tapes
Hold large volumes of data and provide high transfer rates
Few GB for DAT (Digital Audio Tape) format, 1040 GB with DLT (Digital
Linear Tape) format, 100 400 GB+ with Ultrium format, and 330 GB with Ampex
helical scan format
Transfer rates from few to 10s of MB/s
Currently the cheapest storage medium
Tapes are cheap, but cost of drives is very high
Very slow access time in comparison to magnetic disks and optical disks
limited to sequential access.
Some formats (Accelis) provide faster seek (10s of seconds) at cost of lower
capacity
Used mainly for backup, for storage of infrequently used information, and as an offline
medium for transferring information from one system to another.
Tape jukeboxes used for very large capacity storage
(terabyte (10 bytes) to petabye (10 bytes)
12
15
Storage Access
A database file is partitioned into fixed length storage units called blocks. Blocks are
units of both storage allocation and data transfer.
Database system seeks to minimize the number of block transfers between the disk and
memory. We can reduce the number of disk accesses by keeping as many blocks as possible in
main memory.
Buffer portion of main memory available to store copies of disk blocks.
Buffer manager subsystem responsible for allocating buffer space in main memory.
File Organization
The database is stored as a collection of files. Each file is a sequence of records. A
record is a sequence of fields.
One approach:
assume record size is fixed
each file has records of one particular type only
different files are used for different relations
This case is easiest to implement; will consider variable length records later.
Free Lists
Store the address of the first deleted record in the file header.
Use this first record to store the address of the second deleted record, and so on
Can think of these stored addresses as pointers since they point to the location of a
record.
More space efficient representation: reuse space for normal attributes of free records to
store pointers. (No pointers stored in inuse records.)
Ordered Indices
In an ordered index, index entries are stored sorted on the search key value. E.g.,
author catalog in library.
Primary index: in a sequentially ordered file, the index whose search key specifies the
sequential order of the file.
Also called clustering index
The search key of a primary index is usually but not necessarily the primary
key.
Secondary index: an index whose search key specifies an order different from the
sequential order of the file. Also called nonclustering index.
Indexsequential file: ordered sequential file with a primary index.
Multilevel Index
If primary index does not fit in memory, access becomes expensive.
Solution: treat primary index kept on disk as a sequential file and construct a sparse
index on it.
outer index a sparse index of primary index
inner index the primary index file
If even outer index is too large to fit in main memory, yet another level of index can be
created, and so on.
Indices at all levels must be updated on insertion or deletion from the file.
n Disadvantage
of indexedsequential
files
l performance degrades as file grows, since many overflow
blocks get created.
l Periodic reorganization of entire file is required.
n Advantage of B tree
index files:
l automatically reorganizes itself with small, local, changes,
in the face of insertions and deletions.
l Reorganization of entire file is not required to maintain
performance.
n (Minor) disadvantage of B trees:
l extra insertion and deletion overhead, space overhead.
n Advantages of B trees
outweigh disadvantages
l B trees
are used extensively
+
Typical node
n1
NonLeaf
Nodes in B+Trees
Non leaf nodes form a multilevel
sparse index on the leaf
nodes. For a nonleaf
node with m pointers:
l All the searchkeys
in the subtree to which P points are
less than K
l For 2 i n
1, all the searchkeys
in the subtree to
which P points have values greater than or equal to K
1
i1
n1
Example of a B+tree
B tree
for account file (n = 3)
+
Example of B+tree
n Leaf
B tree
for account file (n = 5)
+
the internode
connections are done by pointers,
logically close blocks need not be physically close.
n The nonleaf
levels of the B tree
form a hierarchy of sparse
indices.
n The B tree
contains a relatively small number of levels
+
n/2
Queries on B+Trees
Find all records with a searchkey
value of k.
H N=root
H Repeat
4 Examine N for the smallest searchkey
value > k.
4 If such a value exists, assume it is K . Then set N = P
4 Otherwise k K . Set N = P
Until N is a leaf node
H If for some i, key K = k follow pointer P to the desired record or bucket.
H Else no record with searchkey
value k exists.
i
n1
50
Updates on B+Trees:
Insertion
1. Find
the n (searchkey
value, pointer) pairs (including the one
being inserted) in sorted order. Place the first n/2 in the original
node, and the rest in a new node.
l let the new node be p, and let k be the least key value in p. Insert
(k,p) in the parent of the node being split.
l If the parent is full, split it and propagate the split further up.
n Splitting of nodes proceeds upwards till a node that is not full is found.
l In the worst case the root node may be split increasing the height
of the tree by 1.
B Tree
before and after insertion of Clearview
+
Splitting a nonleaf
node: when inserting (k,p) into an already
full internal node N
l Copy N to an inmemory
area M with space for n+1
pointers and n keys
l Insert (k,p) into M
l Copy P ,K , , K
,P from M back into node N
l Copy P
,K ,,K ,P from M into newly
allocated node N
l Insert (K
,N) into parent N
1
n/2 1
n/2
n/2 +1
n/2 +1
n+1
n/2
Updates on B+Trees:
Deletion
n Find
entries.
l Update the corresponding searchkey
value in the parent of
the node.
n The node deletions may cascade upwards till a node which has
n/2 or more pointers is found.
n If the root node has only one pointer after deletion, it is deleted
and the sole child becomes the root.
Examples of B+Tree
Deletion
B+Tree
File Organization
n Index
Example of B tree
File Organization
+
Good space utilization important since records use more space than
pointers.
n To improve space utilization, involve more sibling nodes in
redistribution during splits and merges
l Involving 2 siblings in redistribution (to avoid split / merge where
possible) results in each node having at least 2n / 3entries
Indexing Strings
n Variable
BTree
Index Files
n Similar
to B+tree,
but Btree
allows searchkey
values
to appear only once; eliminates redundant storage of
search keys.
n Search keys in nonleaf nodes appear nowhere else in
the Btree;
an additional pointer field for each search
key in a nonleaf node must be included.
n Generalized Btree
leaf node
pointers.
Btree
(above) and B+tree
(below) on same data
BTree
Index Files (Cont.)
n Advantages
of BTree
indices:
l May use less tree nodes than a corresponding B Tree.
l Sometimes possible to find searchkey
value before reaching
leaf node.
n Disadvantages of BTree
indices:
l Only small fraction of all searchkey
values are found early
l Nonleaf
nodes are larger, so fanout
is reduced. Thus, BTrees
typically have greater depth than corresponding B Tree
l Insertion and deletion more complicated than in B Trees
+
l Implementation