Chap 11 Storage and File Structure 7 Database
Chap 11 Storage and File Structure 中文版:第 7章 “儲存設備和檔案結構” Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See www. db-book. com for conditions on re-use
Chapter 11: Storage and File Structure n Overview of Physical Storage Media n Magnetic Disks n RAID n Tertiary Storage n Storage Access n File Organization n Organization of Records in Files n Data-Dictionary Storage Database System Concepts, 5 th Edition, Oct 5, 2006 11. 2 ©Silberschatz, Korth and Sudarshan
Storage Hierarchy Database System Concepts, 5 th Edition, Oct 5, 2006 11. 3 ©Silberschatz, Korth and Sudarshan
Storage Hierarchy (Cont. ) n primary storage: Fastest media but volatile (cache, main memory). n secondary storage: next level in hierarchy, non -volatile, moderately fast access time l also called on-line storage l E. g. flash memory, magnetic disks n tertiary storage: lowest level in hierarchy, non- volatile, slow access time l also called off-line storage l E. g. magnetic tape, optical storage Database System Concepts, 5 th Edition, Oct 5, 2006 11. 4 ©Silberschatz, Korth and Sudarshan
Magnetic Hard Disk Mechanism 2007 Nobel AWD on Physics -- Albert Fert and Peter Grünberg Subject to “GMR” – Giant Magneto-resistance (巨磁電阻效應) Database System Concepts, 5 th Edition, Oct 5, 2006 11. 5 ©Silberschatz, Korth and Sudarshan
RAID P I K S n RAID: Redundant Arrays of Independent Disks 1988, UC Berkeley l D. Patterson、R. Katz and G. Gibson l 4 high capacity and high speed by using multiple disks in parallel, and 4 high reliability by storing data redundantly, so that data can be recovered even if a disk fails n Originally a cost-effective alternative to large, expensive disks l I in RAID originally stood for “Inexpensive” l Today RAIDs are used for their higher reliability and bandwidth. 4 The “I” is interpreted as “Independent” Database System Concepts, 5 th Edition, Oct 5, 2006 11. 6 ©Silberschatz, Korth and Sudarshan
Chapter 11: Storage and File Structure n Overview of Physical Storage Media n Magnetic Disks n RAID n Tertiary Storage n Storage Access n File Organization n Organization of Records in Files n Data-Dictionary Storage Database System Concepts, 5 th Edition, Oct 5, 2006 11. 7 ©Silberschatz, Korth and Sudarshan
Storage Access n A database file is partitioned into fixed-length storage units called blocks. Blocks are units of both storage allocation and data transfer. n 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. n Buffer – portion of main memory available to store copies of disk blocks. n Buffer manager – subsystem responsible for allocating buffer space in main memory. IBM: DB 2 server = Hardware + OS + Database (另例: Google) 如果非專用伺服器,可想像成每次磁碟重組後所保持的最佳狀態 Database System Concepts, 5 th Edition, Oct 5, 2006 11. 8 ©Silberschatz, Korth and Sudarshan
Buffer Manager P I K Sn Programs call on the buffer manager when they need a block from disk. 1. If the block is already in the buffer, buffer manager returns the address of the block in main memory 2. If the block is not in the buffer, the buffer manager 1. Allocates space in the buffer for the block 1. Replacing (throwing out) some other block, if required, to make space for the new block. 2. Replaced block written back to disk only if it was modified since the most recent time that it was written to/fetched from the disk. 2. Reads the block from the disk to the buffer, and returns the address of the block in main memory to requester. n least recently used (LRU) strategy n Most recently used (MRU) strategy Database System Concepts, 5 th Edition, Oct 5, 2006 11. 9 ©Silberschatz, Korth and Sudarshan
Chapter 11: Storage and File Structure n Overview of Physical Storage Media n Magnetic Disks n RAID n Tertiary Storage n Storage Access n File Organization n Organization of Records in Files n Data-Dictionary Storage 本節主講: 檔案內剩餘空間的調配 Database System Concepts, 5 th Edition, Oct 5, 2006 11. 10 ©Silberschatz, Korth and Sudarshan
File Organization n The database is stored as a collection of files. n Each file is a sequence of records. n A record is a sequence of fields. n One approach: lassume leach record size is fixed (長度固定) file has records of one particular type only (型態固定) ldifferent files are used for different relations (一表格一檔案) This case is easiest to implement; will consider variable length records later. (其他變化則稍後討論) Database System Concepts, 5 th Edition, Oct 5, 2006 11. 11 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records n Simple approach: l Store record i starting from byte n (i – 1), where n is the size of each record. l Record access is simple but records may cross blocks 4 Modification: do not allow records to cross block boundaries 4由OS調配,但還是同一個檔案。 n Deletion of record i: alternatives: l [A] move records i + 1, . . . , n to i, . . . , n – 1 move record n to i l [B] do not move records, but link all free records on a free list Database System Concepts, 5 th Edition, Oct 5, 2006 11. 12 ©Silberschatz, Korth and Sudarshan
Free Lists n Store the address of the first deleted record in the file header. n Use this first record to store the address of the second deleted record, and so on n Can think of these stored addresses as pointers since they “point” to the location of a record. n More space efficient representation: reuse space for normal attributes of free records to store pointers. (No pointers stored in in-use records. ) Database System Concepts, 5 th Edition, Oct 5, 2006 11. 13 ©Silberschatz, Korth and Sudarshan
Variable-Length Records n Variable-length records arise in database systems in several ways: l Storage of multiple record types in a file. 4 e. g. l Record types that allow variable lengths for inner fields. 4 e. g. l clustering file organization (叢集檔案組) “Memo” or “Image” data types Record types that allow repeating fields 4 used in some older data models 4 中文版 7. 5. 2~7. 5. 3 的例子 Database System Concepts, 5 th Edition, Oct 5, 2006 11. 14 ©Silberschatz, Korth and Sudarshan
Variable-Length Records: Slotted Page Structure n Slotted page header contains: l number of record entries l end of free space in the block l location and size of each record n Records can be moved around within a page to keep them contiguous with no empty space between them; entry in the header must be updated. n Pointers should not point directly to record — instead they should point to the entry for the record in header. Database System Concepts, 5 th Edition, Oct 5, 2006 11. 15 ©Silberschatz, Korth and Sudarshan
n Break n (goto Chap 12) Database System Concepts, 5 th Edition, Oct 5, 2006 11. 16 ©Silberschatz, Korth and Sudarshan
Chapter 11: Storage and File Structure n Overview of Physical Storage Media n Magnetic Disks n RAID n Tertiary Storage n Storage Access n File Organization n Organization of Records in Files n Data-Dictionary Storage 本節主講: 檔案中儲存資料列的配置 Database System Concepts, 5 th Edition, Oct 5, 2006 11. 17 ©Silberschatz, Korth and Sudarshan
Organization of Records in Files P I K S n Heap – a record can be placed anywhere in the file where there is space n Sequential – store records in sequential order, based on the value of the search key of each record n Hashing – a hash function computed on some attribute of each record; the result specifies in which block of the file the record should be placed n Records of each relation may be stored in a separate file. In a multitable clustering file organization (叢集檔案組) records of several different relations can be stored in the same file l Motivation: store related records on the same block to minimize I/O Database System Concepts, 5 th Edition, Oct 5, 2006 11. 18 ©Silberschatz, Korth and Sudarshan
Chapter 11: Storage and File Structure n Overview of Physical Storage Media n Magnetic Disks n RAID n Tertiary Storage n Storage Access n File Organization n Organization of Records in Files n Data-Dictionary Storage Database System Concepts, 5 th Edition, Oct 5, 2006 11. 19 ©Silberschatz, Korth and Sudarshan
Data Dictionary Storage Data dictionary (also called system catalog) stores metadata; that is, data about data, such as n Information about relations names of relations l names and types of attributes of each relation l names and definitions of views l integrity constraints User and accounting information, including passwords l Mysqldump --user=root –password=gogogo mysql user Statistical and descriptive data Physical file organization information E. g. My. SQL 如要加入新 Information about indices (Chapter 12) 使用者權限 需更改 Tables: host, user, db l n n Database System Concepts, 5 th Edition, Oct 5, 2006 11. 20 ©Silberschatz, Korth and Sudarshan
Data Dictionary Storage (Cont. ) n Catalog structure l Relational representation on disk l specialized data structures designed for efficient access, in memory n 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) Database System Concepts, 5 th Edition, Oct 5, 2006 11. 21 ©Silberschatz, Korth and Sudarshan
End of Chapter 11 Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See www. db-book. com for conditions on re-use
- Slides: 22