Notes 03 - Database Storage - I
Notes 03 - Database Storage - I
Yousef M. Elmehdwi
Department of Computer Science
Slides: adapted from a course taught by Andy Pavlo, Carnegie Mellon University
1 / 42
Reading
2 / 42
System Design Goals
3 / 42
Disk-Oriented DBMS Overview
The database is all on disk, and the data in database files is organized
into pages, with the first page being the directory page.
To work this data, the DBMS needs to bring the data into memory.
This is achieved through the utilization of a buffer pool, which manages
the bi-directional transfer of data between the disk and memory.
The execution engine executes queries.
The execution engine requests a particular page from the buffer pool,
which then handles the task of fetching the page into memory.
Subsequently, the buffer pool provides the execution engine with a
memory-based pointer to that requested page.
execution engine a pointer to that page in memory.
The buffer pool manager keeps these pages in memory while the execution
engine operates on them, ensuring efficient data access and manipulation.
4 / 42
Why Not Use the OS?
5 / 42
Database Storage
6 / 42
Today’s Agenda
7 / 42
File Storage
8 / 42
Storage manager
9 / 42
Database Pages
The DBMS organizes the database across one or more files in fixed-size
blocks of data called pages
A page is a fixed-size block of data.
It can contain different kinds of data
tuples, meta-data, indexes, log records, . . .
Most systems do not mix page types within pages.
Some systems require a page to be self-contained.
meaning that all the information needed to read each page is on the page
itself.
Each page is given a unique internal identifier called page id generated by
database system.
To map these page IDs to their physical locations, which include file paths
and offsets, the DBMS employs an indirection layer.
The upper levels of the system will ask for a specific page number.
Then, the storage manager will have to turn that page number into a file
and an offset to find the page.
10 / 42
Database Pages
11 / 42
Database Pages
12 / 42
Database Pages
13 / 42
Database Pages: Hardware Page: Failsafe Write
A hardware page is the largest block of data that the storage device can
guarantee failsafe writes.
The storage device guarantees an atomic write of the size of the hardware
page.
For example, if the hardware page size is 4 KB and the system attempts
to write 4 KB of data to the disk, it’s ensured that either the entire 4 KB
will be successfully written or none of it will be.
When a database page size exceeds the hardware page size, additional
precautions/measures are necessary.
This is because a situation can arise where the system crashes midway
through writing a database page to disk.
In this scenario, the Database Management System (DBMS) needs to take
extra steps to ensure data consistency and reliability during write
operations.
14 / 42
Page Storage Architecture
Within a DBMS, the challenge lies in locating a specific page on the disk
based on its page id.
The DBMS needs a way to find a page on disk given a page id
Various DBMSs adopt distinct strategies for managing pages within disk
files.
15 / 42
Page Storage Architecture
Different DBMSs manage pages in files on disk in different ways.
Some common methods include:
Heap File Organization
This involves storing data pages in an unordered manner.
It’s a straightforward approach where data is appended as it arrives,
without any specific ordering.
Sequential / Sorted File Organization
Data pages are arranged in a sequential or ordered manner based on certain
criteria, such as a primary key.
This can speed up certain types of queries and enable range-based access.
Hashing File Organization
Data pages are distributed across the disk using a hash function.
This aims to evenly distribute data and optimize retrieval through
calculated hash values.
Tree File Organization
Data pages are structured in tree-like structures (such as B-trees or B+
trees) to facilitate efficient search, insertion, and deletion operations.
17 / 42
Heap File: Linked List
However, when the DBMS needs to locate a specific page, it must conduct
a sequential scan across the data page list until the desired page is found.
18 / 42
Heap File: Page Directory
19 / 42
Today’s Agenda
File Storage
Page Layout
What does look like inside the page?
Tuple Layout
20 / 42
Page Header
21 / 42
Page Layout
22 / 42
Tuple Storage
23 / 42
Tuple Storage
24 / 42
Tuple Storage
25 / 42
Tuple Storage
26 / 42
Slotted Pages
The most common layout scheme is called slotted
pages.
Slot array, which keeps track of the location of the
start of each tuple.
A slot array is employed to maintain the starting
position of each tuple on the page.
Each entry in the slot array corresponds to a slot,
mapping to the offset where a tuple begins.
The slot array essentially maps slots to the
offsets where tuples start within the page. This
enables efficient access to specific tuples.
28 / 42
Log-Structured File Organization
29 / 42
Log-Structured File Organization
30 / 42
Log-Structured File Organization
31 / 42
Log-Structured File Organization
32 / 42
Today’s Agenda
File Storage
Page Layout
Tuple Layout
33 / 42
Tuple Layout
34 / 42
Tuple Layout
35 / 42
Tuple Data
36 / 42
Denormalized Tuple Data
37 / 42
Denormalized Tuple Data
38 / 42
Denormalized Tuple Data
The terminology might differ across database systems, but the fundamental
concept of optimizing data organization to improve query efficiency
remains consistent.
39 / 42
Record ID
40 / 42
Conclusion
41 / 42
Next
Value Representation
Storage Models
42 / 42