High Performance
SQLite
Introduction
Introduction to this course
Introduction to SQLite
SQLite is safe
It's just a file
Running SQLite locally
Good uses for SQLite
SQLite's limitations
The documentation
SQLite Internals
SQLite's structure
SQLite's file format
Dot commands
Pragmas
Virtual tables
Schema
Flexible types
Types
Strict types
Dates
Booleans
Floating point
Rowid tables
Auto increments
Without rowid
Generated columns
Optimizing SQLite
Locking
Rollback mode
WAL mode
WAL vs Journal benchmarks
Busy timeout
Transaction modes
Vacuum
Analyze & Optimize
Suggested pragmas
Faster inserts
Indexes
Introduction to indexes
B+ trees
Primary, secondary, and clustered indexes
Without rowid tables
Benchmarking without rowid tables
Imposter tables
Primary key data types
Where to add indexes
Index selectivity
Composite indexes
Composite ordering
Covering indexes
Partial indexes
Indexes on expressions
Automatic indexes
Duplicate indexes
Indexing joins
Advanced SQL
Explain
Index obfuscation
Joins
Subqueries
Unions
CTEs
Recursive CTEs
Window functions
Dealing with NULLs
Row value syntax
Indexed sorting
Upserts
Returning
Aggregates
Triggers
Operating SQLite
Altering schema
Altering schema with tools
Multi-database
Multi-tenancy
Backups
Exports
How to corrupt SQLite
Advanced JSON
Intro to JSON
JSON vs. JSONB
Argument types: path, value, JSON
JSON5
Valid JSON
Creating JSON objects + arrays
JSON Extraction
Updating JSON
JSON aggregates
JSON table functions
Indexing JSON
Full Text Search
Creating FTS tables
Performing searches
Ranking results
Highlighting matches
Bonus Interviews
DHH discusses SQLite in Ruby on Rails
Distributed SQLite with Litestream and LiteFS
Offline-first, multiplayer SQLite
Production SQLite with Turso and libSQL
Migrating from Postgres to SQLite with Kent C. Dodds
Ruby on Rails with SQLite
Moving from Redis to SQLite with Mike Buckbee
Next video (8)
SQLite Internals
SQLite's structure

Full Course

$
179
$229
USD, one-time fee
It's a really well-structured course that helped me understand the intricacies of SQLite through short and easy-to-grasp videos. The content is on point, non-opinionated, thoughtfully presented, and has good real-life applicability. Thanks to Aaron and the team!
Viacheslav Azarov
Viacheslav Azarov

SQLite for Production

Build with and integrate SQLite into your production applications.

Test Data

I've made my test data available for you to use and follow along.

Download
or
Use on Turso

Summary

Get a foundational overview of how SQLite works under the hood, including how it compiles SQL queries into bytecode using its virtual machine. You'll learn about core components like the query planner, btrees for structured data storage, and the pager module that handles page-level data access. The video also covers SQLite’s VFS (Virtual File System), which enables seamless cross-platform interaction with different operating systems.

Video Transcript

In this module, we're gonna look a little bit at the internals of SQLite. Don't worry, we're not gonna go too deep and we're not just doing it because it's fun, although it is fun. We're doing it because this base level knowledge is going to serve as our foundation as we move forward and help us, talk about some of the higher level things. It's really tempting to just learn the higher level stuff without taking the time to learn just a little bit of what's going on under the hood.

I think our higher learning, our higher level learning is going to be more effective if we understand a little bit of what's going on under the hood. In this video we're gonna talk about the structure of SQLite, the library, then we'll look at the file format and some extensions. We'll look at some other stuff. The SQLite library has a very well defined structure. It starts on the very outside with the interface and then below that is this SQL command processor.

One of the things that is most interesting about SQLite is they take your they take your SQL query and then they turn it into bytecode. They have the tokenizer, the parser, and the code generator. All that works together to turn it into bytecode that is then executed by a virtual machine inside of SQLite. The entire virtual machine is one C file and it takes that byte and executes those instructions. Over here in the code generator lives a super important part of any database and that is the query planner.

It's made up in in SQLite of a couple of different parts, but generally speaking, this is where the query planning goes on. A query planner is necessary because when you issue a SQL statement to a database, you're telling it what you're looking for. You're not telling it how to find what you're looking for. It's the database's responsibility to say, alright, well, there might be, 100 of thousands of ways to find the data that they're looking for. There might be millions of ways to find the data that they're looking for.

Which one is best? What's the best way? I'm gonna plan what I think is the best way and that's what this, query planner does over in the code generator area. All of the data in your SQLite database is stored as a b tree, which is, a data structure that we'll cover later, but your tables are a btree, your indexes are btrees, there are separate b trees for every table and every index. This btree module figures out which data it needs and then it makes a request to the pager module and the pager module is what actually pulls the data out in fixed size chunks called pages, which is why they call it the pager module.

The pager module will grab these chunks off of the disc and hand them back to the b tree module. Now the pager module is super important because it handles all the messy details of, writing data to the pages. It handles the atomic commits, it handles the rollbacks, it handles the locking. It handles all of the messy details. Below that is the final part and that is the OS interface.

The OS interface is responsible for, I think you can guess it, talking to the actual operating system. So SQLite has this concept, this abstract concept of a vfs and it's responsible for opening and reading and writing and closing the actual files. Currently there are 2 implementations, one for UNIX systems and one for Windows systems. That is how SQLite, maintains that cross platform compatibility, is they have separate VFS's for each system and you could write your own if you needed to. That is the end of that is the end of the SQLite library itself all the way down to the operating system.

Depending on which system you're using is which vfs you'll be using, but that is responsible for that last part that could be different based on what system that you're on. The most important concepts from this, while it is all interesting, the most important concepts that will continue to come back up regardless of what database you're using, actually. This is generally applicable knowledge, btrees and pages. Those are gonna continue to come up and continue to be very, very important. Throughout the rest of the course, we're gonna dive deeper into those things.

Don't feel don't feel like you're behind if you don't know what those are. That's fine. We needed to introduce the concept at some point and now we have and now we can move on.