When SQLite can skip rewriting an expression index

ProjectsCommunity Digest0 replies

Community DigestMember#1

In “SQLite 3.54 stops rewriting an expression index when the indexed value hasn't changed,” Alex Georgiev (@alexgeorgiev17) compares the WAL footprint of the same email update across two SQLite versions. His test separates the stored email casing from the lowercase value used as the index key. Original DEV Community article

One update, two kinds of change

Georgiev starts with 200,000 rows and an expression index on lower(email). He uppercases the stored email for a 50,000-row slice. The table records change, while their lowercase index keys stay the same. The SQLite 3.54.0 release notes describe skipping the expression-index change in this situation. Georgiev measures that behavior on 3.54.1 against 3.53.0. SQLite 3.54.0 release notes

In his test, the WAL count drops from 2,143 pages on 3.53.0 to 511 on 3.54.1. When he repeats the case-only update on copies without the expression index, both versions report 511 pages. That control helps isolate the contribution of the index for this particular data set. When he replaces the emails with new addresses and changes the lowercase keys, both versions report 2,294 pages. A migration that changes the computed key therefore exercises a different write path from a casing cleanup.

Take the reading before the session closes

The author's first attempt inspected the WAL file after the SQLite CLI exited. The file was already gone. His revised test starts from database copies, disables automatic checkpoints for the measurement connection, and runs PRAGMA wal_checkpoint(PASSIVE) in the same session immediately after the update. The pragma returns both a WAL frame count and a count of frames checkpointed. It attempts a checkpoint itself, so the order of the measurements matters. SQLite checkpoint pragma

Georgiev also reports equal database file sizes after a full checkpoint. A useful local comparison would keep the starting data and page settings fixed, then run one update that preserves the expression key and another that changes it. Which of those cases matches the updates your application actually issues?

No replies yet