02 Storage Management-TELU (2).pdf

Full Transcript

Database System 02 | Storage Management Tahun Ajar Ganjil 2024/2025 Oleh: Tim Dosen Students knows various physical storage media. GOALS O...

Database System 02 | Storage Management Tahun Ajar Ganjil 2024/2025 Oleh: Tim Dosen Students knows various physical storage media. GOALS OF Students understand how to mapping a database to files MEETING Students understand how to organize records in files. 9 /1 0/ 2 02 4 Storage Management 2 OUTLINES Physical Storage Media File Organization Record Organization Database Buffer Storage Organization in Main-Memory Databases 9 /1 0/ 2 02 4 Storage Management 3 P HYSICAL STORAGE MEDIA F I XED - L EN GTH RE CO R D VAR I AB LE - L EN GTH RE CO R D 9 /1 0/ 2 02 4 4 CL ASSIFICATION OF PH YSICAL STORAGE MEDIA ▪ Physical storage media can differentiate into: Volatile storage : loses contents when power is switched off Non-volatile storage: Contents persist even when power is switched off. Includes secondary and tertiary storage, as well as batter-backed up main-memory ▪ Factors affecting choice of storage media include: Speed with which data can be accessed Cost per unit of data Reliability 9 /1 0/ 2 02 4 Storage Management 5 STORAGE HI ERA RC HY Volatile Primary storage Speed Secondary storage (online storage) Non-volatile Tertiary storage (offline storage) Storage Management 6 S T O R A G E H I E R A R C H Y ( C O N T. ) Primary storage: Fastest media but volatile (cache, main memory). Secondary storage: next level in hierarchy, non-volatile, moderately fast access time – Also called on-line storage – E.g., flash memory, magnetic disks Tertiary storage: lowest level in hierarchy, non-volatile, slow access time – also called off-line storage and used for archival storage – e.g., magnetic tape, optical storage – Magnetic tape Sequential access, 1 to 12 TB capacity A few drives with many tapes Juke boxes with petabytes (1000’s of TB) of storage FILE O RGA N I Z AT I O N FIXED-LENGTH RECORD VARIABLE-LENGTH RECORD FILE ORGANIZATION A database is mapped into a number of different files that are maintained by the underlying operating system. These files reside permanently on disks. A file is organized logically as a sequence of records. These records are mapped onto disk blocks. In a relational database, tuples of distinct relations are generally of different sizes. There are two approach to mapping the database to files: – store records of only one fixed length in any given file. – structure our files so that we can accommodate multiple (variable) lengths for records; however, files of fixed-length records are easier to implement than are files of variable-length records. FIXED-LENGTH RECORDS As an example, let us consider a file of instructor records for our university database instructor records for university database. Assume that each character occupies 1 byte and that numeric (8,2) occupies 8 bytes. We allocate the maximum number of bytes that each attribute can hold. Then, the instructor record is 53 bytes long. A simple approach is to use the first 53 bytes for the first record, the next 53 bytes for the second record, and so on. 10 FIXED-LENGTH RECORDS Problem 1 : Record access is simple but records may cross blocks (unless the block size happens to be multiple of the record size) Modification: do not allow records to cross block boundaries Problem 2: Difficult to delete a record from this structure. Alternatives: – move records after the deleted record into the space formerly occupied by the deleted records, an so on. – move the last record into the space formerly occupied by the deleted records – do not move records, but link all free records on a free list EXAMPLE : FILE CONTAINING INSTRUCTOR RECORDS 12 FIXED-LENGTH RECORDS Deletion of record i: alternatives: – move records i + 1,..., n to i,... , n – 1 Record 3 deleted FIXED-LENGTH RECORDS Deletion of record i: alternatives: – move record n to i Record 3 deleted and replaced by record 11 FIXED-LENGTH RECORDS Deletion of record i: alternatives: – do not move records, but link all free records on a free list VAR IAB LE-LEN GTH R ECORD S Variable-length records arise in database systems in several ways: – Storage of multiple record types in a file. – Record types that allow variable lengths for one or more fields such as strings (varchar) – Record types that allow repeating fields (used in some older data models). Attributes are stored in order Variable length attributes represented by fixed size (offset, length), with actual data stored after all fixed length attributes Null values represented by null-value bitmap VARIABLE-LENGTH RECORDS: SLOTTED PAGE STRUCTURE The problem of storing variable-length records in a block. The slotted-page structure is commonly used for organizing records within a block Slotted page header contains: – number of record entries – end of free space in the block – location and size of each record 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. Pointers should not point directly to record — instead they should point to the entry for the record in header. BLOCKING – A Block is a transfer data unit between secondary and primary devices – Block Size in byte (B) Oversize block size will also transfer unnecessary data in it → needs bigger memory allocation Undersize block size will cause repeatable read – Records are stored in block. – Blocking is a method to arrange records in a block. – Blocking Factor (Bfr) : Number of records in a block 18 FIXED BLOCKING Number of fixed length records in all blocks remain the same Record length

Use Quizgecko on...
Browser
Browser