注:机翻,未校。
The Origin of SQLite, the World’s Most Widely-Used Database
SQLite 的起源,世界上使用最广泛的数据库
Jul 11th, 2021 6:00 am by David Cassel
Photos of the USS Oscar Austin by U.S. Navy via Creative Commons. Photo of Mitchell Baker by Joi via Creative Commons.
Last week Adam Gordon Bell brought a special guest onto his podcast Corecursive: Richard Hipp, the main author of SQLite.
Adam Gordon Bell 在他的播客 Corecursive 上带来了一位特别嘉宾:SQLite 的主要作者 Richard Hipp。
Dev invented the most popular database, SQLite, to eliminate server risk on a US battleship. Motorola wanted to license it for phones, so he gave them the biggest $ figure he could think of: $80K 😂 https://t.co/9B7qpGDGSx
Dev 发明了最流行的数据库 SQLite,以消除美国战舰上的服务器风险。摩托罗拉想将其授权用于手机,因此他给了他们他能想到的最大 $ 数字:$80K 😂 https://t.co/9B7qpGDGSx— Manish Vij (@vijmn) July 3, 2021
— 马尼什·维伊 (@vijmn) July 3, 2021
Two decades ago, while building software for a Navy destroyer, he led the creation of a new open source database to overcome the glitches he encountered. Then Google came calling.
20 年前,在为一艘海军驱逐舰开发软件时,他领导创建了一个新的开源数据库,以克服他遇到的故障。然后谷歌打来了电话。
In a little more than two decades, it’s become the most widely deployed database in the world, according to the official webpage at SQLite.org — partly due to its simplicity. Because it’s contained in a library of C code, SQLite can be easily embedded into other software, and it’s fully self-contained. “Unlike most other SQL databases, SQLite does not have a separate server process,” its official page explains. “SQLite reads and writes directly to ordinary disk files.”
根据 SQLite.org 的官方网页,在二十多年的时间里,它已成为世界上部署最广泛的数据库——部分原因是它的简单性。因为它包含在 C 代码库中,所以 SQLite 可以很容易地嵌入到其他软件中,并且它是完全独立的。“与大多数其他 SQL 数据库不同,SQLite 没有单独的服务器进程,”其官方页面解释说。“SQLite 直接读取和写入普通磁盘文件。”
But crucially, it’s also open source, which leads Bell’s podcast to an intriguing question: What happens if your fun side project ends up powering the world? And the host promises that, along the way, the interview will explore the dilemma which still haunts the open source movement today: How to survive becoming core infrastructure for the world.
但最重要的是,它也是开源的,这让 Bell 的播客提出了一个有趣的问题:如果你的有趣的业余项目最终为世界提供了动力,会发生什么?主持人承诺,在这个过程中,采访将探讨今天仍然困扰着开源运动的困境:如何成为世界的核心基础设施。
Bell points out that SQLite is now installed in everything from web browsers to commercial airplanes, as well as popular software like iMessage and WhatsApp.
Bell 指出,SQLite 现在安装在从网络浏览器到商用飞机的所有软件中,以及 iMessage 和 WhatsApp 等流行软件中。
But the software was born out of Hipp’s frustration with a database that was installed on a battleship.
但该软件的诞生源于 Hipp 对安装在战舰上的数据库的不满。
‘Can’t Connect to Server’ “无法连接到服务器”
The story begins in a shipyard in Bath, Maine (population: 8,329). Back in the year 2000, Hipp was working for Bath Iron Works, a shipbuilding subsidiary of defense contractor General Dynamics, and was building software for a Navy destroyer (the USS Oscar Austin). The software would operate on crucial data about the ship’s valves (for routing around pipe ruptures), and their stack had included Informix, which unfortunately stopped working whenever the server went down.
故事始于缅因州巴斯(人口:8,329)的一家造船厂。早在 2000 年,Hipp 就在国防承包商 General Dynamics 的造船子公司 Bath Iron Works 工作,并为海军驱逐舰(USS Oscar Austin)构建软件。该软件将对有关船舶阀门的关键数据进行操作(用于绕过管道破裂),他们的堆栈包括 Informix,不幸的是,每当服务器出现故障时,它就会停止工作。
“That was embarrassing,” Hipp recalled to Bell. “A dialog box would pop up, they’d double click on the thing, and a dialog box would pop up that says, ‘Can’t connect to database server.’ It wasn’t our fault — we didn’t have any control over the database server. But what do you do if you can’t connect to the server? So we got the blame all the same, because we were painting the dialog box.”
“那太尴尬了,”Hipp 对 Bell 回忆道。“会弹出一个对话框,他们会双击这个东西,然后会弹出一个对话框,上面写着’无法连接到数据库服务器’。”这不是我们的错 — 我们对数据库服务器没有任何控制权。但是,如果无法连接到服务器怎么办?所以我们还是受到了指责,因为我们在操作对话框。
And, as Hipp noted, “it’s a warship.” So besides the ship being continually in use, “the idea is it’s supposed to be able to work if you take battle damage! So it’s more than one pipe breaking. There’s going to be a lot of stuff broken, and people are going to be crazy, and there’s going to be smoke and blood and chaos — and in a situation like that they don’t want a dialog box that says, ‘Cannot connect to database server.‘”
而且,正如 Hipp 所指出的,“这是一艘军舰”。因此,除了这艘船持续使用之外,“我们的想法是,如果你受到战斗伤害,它应该能够工作!所以这不仅仅是一次管道破裂。会有很多东西被破坏,人们会发疯,会有烟雾、血腥和混乱 — 在这样的情况下,他们不希望出现一个对话框,上面写着’无法连接到数据库服务器’。
Hipp wondered if there was a way his team could pull its data straight from the database without an external dependency. “I looked around and there were no SQL database engines that would do that, and one of the guys I was working with says, ‘Richard, why don’t you just write one?‘” During a temporary shutdown of government contracts (which had lasted a few months), “I was out of work for a few months, and I thought, ‘Well, I’ll just write that database engine now.’”
Hipp 想知道是否有一种方法可以直接从数据库中提取数据,而无需外部依赖。“我环顾四周,没有 SQL 数据库引擎可以做到这一点,与我共事的一个人说,'Richard,你为什么不写一个呢?'在政府合同暂时关闭期间(持续了几个月),“我失业了几个月,我想,'好吧,我现在就编写那个数据库引擎吧。
Back in 2006, Hipp tried to explain SQLite’s appeal to an audience at Google. “Most people hear SQL database engine, and they’re thinking Oracle — something big that you run your whole enterprise on. SQLite is sort of the opposite of that — it tries to be very small, so it’s very compact.” In fact, fully configured, at the time it was less than 250 kilobytes. And it was also serverless — and designed to be embedded within larger applications.
早在 2006 年,Hipp 就试图向 Google 的受众解释 SQLite 的吸引力。“大多数人听到 SQL 数据库引擎后,他们会想到 Oracle — 您运行整个企业的大型产品。SQLite 有点与此相反 — 它试图变得非常小,因此非常紧凑。事实上,完全配置后,当时它的大小不到 250 KB。它也是无服务器的,旨在嵌入到更大的应用程序中。
But the story of SQLite also shows how initiative and dedication can pay off — and how nothing can stop a determined developer. Later in his interview at Corecursive.com, Hipp recalled looking for a reference on how to write an SQL database engine — and not finding one.
但 SQLite 的故事也展示了主动性和奉献精神如何得到回报——以及没有什么能阻止坚定的开发人员。后来在 Corecursive 的采访中,Hipp 回忆说,他正在寻找有关如何编写 SQL 数据库引擎的参考资料,但没有找到。
“So I just had to kind of invent it myself,” he said. “It was a completely independent invention.”
“所以我只能自己发明它,”他说。“这是一项完全独立的发明。”
For instance, Hipp remembers referring to Donald Knuth’s The Art of Computer Programming for an implementation of a search algorithm. While theoretical underpinnings might’ve been taught at MIT, Harvard, or the University of California-Berkeley, “if you didn’t go to one of those three schools, you didn’t even know this body of theory existed, and there wasn’t a real good way to find it.”
例如,Hipp 记得曾参考 Donald Knuth 的 The Art of Computer Programming 来实现搜索算法。虽然麻省理工学院、哈佛大学或加州大学伯克利分校可能已经教授过理论基础,但“如果你没有去过这三所学校中的任何一所,你甚至不知道这个理论体系的存在,也没有真正好的方法来找到它。
Years later he learned that nonetheless, both SQLite and Postgres had converged on the same ideas.
多年后,他了解到,尽管如此,SQLite 和 Postgres 都采用了相同的想法。
Ironically, back at the shipyard, Hipp’s higher-ups still insisted on using Informix, Hipp tells Bell (although his team did use SQLite for their testing). But in addition, “I put it out there on the internet and other people started picking it up.” Soon Hipp was surprised by the uptake — including one user who’d bragged they now had an SQL database engine running on their Palm Pilot. “It really attracted a lot of attention, and that encouraged me to work on it.”
具有讽刺意味的是,回到造船厂,Hipp 的上级仍然坚持使用 Informix,Hipp 告诉 Bell(尽管他的团队确实使用 SQLite 进行测试)。但除此之外,“我把它放到了互联网上,其他人开始接受它。很快,Hipp 就对这种采用感到惊讶,包括一位吹嘘他们现在在 Palm Pilot 上运行 SQL 数据库引擎的用户。“它确实吸引了很多关注,这鼓励了我继续努力。”
Ringing Phones 电话响铃
Hipp’s website still proudly points out that SQLite won a 2005 Google O’Reilly Open Source Award. But that was the only acclaim that SQLite received. Back in 2006, Hipp told his audience at Google that “it’s public domain, so lots of people are using it that I don’t know about” — but confirmed users included Apple and PHP. (At one point both General Electric and Toshiba had contacted him requesting the U.S. export control number for SQLite — though he never found out why.)
Hipp 的网站仍然自豪地指出 SQLite 获得了 2005 年 Google O’Reilly 开源奖。但这是 SQLite 获得的唯一赞誉。早在 2006 年,Hipp 就告诉他在 Google 的听众,“它是公共领域的,所以很多人都在使用它,但我不知道”——但已确认的用户包括 Apple 和 PHP。(通用电气和东芝都曾一度联系他,要求提供 SQLite 的美国出口管制编号——尽管他从未找到原因。
But soon Hipp confronted another theme that haunts most open source developers: monetization. Hipp told the Corecurisve podcast that very early on, he’d received a phone call from Motorola, who’d wanted to include SQLite in its operating system for cellphones. “Of course, inside, I was like, ‘What? You can make money with open source software? How does this work? How do I price this?” Hipp said. “I have no idea how to do this.'”
但很快,Hipp 就遇到了另一个困扰大多数开源开发人员的主题:货币化。Hipp 告诉 Corecurisve 播客,他很早就接到了摩托罗拉的电话,摩托罗拉希望将 SQLite 包含在其手机操作系统中。“当然,在内心深处,我就想,'什么?您可以通过开源软件赚钱吗?这是如何工作的?我该如何定价?“希普说。“我不知道该怎么做。”
But fortuitously, he’d brought in three people who’d worked on the original SQLite, “and that was sort of the beginning.”
但幸运的是,他带来了三个从事原始 SQLite 工作的人,“这算是个开始。
The next call he fielded was from America Online, which wanted to use an SQLite database on the free-trial CDs it was sending in the mail to prospective users. And soon there was a call from Symbian (which made the operating system on Nokia phones). The company had tested 10 different database systems — two open source, and seven more proprietary. But even after giving the other vendors a chance to fine-tune their systems, SQLite still won the competition. Hipp recalled, “We cut a contract to do some development work for them.”
他接到的下一个电话来自 America Online,该公司希望在邮寄给潜在用户的免费试用 CD 上使用 SQLite 数据库。很快,Symbian 打来了电话(Symbian 是 Nokia 手机的操作系统的制造商)。该公司测试了 10 种不同的数据库系统,其中 2 个是开源的,另外 7 个是专有的。但是,即使在给其他供应商一个微调系统的机会之后,SQLite 仍然赢得了比赛。Hipp 回忆说:“我们签订了一份合同,为他们做一些开发工作。
This led to an important development, when Symbian asked them to increase their “bus factor,” which Hipp describes as “the number of people who have to be hit by a bus in order to stop all development work… They felt like the bus factor at SQLite was too low.” Symbian’s solution? It helped fund the SQLite Consortium, which Hipp said is “a way of funding the project and getting more people involved to guarantee that it was going to be available long term.”
这导致了一个重要的发展,当 Symbian 要求他们增加他们的“公交系数”时,Hipp 将其描述为“为了停止所有开发工作而必须被公交车撞到的人数…他们觉得 SQLite 的总线系数太低了。Symbian的解决方案是什么?它帮助资助了 SQLite 联盟,Hipp 表示这是“为项目提供资金并让更多人参与以保证它将长期可用的一种方式”。
But he also gives a lot of credit to Mitchell Baker (pictured), who was then the CEO of the Mozilla Foundation (and a lawyer by training). She’d reached out, and as he remembers it, insisted that “the developers have to be in control. Their decision is final… The companies that are using, they get the honor of contributing money, but you make all the decisions. She was very adamant about this and she laid out everything.”
但他也给了 Mitchell Baker(如图所示,当时是 Mozilla 基金会的首席执行官,同时也是一名律师)很多赞誉。她主动联系了他,据他回忆,她坚持说:“开发者必须掌握控制权。他们的决定是最终的……使用这些公司的,他们有贡献资金的荣誉,但所有的决定都由你们来做。她对此非常坚决,并且详细地解释了这一切。”
In the end, Mozilla and Adobe joined Symbian in funding the group, and to this day Hipp expresses gratitude for all the early support. “it’s been such an amazing journey… we would not be in this situation were it not for these circumstances.
最终,Mozilla 和 Adobe 加入 Symbian 为该小组提供资金支持,时至今日,Hipp 对所有早期的支持表达了感激之情。“这是一段如此精彩的旅程…… 如果不是这些情况,我们不会处于现在的位置。”
When Google Calls 当 Google 调用
Soon all major smartphones were using SQLite, Adam explains — and soon Richard fielded a phone call from Google, “before Android was a thing. This was before iPhone.”
Adam 解释说,很快所有主流智能手机都开始使用 SQLite,随后 Richard 接到了一个来自 Google 的电话——“在 Android 还未问世之前。这还是在 iPhone 之前。”
This led the project to another key open source lesson about the value of testing. “It’s amazing how many bugs will crop up when your software suddenly gets shipped on millions of devices,” Hipp told Bell.
这让该项目获得了另一个关于测试价值的重要开源课程。“当你的软件突然在数百万台设备上发布时,会出现多少错误,这真是令人惊讶,”Hipp 告诉 Bell。
He spent a whole year generating tests to cover every single branch operation in the resulting binary code, he said. He’d had hopes of selling the test suite to avionics manufacturers — but while they never landed any customers, when it came to reports of bugs in Android, “it made a huge, huge difference. We just didn’t really have any bugs for the next eight or nine years.”
他说,他花了一整年的时间来生成测试,以涵盖生成的二进制代码中的每个分支操作。他曾希望将这个测试套件卖给航空电子制造商——尽管他们从未签下任何客户,但当涉及到 Android 中的错误报告时,“它产生了巨大的、巨大的影响。在接下来的八到九年里,我们实际上几乎没有遇到过任何错误。”
As a result, he said, “It did work out really well for us in that it keeps our product really solid and it enables us to turn around new features and new bug fixes very fast.”
因此,他说:“这对我们来说确实效果非常好,因为它使我们的产品非常稳定,它使我们能够非常快速地推出新功能和新错误修复。
The details are pretty impressive. “We’ll have a test case but it’ll be parameterized, so that one test case might run 100, 1,000, 100,000 tests, just by looping, by changing one of the parameters.” For a typical release, Hipp estimated that there’s on the order of 100,000 distinct test cases — and billions of tests. “We have a checklist and we will run tests for at least three days prior to a release.”
细节令人印象深刻。“我们将有一个测试用例,但它将被参数化,因此一个测试用例可以运行 100、1,000、100,000 次测试,只需通过循环,通过更改其中一个参数。”对于一个典型的版本,Hipp 估计大约有 100,000 个不同的测试用例和数十亿个测试。“我们有一个清单,我们将在发布前至少运行三天的测试。”
Corecursive’s interview closed with Hipp’s own inspiring advice to others who want to create impactful open source software. “I had this crazy idea that I’m going to build a database engine that does not have a server, that talks directly to disk, and ignores the data types,” he said. “And if you asked any of the experts of the day, they would’ve said, ‘That’s impossible. That will never work. That’s a stupid idea.’
Corecursive 的采访以 Hipp 自己对其他想要创建有影响力的开源软件的人的鼓舞人心的建议结束。“我有一个疯狂的想法,我要构建一个没有服务器的数据库引擎,它直接与磁盘通信,并且忽略数据类型,”他说。“如果你问当时的任何一位专家,他们都会说,'这是不可能的。那永远不会奏效。这是个愚蠢的主意。
Fortunately, I didn’t know any experts — and so I did it anyway.”
幸运的是,我不认识任何专家——所以我还是做了。
SQLite: Past, Present, and Future
文 / 约修亚
Chief Huyou Officer
SQLite 是一个非常轻量级的嵌入式数据库,并且已经广泛使用在手机、电脑、浏览器等各种设备中。不过,SQLite 原本的定位是快速的在线事务处理 (online transaction processing - OLTP),其主要的执行设计基于行,存储设计基于 B-tree。然而,近年来随着数据分析的愈发流行,对在线分析处理 (online analytical process - OLAP) 的需求也越来越强烈。那么,原本为了 OLTP 设计的 SQLite 可以直接用于 OLAP 的场景吗?如果不能的话,差距是多大,我们又可以做哪些方面的改进呢?这里,我们就来聊聊发表在 VDLB 2022 上的一篇论文:SQLite: Past, Present, and Future.
SQLite: Past, Present, and Future 阅读笔记
看论文标题,我们就能知道这篇论文大概是讲 SQLite 的过去、现在、和将来的。首先作者们对 SQLite 做了一系列历史性的回顾和对现在功能架构的介绍。SQLite的主要优势有
- 跨平台 (Cross-platform)。SQLite 本身存储在一个单独文件中,所以可以很容易的在各个平台上使用。
- 简洁和自我包含 (Compact and self-contained)。SQLite 本身只是一个文件,也没有任何其他的依赖。
- 可靠 (Reliable)。SQLite 中的每一行代码都有超过 600 行代码来测试。
- 快速 (Fast)。SQLite 可以支持每秒上万次的事务处理。
由于 SQLite 设计用于 OLTP 的场景,SQLite 使用了基于行的存储结构,也就是说对于一行的所有列都是存储在相邻的内存结构中。SQLite 的算子也是基于行 (row-oriented) 的,并没有使用常用于 OLAP 的向量化计算。为了适用于 OLTP,SQLite 提供了 ACID 支持。而 ACID 在 OLAP 场景中一般是不需要的。
SQLite的整体架构如上图所示。Core 模块负责注入和执行 SQL 语句。SQL Compiler 模块把 SQL 语句翻译成可以在虚拟机中执行的字节码程序。Backend 模块和操作系统交互来实现数据的存储和页的使用。Accessories 模块则包含了诸如内存分配、字符串操作、测试等等各种辅助功能。
SQLite 对事务的支持有两种模式:
- 回滚模式 (Rollback mode)。在事务处理中,SQLite 把原本的页写入到回滚日志中并且把修改的页写入到数据库文件中。该模式同时支持 DELETE 和 TRUNCATE 两种子模式。
- 预写式日志模式 (Write-ahead log mode)。在事务处理中,不修改原本的页而是把修改的页追加写到单独的预写式日志文件中。
预写式日志模式可以支持更高的并发度并且常常有更好的性能。但是相较于回滚模式,预写式日志模式不能用于网络文件系统并会增加整体文件管理的复杂度。
说了这么多SQLite的优势,那么SQLite可以直接用于OLAP的场景吗?会有多少的性能劣势呢?论文中,作者们比较了SQLite 和 DuckDB (昵称 SQLite for analytics) 在 OLTP、OLAP、和 blob I/O 三个场景下的性能,并比较了它们的资源消耗。
1 OLTP
首先,作者们用 TATP benchmark 比较了 SQLite-WAL、SQLITE-DELETE、和 DuckDB 在 OLTP 场景下的性能。结果如下图所示。可以看出,无论是云服务器还是树莓派,SQLite 在 OLTP 场景下性能都显著的优于 DuckDB。当然这也是可以预见的,毕竟 SQLite 就是为了 OLTP 场景设计的,而 DuckDB 则是为了 OLAP。
2 OLAP
那么在 OLAP 的场景下呢?SQLite 和 DuckDB 分别表现又如何呢?下图是在 SSB 测试集下的结果。从图中可以看出,DuckDB 对数据分析型查询的性能要远优于 SQLite。当然,类似于上面的 OLTP 场景下的对比,这个结果也是可以预见的。毕竟 SQLite 的设计并不是为了大规模的数据查询。
既然 SQLite 在 OLAP下表现不佳,那么有没有什么方法能帮助我们改善呢?SQLite 对于 OLAP 场景的性能瓶颈又在哪里呢?论文中,作者们对查询的执行进行了性能剖析,发现了 SeekRowid 和 Column 两个指令花费了绝大部分时间。SeekRowid 指令用于搜索一个给定 row ID 的对应 B-tree 索引。Column 指令用于提取给定行中的具体某一列。针对这两个性能瓶颈,作者们提出了两种优化方法:
- 避免无谓的 B-tree 查询 (Avoiding unnecessary B-tree probes)
- 流水线化值的提取 (Streamlining value extraction)
对于第一种方法,作者们使用了一个布隆过滤器 (Bloom filter) 来首先判断给定的一个键值是否在列中存在。比如下图就是一个例子。
具体的实现方法是作者们在 SQLite 的虚拟指令集中增加了两个新的指令:FilterAdd 和 Filter。 FilterAdd 计算哈希值并在布隆过滤器中设置相应的位 (bit)。Filter 指令计算哈希值并在布隆过滤器中检查对应的位是不是已经被设置了。作者们发现仅仅是这样一个简单的优化就给 SQLite 在 OLAP 场景下的性能带来了巨大的飞跃,如下图所示。
那么对于第二种方法流水线化值的提取呢?这种方法效果又如何呢?SQLite 使用了灵活的数据类型,换言之除了主键必须是整数之外,其他任何数据都不需要是固定类型的,也不需要提前指定类型。基于这种设计方式,去提取一个值,SQLite 必须先得到一个指向被编码的值的指针。这种设计方法使得作者们很难流水线化值的提取,并且作者们在探索中也发现这种流水线化值的提取需要修改 SQLite 中的文件存储格式使之易于向量化。最终,作者们并没有实现这种方法。
3 Blob I/O
文章作者们发现 SQLite 在业界也常用于块数据的存储 (blob data store)。那么 blob 类型的数据对 SQLite、DuckDB、和文件系统有多少性能的差异呢?他们特别开发了一个基于 blob 数据的测试集。这个测试集提供了不同比例的读写操作。总体来看,在云服务器上,SQLite-WAL 模式可以获得比较好的性能。而在树莓派上,DuckDB 有比 SQLite-WAL 类似或略好的性能。
4 资源消耗
作者们比较的最后一个维度是资源的消耗 (Resource footprint)。总体来看,SQLite 需要更少的资源去编译,而 DuckDB 需要更少的空间来存储数据 (主要因为采用列式存储易于压缩)。
这篇文章回顾了 SQLite 的设计、开发、以及在实际中的应用,并且介绍了几种可以提高 SQLite OLAP 场景下性能的方法。我主要有三点印象颇为深刻:
- 第一就是我们只需要一些简单的方法,譬如用布隆过滤器来减少 B-tree 的查询就可以非常明显的提高 OLAP 场景下的性能。换言之,找到性能的瓶颈之后,很多看似简单的方法实际上可以带好非常好的效果。
- 其次是 SQLite 尽管设计定位于传统的 OLTP 场景,但目前实际上也常常用于小文件的存储。但是 SQLite 在小文件上读写上的性能却不一定总是优秀的。这需要我们更多的探索和实验。
- 最后是怎样更好得提高 SQLite 在 OLAP 场景下的性能同时尽量减少或者完全不影响 OLTP 场景下的性能呢?目前一种流行的方法是在 SQLite 中另实现一个独立的、但能和 SQLite 本身相互的查询引擎。这个新的查询引擎中可以设计单独的针对分析型数据查询优化的功能。当前这种方法已经被 SQLite3/HE 使用。但更多的方法还需要进一步的研究和探索!
发布于 2022-09-25 02:31
我开发了世界上最流行的软件,并把 100% 的公司股份送给了老婆!
原创 码农翻身刘欣
世界上使用最广泛的软件是哪个?
Windows ? Android? Office ?
都不对!
答案是 SQLite !
你可能没听说过它,但是它就在你身边的:
每一台智能手机中(Android 和 iOS)
每一台 Mac 电脑中
每一台 Windows 10 电脑中
每一个主要的浏览器中(Chrome, Firefox, Safari)
大部分的机顶盒当中
每个 PHP 和 Python 安装目录中
很多流行的桌面应用 (微信、QQ、 DropBox、 Skype、 iMessage、WhatsApp、 Adobe Acrobat Reader…)
…
不信的话可以在电脑中搜索一下 “*.db”,看看能发现多少个。
这个流行的软件,就是我, Richard Hipp 开发的。
每个流行的软件都是为了解决一个痛点问题,SQLite 也不例外。
故事要从 2000 年说起,当时我在为美国海军的一个驱逐舰开发软件,这个软件要对船上所有的阀门进行管理和操作。
当时,美国海军使用的是 IBM 的 Informix 数据库,我写的软件需要通过网络访问它来读取数据。
但是有时候 Informix 所在的服务器会挂掉,阀门管理软件就会报错:不能连接到服务器!
海军对我的冤枉不算什么,但是驱逐舰是要上战场的,打仗时如果受到损害网络不通怎么办?难道我的软件就不能用了吗?
当时纽特・金里奇和比尔・克林顿正在 “打架”,所以所有政府合同都暂停执行,所以我失业了几个月。
没事可干, 我决定把这个嵌入式数据引擎给写出来。
市面上的数据库基本上都是 Client-Server 架构的, 它的特点是这样:
但是我想写的嵌入式数据库则是进程内通信,直接从本地硬盘中读取文件,非常快
换句话说,每个程序都可以拥有一个本地的数据库。
可是我并不是一个数据库专家, 只是在大学中学过一个数据库课程而已。
没办法,我只好去图书馆中借书,学习。
开发软件肯定要选一门编程语言,我选择伟大的 C 语言!
确定了语言,我开始做一些重要的系统设计,首先是如何存储数据。
其次是应用程序如何访问 SQLite
当我在实现 SQL 层的时候,需要阅读 SQL 标准,我发现 SQL 标准太繁杂了。
万般无奈之下,我只好去看 PostGres 的文档,作为处理 SQL 语句的参考。
最终的结果是, SQLite 和 Postgres 的命令行有点像!
SQLite 第一版本很快写出来了,但是具有讽刺意味是,造船厂居然不用,他们还坚持使用 Informix!
那就开源吧!我把它放到一个网站上,满心期望引起世界的关注。
一年过去了,事情的发展往往不能如愿。
平心而论,SQLite 第一个版本并不是真正的关系型数据库,而是一个 Hashing-based 数据库。
我决定重写,实现 B+ Tree 存储引擎
2001 年,911 事件发生不久, SQLite v2 问世了。
很快,我接到了手机巨头摩托罗拉的电话
我没有想到,开源也能赚钱,这一单生意, 我赚了 8 万美元。
随后, 巨无霸 AOL 也抛来了橄榄枝。
2005 年,当时的手机老大诺基亚也来了, 他们也想为手机找个数据库。
他们很谨慎,找了 10 个数据库做横向对比测评,最后 SQLite 轻松胜出。
SQLite 被用的越来越多,发展势头越来越好。
只不过 SQLite 的开发者主要是我,这让客户有点担心
而我的 SQLite ,Bus Factor 等于 1!怪不得客户着急了。
为了保证 SQLite 能长期的发展下去,需要更多业界人士参与 SQLite 开发, 客户希望我建立一个 SQLite 联盟。
在 Mozilla 基金会的负责人米切尔・贝克的帮助下,Mozilla、 Symbian、Adobe 成为了联盟的初始成员
SQLite 重新进入了发展的快车道,2005 年,一个叫 Android 的东西向我抛来了橄榄枝。
这玩意儿可编程性、可调试性非常强,并且操作系统很容易更新,每天都可以更新几次。
Android 最早期的原型机是这样的。
我意识到这是个爆炸性的东西, 但是出于保密协议,我没法通知诺基亚和摩托罗拉它们。
它们将被智能手机无情地碾压。
这时候我的 SQLite 数据库已经很火爆了,我的软件咨询公司不得不雇佣了几个人来做技术支持。
我对自己的代码非常自信, 天真地四处吹嘘 SQLite 没有任何严重 Bug,但是当它发布到海量的移动设备上时,潜藏的 Bug 出现了。
这对我的自尊心造成了很大的伤害,我决心把 SQLite 的质量提上去。达到航空电子设备的质量!
而航空电子设备的质量至少要实现 MC/DC 这个苛刻的标准 !
我开始编写测试,达到 100% 的 MC/DC , 这花了我一年的时间,每周 60 个小时!这真是非常、非常、非常艰难的工作。
实际上,想达到 95% 的覆盖率并不是特别难,但是剩下的 5% 实在是太难了。
艰苦的付出获得了极为丰厚的回报, 从那以后,Android 再也不找我麻烦了。
我付出了艰苦的努力,让 SQLite 成了世界上最流行的数据库。
这一切都很难,但是和说服 Ginger G. Wyrick 嫁给我相比,SQLite 不算什么。
Ginger 是一个音乐家和作家,美丽又才华横溢。
我很爱她,一结婚就把公司名称变成了 Hipp, Wyrick & Company, 并且把公司所有的股份送给了她。
这个公司只有两个人,她是 CEO 和 COO, 而我,则是唯一的程序员。
最后,总结一下 SQLite 为什么能成功吧。
首先,它是一个可靠的、稳定的数据库,对事务的支持,让它在应用崩溃时也不会丢失任何数据。这比你自己操作 XML,JSON 等文件要可靠得多。
其次,它可以轻松地嵌入到任何语言写的系统中。
最后,它开箱即用,非常简单!
via:
-
The Origin of SQLite, the World’s Most Widely-Used Database - The New Stack Jul 11th, 2021 6:00 am by David Cassel
https://thenewstack.io/the-origin-story-of-sqlite-the-worlds-most-widely-used-database-software/
-
SQLite: Past, Present, and Future - 知乎
-
SQLite: past, present, and future: Proceedings of the VLDB Endowment: Vol 15, No 12
-
我开发了世界上最流行的软件,并把 100% 的公司股份送给了老婆!原创 码农翻身刘欣 码农翻身 2024 年 08 月 14 日 08:55 安徽