Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Database Systems 1 Storing Data: Disks and Files Chapter 3 “Yea, from the table of my memory I’ll wipe away all trivial fond records.”

Similar presentations


Presentation on theme: "Introduction to Database Systems 1 Storing Data: Disks and Files Chapter 3 “Yea, from the table of my memory I’ll wipe away all trivial fond records.”"— Presentation transcript:

1 Introduction to Database Systems 1 Storing Data: Disks and Files Chapter 3 “Yea, from the table of my memory I’ll wipe away all trivial fond records.” -- Shakespeare, Hamlet

2 Introduction to Database Systems 2 Contents 1Disk Storage Devices 2Files of Records 3Operations on Files 4Unordered Files 5Ordered Files 6Hashed Files 6.1Static External Hashing 6.2Dynamic and Extendible Hashing Techniques

3 Introduction to Database Systems 3 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.

4 Introduction to Database Systems 4 Disk Storage Devices  Disks are divided into concentric circular tracks on each disk surface.  Track capacities vary typically from 4 to 50 Kbytes.

5 Introduction to Database Systems 5 Why Not Store Everything in Main Memory?  Costs too much. $1000 will buy you either 500MB of RAM or 30GB of disk today.  Main memory is volatile. We want data to be saved between runs. (Obviously!)  Typical storage hierarchy: –Main memory (RAM) for currently used data. –Disk for the main database (secondary storage). –Tapes for archiving older versions of the data (tertiary storage).

6 Introduction to Database Systems 6 Why Not Store Everything in Main Memory?  Note: Some DBMS systems DO keep everything in RAM, “Main Memory Databases”  Limited applications, but 10x faster

7 Introduction to Database Systems 7 Disks  Secondary storage device of choice.  Main advantage over tapes: random access vs. sequential.  Data is stored and retrieved in units called disk blocks or pages.  Unlike RAM, time to retrieve a disk page varies depending upon location on disk. –Therefore, relative placement of pages on disk has major impact on DBMS performance!

8 Introduction to Database Systems 8 Components of a Disk Platters The platters spin (say, 7200rpm). Spindle The arm assembly is moved in or out to position a head on a desired track. Tracks under heads make a cylinder (imaginary!). Disk head Arm movement Arm assembly Only one head reads/writes at any one time. Tracks Sector  Block size is a multiple of sector size (which is fixed).

9 Introduction to Database Systems 9

10 10 Disk Block Address  A physical disk block address consists of –a surface number, –track number, and (within surface) –block number. (within track) –(s,t,b)

11 Introduction to Database Systems 11 Accessing a Disk Page  Time to access (read/write) a disk block: – seek time ( moving arms to position disk head on track ) – rotational delay ( waiting for block to rotate under head ) – transfer time ( actually moving data to/from disk surface ) –Command overhead(the time it takes for the disk drive’s microprocessor and electronics to process and handle an I/O request) Key to lower I/O cost: reduce seek/rotation delays! Hardware vs. software solutions?

12 Introduction to Database Systems 12 Accessing a Disk Page  Seek time and rotational delay dominate. –Seek time varies from about 1 to 20msec(typical 10ms without locality of access, 1/3*10ms with locality) –Rotational delay varies from 0 to 10msec(5.6ms for 5,400rpm) –Transfer rate is about 1msec per 4KB page(5Mbytes/sec) –Command overhead 0.5ms

13 Introduction to Database Systems 13 Typical average time to read a 4- Kbyte disk I/O  Without locality access –Overhead + seek + latency + transfer 0.5 ms + 10 ms + 5.6ms + 0.8ms = 16.9 ms  With locality access 0.3 + 1/3 *10 + 5.6 + 0.8 =10.2ms  5.6ms is for 5,400rpm ½ * (1/5400) * 60 * 1000 ms

14 Introduction to Database Systems 14 Arranging Pages on Disk  ` Next ’ block concept: –blocks on same track, followed by –blocks on same cylinder, followed by –blocks on adjacent cylinder  Blocks in a file should be arranged sequentially on disk (by `next’), to minimize seek and rotational delay.  For a sequential scan, pre-fetching several pages at a time is a big win!

15 Introduction to Database Systems 15 Disk Space Management  Lowest layer of DBMS software manages space on disk.  Higher levels call upon this layer to: –allocate/de-allocate a page –read/write a page  Request for a sequence of pages must be satisfied by allocating the pages sequentially on disk! Higher levels don’t need to know how this is done, or how free space is managed.

16 Introduction to Database Systems 16 Buffer Management in a DBMS  Data must be in RAM for DBMS to operate on it!  Table of pairs is maintained. DB MAIN MEMORY DISK disk page free frame Page Requests from Higher Levels BUFFER POOL choice of frame dictated by replacement policy

17 Introduction to Database Systems 17 When a Page is Requested...  If requested page is not in pool: –Choose a frame for replacement –If frame is “dirty”, write it to disk –Read requested page into chosen frame  Pin the page and return its address.

18 Introduction to Database Systems 18 More on Buffer Management  Page in pool may be requested many times, –a pin count is used. A page is a candidate for replacement iff pin count = 0 ( “unpinned” )  CC & recovery may entail additional I/O when a frame is chosen for replacement. ( Write-Ahead Log protocol; more later.)

19 Introduction to Database Systems 19 DBMS vs. OS File System OS does disk space & buffer mgmt: why not let OS manage these tasks?  Some limitations, e.g., files can’t span disks.  Buffer management in DBMS requires ability to: –pin a page in buffer pool, force a page to disk & order writes (important for implementing CC & recovery) –adjust replacement policy, and pre-fetch pages based on access patterns in typical DB operations.

20 Introduction to Database Systems 20 Record Formats: Fixed Length  Information about field types same for all records in a file; stored in system catalogs.  Finding i’th field done via arithmetic. Base address (B) L1L2 L3L4 F1F2 F3F4 Address = B+L1+L2

21 Introduction to Database Systems 21 Page Formats: Fixed Length Records * Record id =. In first alternative, moving records for free space management changes rid; may not be acceptable. Slot 1 Slot 2 Slot N... NM1 0 M... 3 2 1 PACKED UNPACKED, BITMAP Slot 1 Slot 2 Slot N Free Space Slot M 11 number of records number of slots

22 Introduction to Database Systems 22 Page Formats: Variable Length Records * Can move records on page without changing rid; so, attractive for fixed-length records too. Page i Rid = (i,N) Rid = (i,2) Rid = (i,1) Pointer to start of free space SLOT DIRECTORY N... 2 1 20 1624 N # slots Offset of record from start of data area Length = 24

23 Introduction to Database Systems 23 Files of Records  Page or block is OK when doing I/O, but higher levels of DBMS operate on records, and files of records.  FILE : A collection of pages, each containing a collection of records. Must support: –insert/delete/modify record –read a particular record (specified using record id ) –scan all records (possibly with some conditions on the records to be retrieved)


Download ppt "Introduction to Database Systems 1 Storing Data: Disks and Files Chapter 3 “Yea, from the table of my memory I’ll wipe away all trivial fond records.”"

Similar presentations


Ads by Google