Professional Documents
Culture Documents
03 Storage1
03 Storage1
Part I
ADMINISTRIVIA
U P C O M I N G D ATA B A S E E V E N T S
Kinetica Talk
→ Thursday Sep 6th @ 12pm
→ CIC 4th Floor
SalesForce Talk
→ Friday Sep 7th @ 12pm
→ CIC 4th Floor
Relational AI Talk
→ Wednesday @ Sep 12th @ 4:00pm
→ GHC 8102
CMU 15-445/645 (Fall 2018)
4
OVERVIEW
COURSE OUTLINE
D I S K- O R I E N T E D A R C H I T E C T U R E
STORAGE HIERARCHY
Faster
CPU Registers Smaller
CPU Caches
Volatile
Random Access
Byte-Addressable DRAM
Non-Volatile SSD
Sequential Access
Block-Addressable
HDD
Slower
Network Storage Larger
CMU 15-445/645 (Fall 2018)
7
STORAGE HIERARCHY
Faster
CPU Registers Smaller
CMU 15-721 (Spring 2019)
CPU Caches
Memory DRAM
SSD
Disk HDD
Slower
Network Storage Larger
CMU 15-445/645 (Fall 2018)
7
STORAGE HIERARCHY
Faster
CPU Registers Smaller
CMU 15-721 (Spring 2019)
CPU Caches
Memory DRAM
Non-volatile Memory
SSD
Disk HDD
Slower
Network Storage Larger
CMU 15-445/645 (Fall 2018)
8
ACCESS TIMES
On-Disk File
CMU 15-445/645 (Fall 2018)
11
On-Disk File
CMU 15-445/645 (Fall 2018)
11
On-Disk File
CMU 15-445/645 (Fall 2018)
11
On-Disk File
CMU 15-445/645 (Fall 2018)
11
On-Disk File
CMU 15-445/645 (Fall 2018)
11
of memory. page4
On-Disk File
CMU 15-445/645 (Fall 2018)
12
D ATA B A S E S T O R A G E
T O D AY ' S A G E N D A
File Storage
Page Layout
Tuple Layout
FILE STORAGE
STORAGE MANAGER
D ATA B A S E PA G E S
D ATA B A S E PA G E S
1KB
There are three different notions of
"pages" in a DBMS:
→ Hardware Page (usually 4KB)
→ OS Page (usually 4KB) 4KB
→ Database Page (1-16KB)
16KB
CMU 15-445/645 (Fall 2018)
21
PA G E S T O R A G E A R C H I T E C T U R E
D ATA B A S E H E A P
H E A P F I L E : PA G E D I R E C T O R Y Page
Data
The DBMS maintains special pages
that tracks the location of data pages Directory
Page
in the database files.
Data
The directory also records the number
of free slots per page.
…
Page
The DBMS has to make sure that the
directory pages are in sync with the Data
data pages.
CMU 15-445/645 (Fall 2018)
27
T O D AY ' S A G E N D A
File Storage
Page Layout
Tuple Layout
PA G E H E A D E R
Page
Every page contains a header of meta-
Header
data about the page's contents.
→ Page Size
→ Checksum
→ DBMS Version Data
→ Transaction Visibility
→ Compression Information
PA G E L AYO U T
Two approaches:
→ Tuple-oriented
→ Log-structured
TUPLE STORAGE
Page
How to store tuples in a page?
Num Tuples = 0
Strawman Idea: Keep track of the
number of tuples in a page and then
just append a new tuple to the end.
TUPLE STORAGE
Page
How to store tuples in a page?
Num Tuples = 30
Strawman Idea: Keep track of the Tuple #1
number of tuples in a page and then Tuple #2
just append a new tuple to the end.
Tuple #3
TUPLE STORAGE
Page
How to store tuples in a page?
Num Tuples = 230
Strawman Idea: Keep track of the Tuple #1
number of tuples in a page and then
just append a new tuple to the end.
→ What happens if we delete a tuple? Tuple #3
TUPLE STORAGE
Page
How to store tuples in a page?
Num Tuples = 30
Strawman Idea: Keep track of the Tuple #1
number of tuples in a page and then Tuple #4
just append a new tuple to the end.
→ What happens if we delete a tuple? Tuple #3
TUPLE STORAGE
Page
How to store tuples in a page?
Num Tuples = 30
Strawman Idea: Keep track of the Tuple #1
number of tuples in a page and then Tuple #4
just append a new tuple to the end.
→ What happens if we delete a tuple? Tuple #3
→ What happens if we have a variable-
length attribute?
S L O T T E D PA G E S
Slot Array
The most common layout scheme is
called slotted pages. Header
S L O T T E D PA G E S
Slot Array
The most common layout scheme is
called slotted pages. Header
LO G -S T R U C T U R E D F I L E O R G A N I Z AT I O N
Page
Instead of storing tuples in pages, the
DBMS only stores log records. INSERT id=1,val=a
New Entries
INSERT id=2,val=b
…
attributes that were modified.
LO G -S T R U C T U R E D F I L E O R G A N I Z AT I O N
Page
To read a record, the DBMS scans the
log backwards and "recreates" the INSERT id=1,val=a
Reads
DELETE id=4
…
CMU 15-445/645 (Fall 2018)
33
LO G -S T R U C T U R E D F I L E O R G A N I Z AT I O N
Page
To read a record, the DBMS scans the
log backwards and "recreates" the INSERT id=1,val=a
…
CMU 15-445/645 (Fall 2018)
33
LO G -S T R U C T U R E D F I L E O R G A N I Z AT I O N
Page
To read a record, the DBMS scans the
log backwards and "recreates" the id=1,val=a
id=2,val=b
tuple to find what it needs. id=3,val=X
id=4,val=Y
Build indexes to allow it to jump to
locations in the log.
LO G -S T R U C T U R E D C O M PA C T I O N
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File Log File Log File Log File Log File
LO G -S T R U C T U R E D C O M PA C T I O N
Compaction
Level 0 Log File Log File Log File Log File Log File Log File
Sorted Sorted
Sorted Log File
Log File Log File
Level 2 Sorted Log File
T O D AY ' S A G E N D A
File Storage
Page Layout
Tuple Layout
T U P L E L AYO U T
TUPLE HEADER
Tuple
Each tuple is prefixed with a header Header Attribute Data
that contains meta-data about it.
→ Visibility info (concurrency control)
→ Bit Map for NULL values.
T U P L E D ATA
Tuple
Attributes are typically stored in the Header a b c d e
order that you specify them when you
create the table.
CREATE TABLE foo (
a INT PRIMARY KEY,
This is done for software engineering b INT NOT NULL,
reasons. c INT,
d DOUBLE,
We re-order attributes automatically e FLOAT
in CMU's new DBMS… );
D E N O R M A L I Z E D T U P L E D ATA
D E N O R M A L I Z E D T U P L E D ATA
foo
Can physically denormalize (e.g., "pre Header a b
join") related tuples and store them
together in the same page.
→ Potentially reduces the amount of I/O for
common workload patterns. bar
→ Can make updates more expensive. Header c a
Header c a
Header c a
D E N O R M A L I Z E D T U P L E D ATA
foo
Can physically denormalize (e.g., "pre Header a b c c c …
join") related tuples and store them
together in the same page. foo bar
→ Potentially reduces the amount of I/O for
common workload patterns.
→ Can make updates more expensive.
D E N O R M A L I Z E D T U P L E D ATA
foo
Can physically denormalize (e.g., "pre Header a b c c c …
join") related tuples and store them
together in the same page. foo bar
→ Potentially reduces the amount of I/O for
common workload patterns.
→ Can make updates more expensive.
RECORD IDS
CONCLUSION
NEXT CLASS
Value Representation
Storage Models