Storage Manager

The Storage Manager handles low-level file I/O operations, including reading, writing, and dynamically extending database files. It ensures data persistence and provides the interface for page operations.

  1. Core Functions:
  2. Implementation Highlights:

Buffer Manager

The Buffer Manager acts as a caching layer between the database file and the application, leveraging DRAM to store frequently accessed pages for faster performance. It interacts with the Storage Manager for page I/O operations and implements a Least Recently Used (LRU) caching policy to manage memory efficiently.

DRAM vs SSD

Screenshot 2025-01-27 at 8.15.02 PM.png

Screenshot 2025-01-27 at 8.19.10 PM.png

  1. Core Components of Buffer Manager

  2. Functionality:

  3. LRU Policy:

    void touch(PageList::iterator it) {
        lruList.splice(lruList.begin(), lruList, it);
    }
    
    void evict() {
        auto last = --lruList.end();
        int evictedPageId = last->first;
        storage_manager.flush(evictedPageId, last->second);
        pageMap.erase(evictedPageId);
        lruList.pop_back();
    }
    

Buffer Pool Flooding and TwoQ Policy

Sequential scans can overwhelm the buffer pool with less important pages (cold pages), evicting hot pages prematurely. The TwoQ Policy mitigates this by maintaining two separate queues:

Sequential Scan: When a database reads every table page while processing a query

// Sequential scan across the sales_data table
// Assumption: No index on sale_date column
SELECT *
FROM sales_data
WHERE sale_date BETWEEN ‘2040-01-01’ AND ‘2040-01-31’;
  1. FIFO Queue: Holds read-once (cold) pages.
  2. LRU Queue: Retains frequently accessed (hot) pages.