Physical Database Systems: Storage Media, Blocks, and Buffers
Overview: A DBMS can keep recently read pages in RAM and durable copies on disk.
What are Physical Database Systems?
- Up to this point in our database studies, we have viewed data logically as tables, rows, columns, and mathematical sets.
Physical Access of the Database & Buffer Management
- The CPU can only execute instructions and read data that resides inside Main Memory (RAM).
- The Buffer Pool is a large designated region of RAM reserved by the DBMS.
- The buffer pool is partitioned into equal-sized slots called Frame Buffers.
- When a SQL query asks for a record, the DBMS checks if the disk block containing that record is already in the buffer pool (a **Buffer…
- If not found (a Buffer Miss), the DBMS issues an operating system I/O request to load the entire physical disk block from disk into an…
- If the RAM buffer pool is completely full, a page must be evicted using a Buffer Replacement Policy (most commonly **LRU - Least…
The Physical Storage Hierarchy
- Computer memory is organized in a hierarchical pyramid balancing speed, capacity, and cost:
- 1. Primary Storage (Cache & RAM) Fastest (< 100 ns) | Volatile (Erased on power loss) | Direct CPU Access
- 2. Secondary Storage (SSD & HDD) Moderate speed (Microseconds/ms) | Non-Volatile | Stores active databases
- 3. Tertiary Storage (Tapes & Optical) Slowest (Seconds) | Immense capacity | Used for long-term historical archives
View diagram · Physical Storage Hierarchy
Physical Storage Blocks (Pages) and Sectors
- A disk does not read or write one byte or one record at a time.
- Sector: The smallest physical unit formatted on a magnetic platter (typically 512 bytes or 4,096 bytes).
- Block (Page): A contiguous cluster of sectors treated as the atomic unit of data transfer between disk and RAM.
Mathematical Concept: Blocking Factor (bfr)
- The Blocking Factor (bfr) is the maximum number of records that can fit into a single physical disk block.
- The Formula:
Blocking Factor (bfr) = Floor( Block_Size / Record_Size ) - Practical Numerical Example for DAVV Exams: Problem:
-
- A database table has 10,000 employee records.
-
- Each employee record has a fixed size of
R = 200 bytes.
- Each employee record has a fixed size of
-
- The physical disk block size is
B = 4,096 bytes (4 KB).
- The physical disk block size is
- Calculate:
-
Disk Performance Factors: Seek Time, Rotational Delay, and Transfer Time
Overview: If seek time is 5 ms, rotational delay is 4 ms and transfer takes 1 ms, a single read takes about 10 ms before queueing.
Introduction: Why Do We Measure Disk Performance?
- In modern computers, a fast CPU can perform over 4,000,000,000 operations per second (4 GHz).
Physical Anatomy of a Hard Disk Drive
- To understand performance timing, look at how an HDD is constructed:
- Platters: Circular magnetic discs mounted on a central spindle rotating at high speeds (e.g., 5,400 RPM, 7,200 RPM, 15,000 RPM).
- Tracks: Concentric circular rings on the platter surface where data bits are magnetically recorded.
- Cylinder: The collection of identical track numbers aligned vertically across all platter surfaces.
- Sectors: Pie-shaped subdivisions of a track (typically 512 bytes or 4 KB).
View diagram · Physical Architecture of a Magnetic Hard Disk
The Four Primary Disk Performance Factors
- When a DBMS requests a data block from disk, the total time elapsed is broken into four distinct physical components:
- 1. Access Motion Time (Seek Time) Time taken by the mechanical actuator arm to position the read/write head over the target track.
- 2. Head Activation Time Time required by electronic circuitry to activate the specific read/write head on the target platter surface.
- 3. Rotational Delay (Latency) Time spent waiting for the target sector to rotate underneath the active read/write head.
- 4. Data Transfer Time Actual time spent streaming data bits off the platter surface into the disk controller’s memory buffer.
- 1. Access Motion Time (Seek Time - Ts): This is the slowest, most expensive mechanical component of disk access!
- It requires physical motor acceleration and deceleration of the heavy actuator arm.
- Typical average seek time on modern commercial drives: 3 ms to 8 ms.
View diagram · Components of Total Disk Access Time
Total Disk Access Time Formula
Total Access Time = Seek_Time (Ts) + Rotational_Delay (Tr) + Transfer_Time (Tt)
Practical Numerical Calculation for DAVV Exams
- Problem:
- A hard disk drive has the following specifications:
-
- Average Seek Time =
4 ms
- Average Seek Time =
-
- Rotational Speed =
7,200 RPM
- Rotational Speed =
-
- Data Transfer Rate =
100 MB/sec
- Data Transfer Rate =
-
- Database Block Size =
4 KB
- Database Block Size =
- Calculate:
-
Data Storage Formats on Disk: Record Formats and I/O Management
Overview: A record is one logical item, such as one student’s details.
Introduction: How Records are Packed into Disk Blocks
- In earlier units, we saw that a database relation consists of tuples (rows).
- How to arrange fields within a record.
- How to handle variable-length text (like
VARCHAR) andNULLvalues. - How to store records inside a physical block so that records can be inserted, deleted, and updated without corrupting adjacent data.
Track Format and Sector Formatting
- When a hard disk platter is manufactured, it undergoes Low-Level Formatting:
- Each concentric track is partitioned into sectors.
- Each sector contains:
- Preamble / Header: Contains synchronization bits and the physical sector address (Cylinder number, Head number, Sector number).
- Data Payload Area: Typically 512 bytes or 4,096 bytes of user data.
- ECC (Error-Correcting Code): Parity bits used by the disk controller to detect and automatically correct bit-flips caused by magnetic degradation.
- Inter-Sector Gap: Small unrecorded buffer separating adjacent sectors.
Record Formats: Fixed-Length vs. Variable-Length
- Fixed-length records have predictable positions and sizes.
- Fixed-Length Records Every record has the exact same byte size.
- Variable-Length Records Records vary in size due to VARCHAR fields, repeating groups, or nullable fields.
- A. Fixed-Length Records: Structure: Easy to implement.
- Handling Deletions:
- Shift Records: Move all subsequent records up by one slot (Expensive!).
- Free List (Linked List of Deleted Slots): Overwrite the deleted record with a pointer to the next deleted slot.
- B. Variable-Length Records & Slotted-Page Architecture: In modern relational databases (PostgreSQL, Oracle, MySQL InnoDB), records vary in length because of columns like
VARCHAR(255).
View diagram · Fixed vs. Variable Length Record Architectures View diagram · Slotted-Page Block Architecture
Spanned vs. Unspanned Records
- What happens when a single record is larger than the physical block size (or when a record does not fit in the remaining space of a block)?
- Unspanned Organization Records are NEVER allowed to cross block boundaries.
- Spanned Organization A large record is split across two or more blocks connected by physical disk pointers.
- Detailed Comparison: Unspanned: Simpler, faster.
- Spanned: Essential when a record size exceeds the block size (e.g., storing images, large documents, or massive tables with 100+…
View diagram · Spanned vs. Unspanned Storage Schemes
Input/Output Management: Double Buffering
- When an application reads a large database file sequentially (like computing total payroll over 1,000,000 rows):
- Single Buffering: CPU waits while disk block 1 is read.
- Double Buffering: The DBMS allocates two memory buffer frames (Buffer A and Buffer B):
- While the CPU is busily processing data in Buffer A, the disk controller is simultaneously streaming the NEXT block into Buffer B…
- Once CPU finishes Buffer A, it immediately switches to Buffer B without waiting, while the disk starts filling Buffer A!
- CPU computation and disk I/O are completely overlapped, doubling data throughput!
File Organization Methods: Heap, Sequential, ISAM, and Direct Addressing
Overview: A heap file makes it cheap to append a new receipt.
What is File Organization?
- A database file is stored physically on disk as a collection of records divided into blocks.
- Heap File Organization (Unordered)
- Sequential File Organization (Ordered)
- Indexed-Sequential File Organization (ISAM)
- Direct / Relative File Organization
Heap File Organization (Pile / Unordered Files)
- In a Heap File, records are placed on disk in the exact chronological order in which they were inserted—with zero sorting or ordering:
- When a new record arrives, it is appended to the very end of the file (or placed in the first available empty slot found in the free list).
- Advantages Lightning fast insertions : O(1) time complexity.
- Disadvantages Extremely slow searches : Requires a linear full-table scan through every single block (O(N) time complexity).
- Best Used For: Bulk data logging, audit trails, and initial batch data loading.
View diagram · Characteristics of Heap File Organization
Sequential File Organization (Ordered Files)
- In a Sequential File, records are stored physically on disk in sorted order based on the value of a specific field called the **Ordering…
- Advantages: Binary Search Capability: Searching for a record by its ordering key can be done using Binary Search over the disk blocks:
- Search Time Complexity =
Log2(b) block transfers(wherebis total number of blocks). - Ideal for Sequential Processing: Perfect for generating sorted reports or batch processing (like computing payroll for all employees in employee ID order).
- Disadvantages: Painful Insertions and Deletions: Inserting a new record into the middle of a sorted file requires shifting all subsequent records down!
- Solution: Maintain a separate Overflow File (unsorted heap file) for new insertions, and periodically merge it back into the main…
Indexed-Sequential File Organization (ISAM)
- Indexed-Sequential Access Method (ISAM) combines the rapid range-scanning benefits of sequential files with the lightning-fast random search…
- Dense Index vs. Sparse Index: Dense Index: An index entry appears for every single search-key value (every single record in the data file).
- Advantage: Faster to confirm whether a record exists without touching the data block.
- Disadvantage: Larger index file size.
- Sparse Index: An index entry appears for only the first record of each data block (Block Anchor).
- Advantage: Extremely small index file that easily fits completely inside fast RAM!
- Disadvantage: Requires reading the data block to find the exact target record.
View diagram · Indexed-Sequential File Architecture
Multi-Level Indexing and B/B+ Trees Overview
- When a database table grows to millions of rows, even the sparse index file becomes too large to fit in RAM!
- Multi-Level Indexing: Treats the primary index as a data file, and builds an outer index on top of it.
- B-Trees and B+ Trees: Self-balancing multi-level search tree structures used in virtually all commercial database systems (MySQL InnoDB,…
Direct (Relative / Random) File Organization
- In Direct File Organization, records can be accessed directly at any arbitrary position without scanning earlier records and without…
- How Does Direct Addressing Work?: Uses a mathematical formula or Hash Function
h(k)applied directly to the record’s primary keyk: - Search Time Complexity: Theoretically O(1) (a single disk I/O read!).
- Drawback: Sequential range scans (
WHERE Age BETWEEN 20 AND 30) are impossible because adjacent records are scattered randomly across…
Comprehensive Comparison Table of File Organizations
- Record Arrangement: Random insertion order
- Search by Key: Slow: Linear scan
O(N) - Insertion Speed: Fastest: O(1)
- Range Queries: Terribly slow
- Storage Overhead: Zero extra overhead
Database Hashing: Static vs. Dynamic Hashing (Extendible & Linear)
Overview: With four buckets and h(k) = k mod 4, keys 6 and 10 both land in bucket 2.
What is Hashing in Databases?
- In tree-based indexing (like B+ Trees), finding a record requires traversing multiple levels from root to leaf, which takes multiple disk block…
- The hash function takes a primary key
K(likeRoll_No = 1045) as input and directly computes the physical disk address (or **Bucket…
Fundamental Hashing Terminology
- Bucket: A unit of disk storage (typically one disk block or cluster of blocks) that can hold multiple records.
- Hash Function
h(K): A mathematical function that maps the large search key space into a fixed range of bucket numbers `{0, 1, 2, … - Hash Collision: Occurs when two distinct search keys produce the exact same bucket address (
h(K1) = h(K2)). - Bucket Overflow: Occurs when a bucket is completely full of records and a new record hashing to that same bucket arrives.
Collision and Overflow Resolution in Static Hashing
- In Static Hashing, the total number of buckets
Mis fixed during database creation. - 1. Open Addressing (Linear Probing) If bucket i is full, the engine linearly scans subsequent buckets ( i+1, i+2…
- 2. Separate Chaining (Overflow Chaining) If bucket i is full, an auxiliary Overflow Bucket is allocated and linked via a physical pointer.
- Drawbacks of Static Hashing: If Database Grows Too Large: Buckets become overfilled, overflow chains become very long, and search performance degrades from
O(1)down to linear… - If Database Shrinks Too Small: Large numbers of allocated disk buckets sit completely empty, causing massive wasted disk space.
- Reorganization Penalty: Resizing the hash table requires re-hashing every single record in the entire database!
View diagram · Collision Resolution Techniques
Dynamic Hashing (Extendible Hashing)
- To overcome the rigid limitations of static hashing, Dynamic Hashing allows the number of buckets to grow and shrink dynamically as records…
- Key Concepts in Extendible Hashing: Global Depth (
d): The number of prefix bits from the binary hash value currently used by the directory. - Local Depth (
d'): Each individual physical bucket has its own local depthd'indicating that all keys in that bucket share the samed'… - Always:
Local Depth (d') <= Global Depth (d). - How Bucket Splitting Works in Extendible Hashing: Suppose a bucket overflows:
- Case 1: If
Local Depth (d') < Global Depth (d): - We do NOT need to double the directory!
- We simply allocate one new bucket on disk.
View diagram · Extendible Hashing Architecture
Linear Hashing Overview
- Linear Hashing is another form of dynamic hashing that allows the hash file to grow incrementally:
- Unlike Extendible Hashing, Linear Hashing does NOT require a Directory!
- Buckets are split in a systematic linear round-robin order (
Bucket 0, Bucket 1, Bucket 2...) whenever the file storage utilization… - Avoids the sudden directory doubling memory spikes of Extendible Hashing.
Comprehensive Comparison: Static vs. Dynamic Hashing
- Number of Buckets: Fixed at database creation time
- Directory Usage: No directory needed
- Handling Overflows: Long overflow chains degrade performance
- Disk Space Efficiency: Poor (wastes empty buckets or overfills)
- Reorganization: Requires periodic full table re-hashing
- Complexity: Simple to implement