Volatile Devices:
- Volatile means that if you pull the power from the machine, then the data is lost.
- Volatile storage supports fast random access with byte-addressable locations. This means that the program can jump to any byte address and get the data that is there
- For our purposes, we will always refer to this storage class as “memory.”
Non-Volatile Devices:
- Non-volatile means that the storage device does not require continuous power in order for the device to retain the bits that it is storing.
- It is also block/page addressable. This means that in order to read a value at a particular offset, the program first has to load the 4 KB page into memory that holds the value the program wants to read.
- Non-volatile storage is traditionally better at sequential access (reading multiple contiguous chunks of data at the same time).
- We will refer to this as “disk.” We will not make a (major) distinction between solid-state storage (SSD) and spinning hard drives (HDD).
课上讨论的都是面向磁盘的DBMS
数据库都在磁盘上,数据库文件中的数据被组织成多个页面,第一个页面是目录页面。为了对数据进行操作,DBMS需要将数据放入内存。它通过拥有一个缓冲池(Buffer pool)来实现这一点,该缓冲池管理磁盘和内存之间的数据来回移动。DBMS还具有执行查询的执行引擎。执行引擎将向缓冲池请求特定页面,缓冲池将负责将该页面带入内存,并向执行引擎提供指向内存中该页面的指针。缓冲池管理器将确保当执行引擎在内存的该部分上运行时,页面在那里
We do not advise using mmap in a DBMS for correctness and performance reasons.
Database Pages
DBMS将数据库跨一个或多个文件组织在称为页面的固定大小的数据块中。页面可以包含不同类型的数据(元组、索引等)。大多数系统不会在页面中混合这些类型。一些系统将要求页面是自包含的,这意味着阅读每页所需的所有信息都在页面本身。
每个页面都有一个唯一的标识符。如果数据库是单个文件,则页面id只能是文件偏移量。大多数DBMS都有一个间接层,将页面id映射到文件路径和偏移量。系统的上层将要求指定页码。然后,存储管理器必须将该页码转换为文件和偏移量才能找到该页。
大多数DBMS使用固定大小的页面,以避免支持可变大小页面所需的工程开销。例如,对于可变大小的页面,删除页面可能会在文件中创建漏洞,DBMS无法轻松用新页面填充。
在DBMS中有三种类型的pages:
- Hardware page (usually 4 KB).
- OS page (4 KB).
- Database page (1-16 KB).
Database Heap
有几种方法可以找到DBMS想要的页面在磁盘上的位置,堆文件组织就是其中之一。堆文件是无序的页面集合,其中元组以随机顺序存储。
- Linked List:Headers包含指向空闲页列表和数据页列表的指针。但是,如果DBMS正在查找特定页面,它必须对数据页面列表进行顺序扫描,直到找到它正在查找的页面。
- Page Directory:DBMS维护特殊页面,跟踪数据页面的位置以及每个页面上的可用空间量。
Page Layout
每个页面都包含一个Header,用于记录有关页面内容的元数据
• Page size.
• Checksum.
• DBMS version.
• Transaction visibility.
• Self-containment. (Some systems like Oracle require this.)
Page Layout
- Slotted Pages
- Log-Structured
Tuple Layout
元组本质上是一个字节序列。DBMS的工作是将这些字节解释为属性类型和值。
Tuple Header:包含关于元组的元数据
- DBMS并发控制协议的可见性信息(即关于哪个事务创建/修改了该元组的信息)。
- 空值的位图
- DBMS不需要在此处存储关于数据库模式的元数据
Tuple Data:属性的实际数据
- 属性通常按创建表时指定的顺序存储。
- 大多数数据库管理系统不允许元组超过页面大小。
Unique Identifier
- 数据库中的每个元组都分配了一个唯一标识符。
- 最常见的:page_id + (offset or slot)
- 应用程序不能依赖这些ID来表示任何内容。