Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Turso 3 min read Deep dive mediumAdept

Faster schema changes for large SQLite databases

SQLite re-parses the entire sqlite_schema table after every ALTER TABLE, so schema changes cost time proportional to total schema size even when only one table is touched. Turso, a Rust rewrite of SQLite, adds dedicated bytecode instructions (RenameTable, DropColumn, AddColumn, RenameColumn) that mutate the in-memory schema directly and update only the affected table's indexes in batch. Initial schema loading is also sped up by replacing the lemon-generated parser with a handwritten one, while the in-memory schema is shared across connections so later connections skip parsing entirely.

Assumes: SQLite basicsALTER TABLE semanticsbytecode virtual machines

Related posts

  • How Turso made connections to SQLite databases 575x faster

    Turso mediumAdept

    SQLite re-reads and parses the sqlite_schema table on every new connection, so opening a connection to a database with 10,000 tables takes about 23ms. Turso, a Rust rewrite of SQLite, parses the schema once and shares it across connections in the same process. It uses Arc::make_mut copy-on-write, so a connection only clones the schema when it changes it inside a transaction, and committed changes propagate to all connections. New connections then open in about 40 microseconds no matter how many tables exist, which is faster even than SQLite's 130 microseconds for a single-table database.

  • Change Data Capture in SQLite, Without the Triggers

    Turso mediumAdept

    Turso Database, a Rust rewrite of SQLite, has built-in change data capture enabled with a single PRAGMA. It records every committed insert, update, delete and schema change into a regular `turso_cdc` table with transaction IDs, before/after row images and commit markers, so no triggers or WAL decoding are needed. The post compares this to trigger-based sqlite-cdc, the session extension and update hooks, and lists rough edges: decoding uses the current schema, the change table grows until pruned, and capture is per connection. It ends with a restart-safe polling consumer that groups changes by transaction, advances a watermark only at transaction boundaries, needs an idempotent apply step and prunes against the slowest consumer.

  • Turso Sync: Local-First SQLite with Push and Pull

    Turso mediumAdept

    Turso Sync replaces libSQL's page-based Embedded Replicas with logical row-level changes captured via CDC in Turso Database, a Rust rewrite of SQLite, so reads and writes stay local and apps call push() and pull() explicitly. Shipping logical statements instead of WAL pages lets unrelated writes merge on the server. Experimental partial sync fetches 128 KiB segments on demand, with optional prefetch. Benchmarks show roughly 7–10x speedups and about 15x less data for small-write workloads, but only 1.2x when writes are already batched. Conflicts resolve by last-push-wins, which suits single-writer data but loses updates on shared counters unless data is modeled append-only.

  • Introducing Change Data Capture for SQLite in Turso

    Turso mediumAdept

    Turso's SQLite rewrite gains an unstable, built-in Change Data Capture feature enabled per connection via PRAGMA unstable_capture_data_changes_conn. The pragma logs every insert, update and delete into a regular turso_cdc table with change type, rowid and binary before/after row images, and JSON helper functions decode those images. Four modes (id, before, after, full) trade detail against storage. Decoding uses the current schema, so dropped or added columns can corrupt historical records unless schema versions are tracked manually. Release v0.1.2 also adds Euclidean vector distance, new language bindings, B-tree lookup optimizations and fault-injection and Antithesis testing.

  • How to Deploy Schema Changes to a Million Databases

    Turso mediumAdept

    Database-per-tenant schema migrations can scale to millions of databases by inverting control: a hosted schema registry stores a versioned catalog of SQL scripts, and each client periodically reports its schema version, pulls the missing migrations and applies them locally. The registry needs only a simple migrations table, with no per-tenant state or distributed locks. Check-in timing (before critical operations, daily, or on user workflows) trades consistency against performance. The pull model suits offline-first apps that reconnect several versions behind, and a proof-of-concept is written in Go with SQLite.

The quest for software engineering knowledge.

Look:
Layout: