数据库系统:实现

数据库系统:实现

2025 南京大学《操作系统原理》
数据库系统:实现

Databases v.s. Compilers

实现查询 = 实现编译优化 (语义等价的 rewriting)

center

2025 南京大学《操作系统原理》
数据库系统:实现

一个超级复杂的并发程序

每个 SQL 都操作数据库的一部分

  • Write(x)
  • Read(y)
    • 用于维护 “磁盘上的数据结构
    • 类似文件系统,write-ahead logging (crash consistency)

但并发控制更困难

  • T1T_1: txbegin; x = 1; sleep(100000); y = 2; commit
  • T2T_2: txbegin; y = 1; sleep(100000); x = 2; commit
    • Transactions 不能用 lock/unlock 实现
2025 南京大学《操作系统原理》
数据库系统:实现

例子:SQLite

center

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day. More Information...

  • Android, iOS, macOS, Chrome, ... 中广泛内嵌了 SQLite
    • Zero Configuration (发行版自带 libsqlite3.so;适合 “年轻人的第一个应用”)
2025 南京大学《操作系统原理》