More instances of SQLite are used every day, by more people, than all other database engines combined. An yet, SQLite does not get much attention. Many developers hardly know anything about it. This session will review the features of SQLite, how it is different from other database engines, its strengths and its weaknesses, and when SQLite is an appropriate technology and when some other database engine might be a better choice.
5. used in....
● Every Android device (~2 billion)
● Every Mac and iOS device (~1 billion)
● Every Win10 machine (~500 million)
● Every Chrome and Firefox browser (~2 billion)
● Every Skype, iTunes, WhatApp (~2 billion)
● Millions of other applications
● Many billions of running instances
● 100s of billions, perhap trillions, of databases
6. More Copies of Than...
● Linux
● Windows
● MacOS and iOS
● All other database engines combined
● Any application
● Any other library¹
¹except maybe zLib
7.
8. One File Of C-code
sqlite3.c
● 204K lines
● 125K SLOC¹
● 7.2MB
Also: sqlite3.h
● 10.7K lines
● 1.5K SLOC
● 0.5MB
¹SLOC: “Source Lines Of Code” - Lines of code
not counting comments and blank lines.
11. Single File Database
● One file holds
thousands of tables,
indexes, and views
● Space efficient
● Send a complete
database as an email
attachment
● Name it whatever you
like.
whatever.db
12. Open File Format
● sqlite.org/fileformat.html
● Cross-platform
– 32-bit ↔ 64-bit
– little-endian ↔ big-endian
● Backwards-compatible
● Readable by 3rd-party
tools
13. Faster Than The Filesystem
● 35% faster reads and writes
● 20% less disk space
● https://sqlite.org/fasterthanfs.html
35% faster
than
open()
read()
close()
14. Faster Than The File System
https://sqlite.org/fasterthanfs.html
SQLite android ubuntu mac win7 win10
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
6.0
Time
Time to read 100,000 BLOBs with average size of 10,000 bytes
from SQLite versus directly from a file on disk.
15. Faster Than The File System
https://sqlite.org/fasterthanfs.html
Time to write 10,000 BLOBs with average size of 10,000 bytes
from SQLite versus writing directly into a file on disk.
SQLite ubuntu mac win7 win10
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
time
16.
17. Documentation
● Hundreds of pages of stand-alone HTML
– Extensively hyperlinked
– Downloadable as a single tarball
● Source code is 29% comment
– Useful comments, not boilerplate
● Thousands of assert() statements
● Test cases linked to documentation
● More documentation than source code
18. Aviation-Grade Testing
● DO-178B development process
● 100% MC/DC, as-deployed, with independence
results
in
● Very few bugs
● Refactor and optimize without breaking things
https://sqlite.org/testing.html
22. Limits
● 140 terabytes per database
● 125 databases per connection
● 2 gigabyte strings & BLOBs
● 64 tables in a join
● 32,767 columns per table
● 1 simultaneous writer + N readers
● No arbitrary limits on the number of tables or
the number of rows in a table
17.5 petabytes
per connection
28. File Format
● Row-store
● Variable-length records
● Forest of B-trees
– One B-tree for each table and each index
– Table key: PRIMARY KEY or ROWID
– Index key: indexed columns + table key
● Stable, cross-platform, byte-order independent, and
carefully documented
● SERIALIZABLE, power-safe transactions
29. Ins & Outs of
Compile SQL
into bytecode
Bytecode
InterpreterSQL Prep'ed
Stmt
Result
B-Tree
Storage Engine
31. Business Model
● Technical support contracts
– Annual maintenance subscription
– Technical support
– SQLite Consortium membership
● Proprietary extensions
– Encryption
– Compression
● Keep expenses very low
If the software is free, how do we get money to live?
Primary
Revenue
Source
32. The Future
● Support through 2050
● 5 or 6 releases per year
● Keep it stable, backwards-compatible, free, and
organic
● Constantly improving query planner
● Better performance