编程与软件工程jvns.ca
SQLite 是如何工作的?
How Does Sqlite Work? (2014)
2014 — 2020,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Julia Evans 2014 年'SQLite 是如何工作的'系列第一篇,她通过亲手剖析数据库文件的字节内容,讲解 SQLite 如何以'页'为单位在磁盘上组织数据。文章延续她一贯的动手实验风格,把数据库内部机制讲得直观易懂,续篇第二部分则深入 B 树。
为什么经久不衰:SQLite 无处不在,而这篇文章把晦涩的数据库存储原理拆解成人人可以跟着做的实验,多年后仍是理解数据库内部机制的经典入门。
HN 评论精选
SQLite 的页面存储源于 1979 年的 B-树经典论文,几乎所有关系数据库都沿用这一结构。
数据存储的细节在 Douglas Comer 1979 年的论文《The Ubiquitous B-Tree》中就有描述。自它发明以来基本没什么变化:几乎所有关系型数据库都在使用这种结构的某种变体。我也写过相关文章,或许有助于理解它的工作原理。
gtrubetskoy查看英文原文
The details of how the data is stored are described in this 1979 paper by Douglas Comer: "The Ubiquitous B-Tree" [1]. Since it was invented, much hasn't really changed: practically all relational databases use some variation of this structure. I wrote about it in [2], which might help explain some aspects of how it works. [1] https://dl.acm.org/doi/10.1145/356770.356776 [2] https://grisha.org/blog/2013/05/11/relational-database-on-top-of-key-value-store-explained/ Edit: also [3] is about how to store SQLite in a Redis hash (rather than on-disk file). [3] https://grisha.org/blog/2013/05/29/sqlite-db-stored-in-a-redis-hash/
建议阅读 src/ 下的独立模块而非合并的 sqlite3.c,并指出引擎核心是执行 SQL 的虚拟机。
SQLite 代码模块划分清晰,构建也很快。探索代码库更简单的办法是阅读 src/ 下的各个独立模块,而不是打开过于庞大、难以驾驭的合并版 sqlite3.c。据我所知,数据库引擎的核心是一个处理解析后 SQL 的虚拟机,用调试器单步跟踪必然会进入执行语句的那个循环。此外 sqlite.org 上有大量设计文档。
zoomablemind查看英文原文
The SQLite code is nicely split into modules, and builds together reatively quickly. So the easier way to explore the codebase is to load into editor the individual modules at src/ rather than the aggregated sqlite3.c file which is too big and unmanageable in the editor. IIRC, the heart of the db engine appears to be some sort of vm that processes the parsed out SQL. Stepping through in debugger will inevitably capture you in the loop which executes the statements. Of course, there're plentiful design docs, all on https://sqlite.org.
推荐同类嵌入式数据库 DuckDB,它面向分析型负载而非事务型负载。
有人看过 DuckDB 吗?和 SQLite 一样,它是带 C API 的嵌入式关系数据库,甚至提供与 SQLite 相同 API 的封装。但它针对分析型而非事务型负载优化——适合少量大查询,而不是大量小读写。
twic查看英文原文
Anyone looked at DuckDB [1]? Like SQLite, it's an embedded relational database with a C API. In fact, it has a wrapper which presents the same API as SQLite [2]. But it's optimised for analytical rather than transactional work - a few huge queries rather than lots of little reads and writes. [1] https://duckdb.org/ [2] https://github.com/cwida/duckdb/tree/master/tools/sqlite3_api_wrapper
赞赏作者动手实验、亲自验证的写作风格,而非照本宣科。
我很欣赏 Julia Evans 乐于在编程中动手实验,并能把这种乐趣传递给读者。相比许多只是读书、常常不加批判地'相信'书面文字的从业者,这让人耳目一新。
acqq查看英文原文
I really appreciate how Julia Evans enjoys experimenting in programming and how she can carry that to her readers. That's so refreshing, compared to so many practitioners who just read the books and often uncritically "believe" the written texts.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选