ppt format

445 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
445
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ppt format

  1. 1. Recap of Feb 20: Database Design Goals, Normalization, Normal Forms <ul><li>Goals for designing a database: a schema with: </li></ul><ul><ul><li>simple, easy to phrase queries </li></ul></ul><ul><ul><li>avoids redundancies (repetition of information) </li></ul></ul><ul><ul><li>avoids anomalies </li></ul></ul><ul><ul><li>good performance </li></ul></ul><ul><li>Normalization </li></ul><ul><ul><li>decompose complex relations </li></ul></ul><ul><ul><li>Lossy decompositions </li></ul></ul><ul><ul><li>Functional Dependencies </li></ul></ul><ul><li>Normal Forms: 1NF, 2NF, 3NF, BCNF </li></ul><ul><ul><li>BCNF or 3NF: lossless decomposition in both </li></ul></ul><ul><ul><ul><li>BCNF can’t always ensure dependency preservation </li></ul></ul></ul><ul><ul><ul><li>3NF sometimes requires null values or redundant information </li></ul></ul></ul>
  2. 2. Getting Physical: Storage and File Structure (Chapter 11) <ul><li>Up until now we have examined database design from a high-level conceptual view, passing over actual implementation and underlying hardware. </li></ul><ul><ul><li>Appropriate focus for database users </li></ul></ul><ul><ul><li>But hardware does have an influence on implementation, and implementation does have an influence on what conceptual designs will be more efficient and useful </li></ul></ul><ul><li>Now we get physical -- examine physical storage media to give a background for later focus on implementation of the data models and languages already described </li></ul>
  3. 3. Chapter 11 <ul><li>At this point we are focussing on the following sections </li></ul><ul><li>11.1 Overview of Physical Storage Media </li></ul><ul><li>11.2 Magnetic Disks </li></ul><ul><li>11.3 RAID (very briefly) </li></ul><ul><li>11.4 Tertiary Storage </li></ul><ul><li>11.5 Storage Access </li></ul><ul><li>11.6 File Organization </li></ul><ul><li>11.7 Organization of Records in Files </li></ul><ul><li>11.8 Data-Dictionary Storage </li></ul>
  4. 4. Midterm! <ul><li>As per the syllabus, the Midterm will cover the pre-midterm lecture notes plus sections 1,2,3 (except 3.4 & 3.5), 4, 6, 7-7.7, 11 (except 11.3 and 11.9) of the text </li></ul><ul><li>We have examined all that material except chapter 11, which starts today </li></ul><ul><li>Scheduling the midterm depends upon the speed with which we get through the material. </li></ul><ul><li>It looks as if we’ll have enough time to schedule one day for review before the midterm </li></ul><ul><li>My current guess is that we might be able to schedule the midterm as early as March 13; certainly no later than March 20. I’m aiming for Tuesday, March 18. </li></ul>
  5. 5. Midterm Study and Homework #2 <ul><li>Material you are responsible for: </li></ul><ul><ul><li>All material presented in class before the midterm </li></ul></ul><ul><ul><li>Textbook sections 1,2,3 (except 3.4 & 3.5), 4, 6, 7-7.7, 11 (except 11.3 and 11.9) </li></ul></ul><ul><li>The homework questions from assignment 1 (exercises 1.1, 1.2, 1.3, and 2.1-2.6) are all useful study aids, as are the questions from homework assignment #2: </li></ul><ul><ul><li>3.2, 3.3, 3.5, 3.6 -- 3.9, 3.16 </li></ul></ul><ul><ul><li>4.1, 4.2, 4.4 -- 4.8 </li></ul></ul><ul><ul><li>7.2, 7.4, 7.5, 7.11, 7.12, 7.15, 7.16, 7.21, 7.23 </li></ul></ul><ul><li>Homework #2 is due Tuesday, March 11. I’ll try to have them back to you, graded, Thursday March 13 so you can use them as a study aid for the exam Tuesday, March 18. </li></ul>
  6. 6. Classification of Physical Storage Media <ul><li>Media are classified according to three characteristics: </li></ul><ul><ul><li>speed of access </li></ul></ul><ul><ul><li>cost per unit of data </li></ul></ul><ul><ul><li>reliability </li></ul></ul><ul><ul><ul><li>data loss on power failure or system crash </li></ul></ul></ul><ul><ul><ul><li>physical failure of the storage device </li></ul></ul></ul><ul><li>We can also differentiate storage as either </li></ul><ul><ul><li>volatile storage </li></ul></ul><ul><ul><li>non-volative storage </li></ul></ul>
  7. 7. Physical Storage Media Overview (11.1) <ul><li>Typical media available are: </li></ul><ul><ul><li>Cache </li></ul></ul><ul><ul><li>Main memory </li></ul></ul><ul><ul><li>Flash memory </li></ul></ul><ul><ul><li>Mag disk </li></ul></ul><ul><ul><li>Optical storage (CD or DVD) </li></ul></ul><ul><ul><li>Tape storage </li></ul></ul>
  8. 8. Physical Storage Media -- Cache and Main Memory <ul><li>Cache </li></ul><ul><ul><li>fastest and most costly form of storage </li></ul></ul><ul><ul><li>volatile </li></ul></ul><ul><ul><li>managed by computer system hardware </li></ul></ul><ul><li>Main memory </li></ul><ul><ul><li>fast access (10s to 100s of nanoseconds) </li></ul></ul><ul><ul><li>generally too small or expensive to hold the entire database </li></ul></ul><ul><ul><ul><li>current capacities commonly used are up to a few Gigabites </li></ul></ul></ul><ul><ul><ul><li>capacities have gone up and per-byte costs have decreased steadily, roughly a factor of 2 every 2-3 years </li></ul></ul></ul><ul><ul><li>volatile </li></ul></ul>
  9. 9. Physical Storage Media -- Flash Memory <ul><li>Also known as EEPROM -- Electrically Erasable Programmable Read-Only Memory </li></ul><ul><li>non-volatile </li></ul><ul><li>reading data is comparable to main memory speeds </li></ul><ul><li>writing is more complex </li></ul><ul><ul><li>can’t overwrite a single location -- a whole bank of memory must be erased to permit writing within that bank. </li></ul></ul><ul><ul><li>erasing is only supported a limited number of times -- 10,000 to one million erase cycles </li></ul></ul><ul><ul><li>writes are slow (a few microseconds), and erases are slower </li></ul></ul><ul><li>cost comparable to main memory </li></ul><ul><li>widely used in computer systems embedded in other devices, such as digital cameras and hand-held computers </li></ul>
  10. 10. Physical Storage Media -- Magnetic Disk <ul><li>data is stored on a spinning disk and read/written magnetically </li></ul><ul><li>primary medium for long-term storage of data </li></ul><ul><li>typically stores entire database </li></ul><ul><li>data must be moved from disk to main memory for access, and written back for storage </li></ul><ul><ul><li>much slower access than main memory (about which more later) </li></ul></ul><ul><li>direct access -- possible to read data on disk in any order, unlike magnetic tape </li></ul><ul><li>capacities up to 100 gig </li></ul><ul><ul><li>much larger capacity and cheaper cost/byte than main memory or flash memory </li></ul></ul><ul><ul><li>capacity doubles every two or three years </li></ul></ul><ul><li>survives power failures and system crashes </li></ul><ul><ul><li>disk failure can destroy data, but this is more rare than system crashes </li></ul></ul>
  11. 11. Physical Storage Media -- Optical Storage <ul><li>Non-volatile; data is read optically from a spinning disk using a laser </li></ul><ul><li>CD-ROM (640 MB) and DVD (4.7 to 17 GB) most popular forms </li></ul><ul><li>Write-once, Read-many (WORM) optical disks used for archival storage (CD-R and DCD-R) </li></ul><ul><li>Multiple-write versions also available (CD-RW, DVD-RW, and DVD-RAM) </li></ul><ul><li>Reads and writes are slower than with magnetic disk </li></ul><ul><li>Juke-box systems available for storing large volumes of data </li></ul><ul><ul><li>large numbers of removable disks </li></ul></ul><ul><ul><li>several drives </li></ul></ul><ul><ul><li>mechanism for automatic loading/unloading of disks </li></ul></ul>
  12. 12. Physical Storage Media -- Tape Storage <ul><li>Non-volatile </li></ul><ul><li>used primarily for backup (to recover from disk failure) and for archival data </li></ul><ul><li>sequential access -- much slower than disk </li></ul><ul><li>very high capacity (40-300 GB tapes available) </li></ul><ul><li>tape can be removed from drive; storage costs much cheaper than disk, but drives are expensive; data is read optically from a spinning disk using a laser </li></ul><ul><li>Juke-box systems available for storing large volumes of data </li></ul><ul><ul><li>e.g., remote sensing data, possibly hundreds of terabytes (10 12 bytes) or even a petabyte (10 15 bytes) </li></ul></ul>
  13. 13. Storage Hierarchy <ul><li>Primary storage: fastest media but volatile </li></ul><ul><ul><li>cache </li></ul></ul><ul><ul><li>main memory </li></ul></ul><ul><li>secondary storage: next level in hierarchy; moderately fast access time, non-volatile </li></ul><ul><ul><li>also called on-line storage </li></ul></ul><ul><ul><li>flash memory, magnetic disks </li></ul></ul><ul><li>tertiary storage: lowest level in hierarchy; slower access time, non-volatile </li></ul><ul><ul><li>also called off-line storage </li></ul></ul><ul><ul><li>optical storage, magnetic tape </li></ul></ul>
  14. 14. Magnetic Disks (11.2) <ul><li>Read-write head </li></ul><ul><ul><li>positioned very close to the platter surface (almost touching it) </li></ul></ul><ul><ul><li>Reads or writes magnetically coded information </li></ul></ul><ul><li>Surface of platter divided into circular tracks </li></ul><ul><ul><li>over 16,000 tracks per platter on typical hard disks </li></ul></ul><ul><li>Each track is divided into sectors </li></ul><ul><ul><li>a sector is the smallest unit of data that can be read or written </li></ul></ul><ul><ul><li>sector size is typically 512 bytes </li></ul></ul><ul><ul><li>typically 200 (on inner tracks) to 400 (outer tracks) sectors per track </li></ul></ul>
  15. 15. Magnetic Disks (cont) <ul><li>To read/write a sector </li></ul><ul><ul><li>disk arm swings to position head on the right track </li></ul></ul><ul><ul><li>platter spins continually; data is read/written as sector passes under head </li></ul></ul><ul><li>Head-disk assemblies </li></ul><ul><ul><li>multiple disk platters on a single spindle (typically 2 to 4) </li></ul></ul><ul><ul><li>one head per platter, mounted on a common arm </li></ul></ul><ul><li>Cylinder i consists of i th track of all the platters </li></ul>
  16. 16. Magnetic Disks (cont) <ul><li>Earlier generation disks were susceptible to head crashes </li></ul><ul><ul><li>disk spins constantly at 60, 120, even 250 revolutions per second </li></ul></ul><ul><ul><li>head is very close to the surface; if it touches the surface it can scrape the recording medium off the surface, wiping out data and causing the removed medium to fly around, causing more head crashes </li></ul></ul><ul><ul><li>newer disks have less friable material; less subject to head crashes </li></ul></ul>
  17. 17. Magnetic Disks (cont) <ul><li>Disk controller -- interfaces between the computer system and the disk drive </li></ul><ul><ul><li>accepts high-level commands to read or write a sector </li></ul></ul><ul><ul><li>initiates actions such as moving the disk arm to the right track and actually reading or writing the data </li></ul></ul><ul><ul><li>computes and attaches checksums to each sector to verify that data is read back correctly </li></ul></ul><ul><ul><li>Ensures successful writing by reading back sector after writing it </li></ul></ul><ul><ul><li>Performs remapping of bad sectors </li></ul></ul><ul><li>Multiple disks are connected to a computer system through a controller </li></ul><ul><ul><li>controllers functionality (checksum, bad sector remapping) often carried out by individual disks, reducing load on controller </li></ul></ul><ul><li>Two disk interface standards are ATA (AT attachment) and SCSI (Small Computer System Interconnect) </li></ul>
  18. 18. Disk Performance Measures <ul><li>Access time -- the time it takes from when a read or write request is issued to when data transfer begins. Consists of: </li></ul><ul><ul><li>Seek time -- time it takes to reposition the arm over the correct track </li></ul></ul><ul><ul><ul><li>average seek time is 1/2 the worst case seek time </li></ul></ul></ul><ul><ul><ul><li>4 to 10 milliseconds on typical disks </li></ul></ul></ul><ul><ul><li>Rotational latency -- time it takes for the sector to appear under the head </li></ul></ul><ul><ul><ul><li>average latency is 1/2 the worst case latency </li></ul></ul></ul><ul><ul><ul><li>4 to 11 milliseconds on typical disk (5400 to 15000 rpm) </li></ul></ul></ul><ul><li>Data Transfer Rate -- rate of retrieval from or storage to disk </li></ul><ul><ul><li>4 to 8 MB per second is typical </li></ul></ul><ul><ul><li>Multiple disks may share a controller, so the rate that controller can handle is also important. E.G., ATA-5: 66MB/sec, SCSI-3: 40MB/sec, Fiber Channel: 256 MB/s </li></ul></ul>
  19. 19. Disk Performance Measures (cont.) <ul><li>Mean time to failure (MTTF) - the average time the disk is expected to run continuously without any failure. </li></ul><ul><ul><li>Typically 3-5 years </li></ul></ul><ul><ul><li>Sounds good, but if you have 1500 disks then 300 per year will fail, or about 1 per day </li></ul></ul><ul><ul><li>MTTF decreases as the disk ages </li></ul></ul><ul><li>RAID (Redundant Arrays of Independent Disks) ( 11.3 ) </li></ul><ul><ul><li>disk organization techniques that manage a large number of disks, providing a view of a single disk of </li></ul></ul><ul><ul><ul><li>high capacity and high speed by using multiple disks in parallel </li></ul></ul></ul><ul><ul><ul><li>high reliability by storing data redundantly, so that data can be recovered even if a disk fails </li></ul></ul></ul><ul><ul><ul><li>MTTdata loss can be as high as 500,000 to 1,000,000 hours on a RAID </li></ul></ul></ul>
  20. 20. Optimization of Disk-Block Access: Motivation <ul><li>Requests for disk I/O are generated both by the file system and by the virtual memory manager </li></ul><ul><li>Each request specifies the address on the disk to be referenced in the form of a block number </li></ul><ul><ul><li>a block is a contiguous sequence of sectors from a single track on one platter </li></ul></ul><ul><ul><li>block sizes range from 512 bytes to several K (4 -- 16K is typical) </li></ul></ul><ul><ul><li>smaller blocks mean more transfers from disk; larger blocks makes for more wasted space due to partially filled blocks </li></ul></ul><ul><ul><li>block is the standard unit of data transfer between disk to main memory </li></ul></ul><ul><li>Since disk access speed is much slower than main memory access, methods for optimizing disk-block access are important </li></ul>
  21. 21. Optimization of Disk-Block Access: Methods <ul><li>Disk-arm Scheduling: requests for several blocks may be speeded up by requesting them in the order they will pass under the head. </li></ul><ul><ul><li>If the blocks are on different cylinders, it is advantageous to ask for them in an order that minimizes disk-arm movement </li></ul></ul><ul><ul><li>Elevator algorithm -- move the disk arm in one direction until all requests from that direction are satisfied, then reverse and repeat </li></ul></ul><ul><ul><li>Sequential access is 1-2 orders of magnitude faster; random access is about 2 orders of magnitude slower </li></ul></ul>
  22. 22. Optimization of Disk-Block Access: Methods <ul><li>Non-volatile write buffers </li></ul><ul><ul><li>store written data in a RAM buffer rather than on disk </li></ul></ul><ul><ul><li>write the buffer whenever it becomes full or when no other disk requests are pending </li></ul></ul><ul><ul><li>buffer must be non-volatile to protect from power failure </li></ul></ul><ul><ul><ul><li>called non-volatile random-access memory (NV-RAM) </li></ul></ul></ul><ul><ul><ul><li>typically implemented with battery-backed-up RAM </li></ul></ul></ul><ul><ul><li>dramatic speedup on writes; with a reasonable-sized buffer write latency essentially disappears </li></ul></ul><ul><ul><li>why can’t we do the same for reads? (hints: ESP, clustering) </li></ul></ul>
  23. 23. Optimization of Disk-Block Access: Methods <ul><li>File organization ( Clustering ): reduce access time by organizing blocks on disk in a way that corresponds closely to the way we expect them to be accessed </li></ul><ul><ul><li>sequential files should be kept organized sequentially </li></ul></ul><ul><ul><li>hierarchical files should be organized with mothers next to daughters </li></ul></ul><ul><ul><li>for joining tables (relations) put the joining tuples next to each other </li></ul></ul><ul><ul><li>over time fragmentation can become an issue </li></ul></ul><ul><ul><ul><li>restoration of disk structure (copy and rewrite, reordered) controls fragmentation </li></ul></ul></ul>
  24. 24. Optimization of Disk-Block Access: Methods <ul><li>Log-based file system </li></ul><ul><ul><li>does not update in-place, rather writes updates to a log disk </li></ul></ul><ul><ul><ul><li>essentially, a disk functioning as a non-volatile RAM write buffer </li></ul></ul></ul><ul><ul><li>all access in the log disk is sequential, eliminating seek time </li></ul></ul><ul><ul><li>eventually updates must be propogated to the original blocks </li></ul></ul><ul><ul><ul><li>as with NV-RAM write buffers, this can occur at a time when no disk requests are pending </li></ul></ul></ul><ul><ul><ul><li>the updates can be ordered to minimize arm movement </li></ul></ul></ul><ul><ul><li>this can generate a high degree of fragmentation on files that require constant updates </li></ul></ul><ul><ul><ul><li>fragmentation increases seek time for sequential reading of files </li></ul></ul></ul>
  25. 25. Storage Access (11.5) <ul><li>Basic concepts (some already familiar): </li></ul><ul><ul><li>block-based. A block is a contiguous sequence of sectors from a single track; blocks are units of both storage allocation and data transfer </li></ul></ul><ul><ul><li>a file is a sequence of records stored in fixed-size blocks (pages) on the disk </li></ul></ul><ul><ul><li>each block (page) has a unique address called BID </li></ul></ul><ul><ul><li>optimization is done by reducing I/O, seek time, etc. </li></ul></ul><ul><ul><li>database systems seek 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. </li></ul></ul><ul><ul><li>Buffer - portion of main memory used to store copies of disk blocks </li></ul></ul><ul><ul><li>buffer manager - subsystem responsible for allocating buffer space in main memory and handling block transfer between buffer and disk </li></ul></ul>
  26. 26. Buffer Management <ul><li>The buffer pool is the part of the main memory alocated for temporarily storing disk blocks read from disk and made available to the CPU </li></ul><ul><li>The buffer manager is the subsystem responsible for the allocation and the management of the buffer space (transparent to users) </li></ul><ul><li>On a process (user) request for a block (page) the buffer manager: </li></ul><ul><ul><li>checks to see if the page is already in the buffer pool </li></ul></ul><ul><ul><li>if so, passes the address to the process </li></ul></ul><ul><ul><li>if not, it loads the page from disk and then passes the address to the process </li></ul></ul><ul><ul><li>loading a page might require clearing (writing out) a page to make space </li></ul></ul><ul><li>Very similar to the way virtual memory managers work, although it can do a lot better (why?) </li></ul>
  27. 27. Buffer Replacement Strategies <ul><li>Most operating systems use a LRU replacement scheme. In database environments, MRU is better for some common operations (e.g., join) </li></ul><ul><ul><li>LRU strategy: replace the least recently used block </li></ul></ul><ul><ul><li>MRU strategy: replace the most recently used block </li></ul></ul><ul><li>Sometimes it is useful to fasten or pin blocks to keep them available during an operation and not let the replacement strategy touch them </li></ul><ul><ul><li>pinned block is thus a block that is not allowed to be written back to disk </li></ul></ul><ul><li>There are situations where it is necessary to write back a block to disk even though the buffer space it occupies is not yet needed. This write is called the forced output of a block; useful in recovery situations </li></ul><ul><li>Toss-immediate strategy: free the space occupied by a block as soon as the final tuple of that block has been processed </li></ul>
  28. 28. Buffer Replacement Strategies <ul><li>Most recently used (MRU) strategy: system must pin the block currently being processed. After the final tuple of that block has been processed the block is unpinned and becomes the most recently used block. This is essentially “toss-immediate” with pinning, and works very well with joins. </li></ul><ul><li>The buffer manager can often use other information (design or statistical) to predict the probability that a request will reference a particular page </li></ul><ul><ul><li>e.g., the data dictionary is frequently accessed -- keep the data dictionary blocks in main memory buffer </li></ul></ul><ul><ul><li>if several pages are available for overwrite; choose the one that has the lowest number of recent access requests to replace </li></ul></ul>
  29. 29. Buffer Management (cont) <ul><li>Existing OS affect DBMS operations by: </li></ul><ul><ul><li>read ahead, write behind </li></ul></ul><ul><ul><li>wrong replacement strategies </li></ul></ul><ul><ul><li>Unix is not good for DBMS to run on top </li></ul></ul><ul><ul><li>Most commercial systems implement their own I/O on a raw disk partition </li></ul></ul><ul><li>Variations of buffer allocation </li></ul><ul><ul><li>common buffer pool for all relations </li></ul></ul><ul><ul><li>separate buffer pool for each relation </li></ul></ul><ul><ul><li>as above but with relations borrowing space from each other </li></ul></ul><ul><ul><li>prioritized buffers for very frequently accessed blocks, e.g. data dictionary </li></ul></ul>
  30. 30. Buffer Management (cont) <ul><li>For each buffer the manager keeps the following: </li></ul><ul><ul><li>which disk and which block it is in </li></ul></ul><ul><ul><li>whether the block is dirty (has been modified) or not (why?) </li></ul></ul><ul><ul><li>information for the replacement strategy </li></ul></ul><ul><ul><ul><li>last time block was accessed </li></ul></ul></ul><ul><ul><ul><li>whether it is pinned </li></ul></ul></ul><ul><ul><ul><li>possible statistical information (access frequency etc.) </li></ul></ul></ul>

×