Rdbms (Unit 1)

download Rdbms (Unit 1)

of 41

Transcript of Rdbms (Unit 1)

  • 8/14/2019 Rdbms (Unit 1)

    1/41

    Unit 1: Storage and File StructureUnit 1: Storage and File Structure

  • 8/14/2019 Rdbms (Unit 1)

    2/41

    2Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Unit 1 : Storage and File StructureUnit 1 : Storage and File Structure

    s Overview of Physical Storage Media

    s Magnetic Disks

    s RAID (Redundant arrays of independent disks)

    s File Organization

    s Organization of Records in Files

    s Data-Dictionary Storage

  • 8/14/2019 Rdbms (Unit 1)

    3/41

    3Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Classification of Physical Storage MediaClassification of Physical Storage Media

    s Speed with which data can be accessed

    s Cost per unit of data

    s Reliability

    q data loss on power failure or system crash

    q physical failure of the storage device

    s Can differentiate storage into:

    q volatile storage: loses contents when power is switched off

    q non-volatile storage:

    Contents persist even when power is switched off.

    Includes secondary and tertiary storage, as well as batter-backed up main-memory.

  • 8/14/2019 Rdbms (Unit 1)

    4/41

    4Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Physical Storage MediaPhysical Storage Media

    s Cache fastest and most costly form of storage; volatile;managed by the computer system hardware.

    s Main memory:

    q fast access (10 to 100 of nanoseconds; 1 nanosecond = 109

    seconds)

    q

    generally too small (or too expensive) to store the entiredatabase

    capacities of up to a few Gigabytes widely used currently

    q Volatile contents of main memory are usually lost if a powerfailure or system crash occurs.

  • 8/14/2019 Rdbms (Unit 1)

    5/41

    5Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Physical Storage Media (Cont.)Physical Storage Media (Cont.)

    s Flash memory

    q Data survives power failure

    q Data can be written at a location only once, but location can beerased and written to again

    Can support only a limited number (10,000 to 1 million) ofwrite/erase cycles.

    Erasing of memory has to be done to an entire bank ofmemory

    q Reads are almost as fast as main memory

    q But writes are slow (few microseconds), erase is slower

    q

    Cost per unit of storage almost similar to main memoryq Widely used in embedded devices such as digital cameras

    q Is a type of EEPROM (Electrically Erasable ProgrammableRead-Only Memory)

  • 8/14/2019 Rdbms (Unit 1)

    6/41

    6Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Physical Storage Media (Cont.)Physical Storage Media (Cont.)

    s Magnetic-disk

    q Data is stored on spinning disk, and read/written magnetically

    q Primary medium for the long-term storage of data; typically stores entiredatabase.

    q Data must be moved from disk to main memory for access, and writtenback for storage

    Much slower access than main memory (more on this later)

    q direct-access possible to read data on disk in any order, unlikemagnetic tape

    q Capacities range up to almost 400 GB currently

    Much larger capacity and cost/byte than main memory/flash memory

    Growing constantly and rapidly with technology improvements.q Survives power failures and system crashes

    disk failure can destroy data, but is rare

  • 8/14/2019 Rdbms (Unit 1)

    7/417Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Physical Storage Media (Cont.)Physical Storage Media (Cont.)

    s Optical storage

    q non-volatile, data is read optically from a spinning disk usinga laser

    q CD-ROM (640 MB) and DVD (4.7 to 17 GB) most popularforms

    q Write-one, read-many (WORM) optical disks used for archival

    storage (CD-R, DVD-R, DVD+R)

    q Multiple write versions also available (CD-RW, DVD-RW,DVD+RW, and DVD-RAM)

    q Reads and writes are slower than with magnetic disk

  • 8/14/2019 Rdbms (Unit 1)

    8/418Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Physical Storage Media (Cont.)Physical Storage Media (Cont.)

    s Tape storage

    q non-volatile, used primarily for backup (to recover from diskfailure), and for archival data

    q sequential-access much slower than disk

    q very high capacity (40 to 300 GB tapes available)

    q tape can be removed from drive storage costs muchcheaper than disk, but drives are expensive

    q Tape jukeboxes available for storing massive amounts of data

    hundreds of terabytes (1 terabyte = 109 bytes) to even a

    petabyte (1 petabyte = 1012 bytes)

  • 8/14/2019 Rdbms (Unit 1)

    9/419Shrimad Rajchandra Institute of Management & Computer Application

    Storage HierarchyStorage Hierarchy

  • 8/14/2019 Rdbms (Unit 1)

    10/4110Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Storage Hierarchy (Cont.)Storage Hierarchy (Cont.)

    s primary storage: Fastest media but volatile (cache,

    main memory).

    s secondary storage: next level in hierarchy, non-volatile, moderately fast access time

    q also called on-line storage

    q E.g. flash memory, magnetic disks

    s tertiary storage: lowest level in hierarchy, non-volatile, slow access time

    q also called off-line storage

    q E.g. magnetic tape, optical storage

  • 8/14/2019 Rdbms (Unit 1)

    11/4111Shrimad Rajchandra Institute of Management & Computer Application

    Magnetic Hard Disk MechanismMagnetic Hard Disk Mechanism

    NOTE: Diagram is schematic, and simplifies the structure of actual disk drives

  • 8/14/2019 Rdbms (Unit 1)

    12/4112Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Magnetic DisksMagnetic Disks

    s Read-write head

    q Positioned very close to the platter surface (almost touching it)q Reads or writes magnetically encoded information.

    s Surface of platter divided into circular tracks

    q Over 50K-100K tracks per platter on typical hard disks

    s Each track is divided into sectors.

    q A sector is the smallest unit of data that can be read or written.

    q Sector size typically 512 bytes

    q Typical sectors per track: 500 (on inner tracks) to 1000 (on outer tracks)

    s To read/write a sector

    q disk arm swings to position head on right track

    q platter spins continually; data is read/written as sector passes under head

    s Head-disk assemblies

    q multiple disk platters on a single spindle (1 to 5 usually)

    q one head per platter, mounted on a common arm.

    s Cylinder iconsists ofith track of all the platters

  • 8/14/2019 Rdbms (Unit 1)

    13/4113Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Magnetic Disks (Cont.)Magnetic Disks (Cont.)

    s Earlier generation disks were susceptible to head-crashes

    q Surface of earlier generation disks had metal-oxide coatings whichwould disintegrate on head crash and damage all data on disk

    q Current generation disks are less susceptible to such disastrousfailures, although individual sectors may get corrupted

    s Disk controller interfaces between the computer systemand the disk drive hardware.

    q accepts high-level commands to read or write a sectorq initiates actions such as moving the disk arm to the right track and

    actually reading or writing the data

    q Computes and attaches checksums to each sector to verify thatdata is read back correctly

    If data is corrupted, with very high probability stored checksum

    wont match recomputed checksumq Ensures successful writing by reading back sector after writing it

    q Performs remapping of bad sectors

  • 8/14/2019 Rdbms (Unit 1)

    14/4114Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Performance Measures of DisksPerformance Measures of Disks

    s Access time the time it takes from when a read or write request isissued to when data transfer begins. Consists of:

    q Seek time time it takes to reposition the arm over the correct track.

    Average seek time is 1/2 the worst case seek time.

    Would be 1/3 if all tracks had the same number of sectors, and weignore the time to start and stop arm movement

    4 to 10 milliseconds on typical disks

    q Rotational latency time it takes for the sector to be accessed to appearunder the head.

    Average latency is 1/2 of the worst case latency.

    4 to 11 milliseconds on typical disks (5400 to 15000 r.p.m.)

    s Data-transfer rate the rate at which data can be retrieved fromor stored to the disk.

    q 25 to 100 MB per second max rate, lower for inner tracks

    q Multiple disks may share a controller, so rate that controller can handle isalso important

    E.g. ATA-5: 66 MB/sec, SATA: 150 MB/sec, Ultra 320 SCSI: 320 MB/s

    Fiber Channel (FC2Gb): 256 MB/s

  • 8/14/2019 Rdbms (Unit 1)

    15/4115Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Performance Measures (Cont.)Performance Measures (Cont.)

    s Mean time to failure (MTTF) the average time the diskis expected to run continuously without any failure.

    q Typically 3 to 5 years

    q Probability of failure of new disks is quite low, corresponding to atheoretical MTTF of 500,000 to 1,200,000 hours for a new disk

    E.g., an MTTF of 1,200,000 hours for a new disk means thatgiven 1000 relatively new disks, on an average one will failevery 1200 hours

    q MTTF decreases as disk ages

  • 8/14/2019 Rdbms (Unit 1)

    16/4116Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Optimization of Disk-Block AccessOptimization of Disk-Block Access

    s Block a contiguous sequence of sectors from a single track

    q data is transferred between disk and main memory in blocks

    q sizes range from 512 bytes to several kilobytes

    Smaller blocks: more transfers from disk

    Larger blocks: more space wasted due to partially filled blocks

    Typical block sizes today range from 4 to 16 kilobytess Disk-arm-scheduling algorithms order pending accesses to

    tracks so that disk arm movement is minimized

    q elevator algorithm: move disk arm in one direction (from outer toinner tracks or vice versa), processing next request in that

    direction, till no more requests in that direction, then reversedirection and repeat

  • 8/14/2019 Rdbms (Unit 1)

    17/4117Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Optimization of Disk Block Access (Cont.)Optimization of Disk Block Access (Cont.)

    s File organization optimize block access time by

    organizing the blocks to correspond to how data will beaccessed

    q E.g. Store related information on the same or nearby cylinders.

    q Files may get fragmented over time

    E.g. if data is inserted to/deleted from the file

    Or free blocks on disk are scattered, and newly created filehas its blocks scattered over the disk

    Sequential access to a fragmented file results in increaseddisk arm movement

    q Some systems have utilities to defragment the file system, in

    order to speed up file access

  • 8/14/2019 Rdbms (Unit 1)

    18/4118Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAIDRAID

    s RAID: Redundant Arrays of Independent Disks

    q 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 berecovered even if a disk fails

    s The chance that some disk out of a set ofNdisks will fail is muchhigher than the chance that a specific single disk will fail.

    q E.g., a system with 100 disks, each with MTTF(the average timethe disk is expected to run continuously without any failure)of 100,000 hours (approx. 11 years), will have a system MTTF of1000 hours (approx. 41 days)

    q Techniques for using redundancy to avoid data loss are critical with

    large numbers of disks

  • 8/14/2019 Rdbms (Unit 1)

    19/4119Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Improvement of Reliability via RedundancyImprovement of Reliability via Redundancy

    s Redundancy store extra information that can be used to

    rebuild information lost in a disk failures E.g., Mirroring(or shadowing)

    q Duplicate every disk. Logical disk consists of two physical disks.

    q Every write is carried out on both disks

    Reads can take place from either disk

    q If one disk in a pair fails, data still available in the other

    Data loss would occur only if a disk fails, and its mirror disk alsofails before the system is repaired

    Probability of combined event is very small

    Except for dependent failure modes such as fire or buildingcollapse or electrical power surges

    s

    Mean time to data loss depends on mean time to failure,and mean time to repair

  • 8/14/2019 Rdbms (Unit 1)

    20/4120Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Improvement in Performance via ParallelismImprovement in Performance via Parallelism

    s Two main goals of parallelism in a disk system:

    1. Load balance multiple small accesses to increase throughput

    2. Parallelize large accesses to reduce response time.

    s Improve transfer rate by striping data across multiple disks.

    s Bit-level striping split the bits of each byte across multiple disks

    q In an array of eight disks, write bit iof each byte to disk i.

    q Each access can read data at eight times the rate of a single disk.

    q But seek/access time worse than for a single disk

    Bit level striping is not used much any more

    s Block-level striping with n disks, block iof a file goes to disk (imod n) + 1

    q Requests for different blocks can run in parallel if the blocks reside ondifferent disks

    q A request for a long sequence of blocks can utilize all disks in parallel

  • 8/14/2019 Rdbms (Unit 1)

    21/4121Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID LevelsRAID Levels

    s Schemes to provide redundancy at lower cost by using disk

    striping combined with parity bitsq Different RAID organizations, or RAID levels, have differing cost,

    performance and reliability characteristics

    s RAID Level 1: Mirrored disks with block striping

    q Offers best write performance.

    q Popular for applications such as storing log files in a database system.

    s RAID Level 0: Block striping; non-redundant.

    q Used in high-performance applications where data lose is not critical.

  • 8/14/2019 Rdbms (Unit 1)

    22/4122Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID Levels (Cont.)RAID Levels (Cont.)

    s RAID Level 2: Memory-Style Error-Correcting-Codes (ECC) with

    bit striping.s RAID Level 3: Bit-Interleaved Parity

    q a single parity bit is enough for error correction, not just detection, sincewe know which disk has failed

    When writing data, corresponding parity bits must also be computedand written to a parity bit disk

    To recover data in a damaged disk, compute XOR of bits from otherdisks (including parity bit disk)

  • 8/14/2019 Rdbms (Unit 1)

    23/4123Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID Levels (Cont.)RAID Levels (Cont.)

    s RAID Level 3 (Cont.)

    q Faster data transfer than with a single disk, but fewer I/Os per secondsince every disk has to participate in every I/O.

    q Subsumes Level 2 (provides all its benefits, at lower cost).

    s RAID Level 4: Block-Interleaved Parity; uses block-level striping,and keeps a parity block on a separate disk for correspondingblocks from Nother disks.

    q When writing data block, corresponding block of parity bits must also becomputed and written to parity disk

    q To find value of a damaged block, compute XOR of bits fromcorresponding blocks (including parity block) from other disks.

  • 8/14/2019 Rdbms (Unit 1)

    24/41

    24Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID Levels (Cont.)RAID Levels (Cont.)

    s RAID Level 4 (Cont.)

    q Provides higher I/O rates for independent block reads than Level 3 block read goes to a single disk, so blocks stored on different

    disks can be read in parallel

    q Provides high transfer rates for reads of multiple blocks than no-striping

    q Before writing a block, parity data must be computed

    Can be done by using old parity block, old value of current blockand new value of current block (2 block reads + 2 block writes)

    Or by recomputing the parity value using the new values of blockscorresponding to the parity block

    More efficient for writing large amounts of data sequentially

    q Parity block becomes a bottleneck for independent block writes sinceevery block write also writes to parity disk

  • 8/14/2019 Rdbms (Unit 1)

    25/41

    25Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID Levels (Cont.)RAID Levels (Cont.)

    s RAID Level 5: Block-Interleaved Distributed Parity; partitions data

    and parity among all N+ 1 disks, rather than storing data in Ndisksand parity in 1 disk.

    q E.g., with 5 disks, parity block for nth set of blocks is stored on disk (nmod5) + 1, with the data blocks stored on the other 4 disks.

  • 8/14/2019 Rdbms (Unit 1)

    26/41

    26Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    RAID Levels (Cont.)RAID Levels (Cont.)

    s RAID Level 5 (Cont.)

    q Higher I/O rates than Level 4.

    Block writes occur in parallel if the blocks and their parityblocks are on different disks.

    q Subsumes Level 4: provides same benefits, but avoids bottleneckof parity disk.

    s RAID Level 6: P+Q Redundancy scheme; similar to Level 5,but stores extra redundant information to guard againstmultiple disk failures. (Reed-Solomon Algorithm)

    q Better reliability than Level 5 at a higher cost; not used as widely.

  • 8/14/2019 Rdbms (Unit 1)

    27/41

    27Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Choice of RAID LevelChoice of RAID Level

    s Factors in choosing RAID level

    q

    Monetary costq Performance: Number of I/O operations per second, and bandwidth

    during normal operation

    q Performance during failure

    q Performance during rebuild of failed disk

    Including time taken to rebuild failed disk

    s RAID 0 is used only when data safety is not important

    q E.g. data can be recovered quickly from other sources

    s Level 2 and 4 never used since they are subsumed by 3 and 5

    s Level 3 is not used anymore since bit-striping forces single blockreads to access all disks, wasting disk arm movement, whichblock striping (level 5) avoids

    s Level 6 is rarely used since levels 1 and 5 offer adequate safetyfor almost all applications

    s So competition is between 1 and 5 only

  • 8/14/2019 Rdbms (Unit 1)

    28/41

    28Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Choice of RAID Level (Cont.)Choice of RAID Level (Cont.)

    s Level 1 provides much better write performance than level 5

    q Level 5 requires at least 2 block reads and 2 block writes to write a singleblock, whereas Level 1 only requires 2 block writes

    q Level 1 preferred for high update environments such as log disks

    s Level 1 had higher storage cost than level 5

    q disk drive capacities increasing rapidly (50%/year) whereas disk accesstimes have decreased much less (x 3 in 10 years)

    q I/O requirements have increased greatly, e.g. for Web servers

    q When enough disks have been bought to satisfy required rate of I/O, theyoften have spare storage capacity

    so there is often no extra monetary cost for Level 1!

    s Level 5 is preferred for applications with low update rate,

    and large amounts of data

    s Level 1 is preferred for all other applications

  • 8/14/2019 Rdbms (Unit 1)

    29/41

    29Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    File OrganizationFile Organization

    s The database is stored as a collection offiles. Each file is

    a sequence ofrecords. A record is a sequence of fields.

    s In a relational database ,tuples of distinct relation aregenerally of different sizes.

    s Two approach to mapping the database to files andstored records in files.

    q Fixed-Length Records

    q Variable Length Records

  • 8/14/2019 Rdbms (Unit 1)

    30/41

    30Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Fixed-Length RecordsFixed-Length Records

    s Simple approach:

    q Store record istarting from byte n (i 1), where nis the size ofeach record.

    q Record access is simple but records may cross blocks

    Modification: do not allow records to cross block boundaries

    s Deletion of record i:alternatives:

    q move records i+ 1, . . ., nto i, . . . , n 1

    q

    move record n to iq do not move records, but

    link all free records on afree list

  • 8/14/2019 Rdbms (Unit 1)

    31/41

    31Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Free ListsFree Lists

    s Store the address of the first deleted record in the file header.

    s Use this first record to store the address of the second deletedrecord, and so on

    s Can think of these stored addresses as pointerssince theypoint to the location of a record.

    s More space efficient representation: reuse space for normal

    attributes of free records to store pointers. (No pointersstored in in-use records.)

  • 8/14/2019 Rdbms (Unit 1)

    32/41

    32Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Variable-Length RecordsVariable-Length Records

    s Variable-length records arise in database systems in

    several ways:

    q Storage of multiple record types in a file.

    q Record types that allow variable lengths for one or morefields.

    q Record types that allow repeating fields (used in someolder data models).

  • 8/14/2019 Rdbms (Unit 1)

    33/41

    33Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Variable-Length Records: Slotted Page StructureVariable-Length Records: Slotted Page Structure

    s Slotted page header contains:q number of record entries

    q end of free space in the block

    q location and size of each record

    s

    Records can be moved around within a page to keep themcontiguous with no empty space between them; entry in theheader must be updated.

    s Pointers should not point directly to record instead theyshould point to the entry for the record in header.

  • 8/14/2019 Rdbms (Unit 1)

    34/41

    34Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Organization of Records in FilesOrganization of Records in Files

    s Heap a record can be placed anywhere in the file

    where there is space

    s Sequential store records in sequential order, basedon the value of the search key of each record

    s Hashing a hash function computed on someattribute of each record; the result specifies in which

    block of the file the record should be placeds Records of each relation may be stored in a separate

    file. In a multitable clustering file organizationrecords of several different relations can be stored inthe same file

    q Motivation: store related records on the same block tominimize I/O

  • 8/14/2019 Rdbms (Unit 1)

    35/41

    35Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Sequential File OrganizationSequential File Organization

    s Suitable for applications that require sequential

    processing of the entire files The records in the file are ordered by a search-key

  • 8/14/2019 Rdbms (Unit 1)

    36/41

    36Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Sequential File Organization (Cont.)Sequential File Organization (Cont.)

    s Deletion use pointer chains

    s Insertion locate the position where the record is to be insertedq if there is free space insert there

    q if no free space, insert the record in an overflow block

    q In either case, pointer chain must be updated

    s

    Need to reorganize the filefrom time to time to restoresequential order

  • 8/14/2019 Rdbms (Unit 1)

    37/41

    37Shrimad Rajchandra Institute of Management & Computer Application

    Multitable Clustering File OrganizationMultitable Clustering File Organization

    Store several relations in one file using a multitable clustering

    file organization

  • 8/14/2019 Rdbms (Unit 1)

    38/41

    38Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Multitable Clustering File Organization (cont.)Multitable Clustering File Organization (cont.)

    Multitable clustering organization ofcustomerand depositor:

    q

    good for queries involving depositor customer, and for queriesinvolving one single customer and his accounts

    q bad for queries involving only customer

    q results in variable size records

    q Can add pointer chains to link records of a particular relation

    D Di i S

  • 8/14/2019 Rdbms (Unit 1)

    39/41

    39Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Data Dictionary StorageData Dictionary Storage

    s Information about relations

    q names of relations

    q names and types of attributes of each relation

    q names and definitions of views

    q integrity constraints

    s User and accounting information, including passwords

    s Statistical and descriptive data

    q number of tuples in each relation

    s Physical file organization information

    q How relation is stored (sequential/hash/)

    q Physical location of relation

    s Information about indices (Chapter 12)

    Data dictionary (also called system catalog) stores metadata;

    that is, data about data, such as

    D Di i S (C )

  • 8/14/2019 Rdbms (Unit 1)

    40/41

    40Shrimad Ra chandra Institute of Mana ement & Com uter A lication

    Data Dictionary Storage (Cont.)Data Dictionary Storage (Cont.)

    s Catalog structure

    q Relational representation on diskq specialized data structures designed for efficient access, in

    memory

    s A possible catalog representation:

    Relation_metadata = (relation_name, number_of_attributes,storage_organization, location)

    Attribute_metadata = (attribute_name, relation_name, domain_type,position, length)

    User_metadata = (user_name, encrypted_password, group)Index_metadata = (index_name, relation_name, index_type,

    index_attributes)View_metadata = (view_name, definition)

  • 8/14/2019 Rdbms (Unit 1)

    41/41

    End of Unit 1End of Unit 1