Database Storage Part 1
https://15445.courses.cs.cmu.edu/fall2022/slides/03-storage1.pdf
数据库常见分层结构:
Disk based Architecture
存储层次结构:
一些新式存储
- Persistent Memory:非易失的内存
- Fast Network Storage:RDMA
常见存储访问时间
DBMS System Design Goals
- DBMS 可以管理超过内存容量的数据(页表换入换出机制)
- 读写磁盘代价高,DBMS 需要避免性能降级
- 随机访问要慢于顺序访问,DBMS 最大化顺序读写
Disk-Oriented DBMS
DBMS 为什么不使用 memory mapping
DBMS 需要管理数据在磁盘和内存之间的流动
使用 OS 的 memory mapping 机制(
mmap
)存在的问题:
- Transaction Safety(事务安全)
- I/O Stalls(DBMS 不知道哪些页在内存中,会导致更多的 page fault)
- Error Handling(需要更多的错误处理,SIGBUS)
- TLB Shootdowns
memory mapping 一些其他函数:
mdavise
:Tell the OS how you expect to read certain pagesmlock
:Tell the OS that memory ranges cannot be paged outmsync
:Tell the OS to flush memory ranges out to diskDBMS 控制内存换入换出会比 OS 更好:
Link to original
- 写脏页时可以以正确的顺序写入
- 预读
- Buffer replacement policy
- Thread scheduling
File Storage
- DBMS 将数据库存储为磁盘上的一个或多个文件(特定格式)
- 存储管理器(Storage Manager)负责维护数据库文件
Database Pages
Link to original
- 一个 Page 是指一个固定长度的数据块
- 可以包含 tuple,meta-data, indexes, log records
- 大部分 DBMS 不会混合页类型
- 一些数据库要求 page 是 self-contained
- 每个 page 都有唯一的页号
- 对 Page 的不同定义:
- Hardware Page (4KB),保证原子写
- OS Page(4KB)
- Database Page(512B - 16KB)
Page Storage Architecture
Page Storage Architecture
Link to original
- Heap File Organization
- Tree File Organization
- Squential / Sorted File Organization
- Hashing File Organization
Database Storage Part 2
https://15445.courses.cs.cmu.edu/fall2022/slides/04-storage2.pdf