# SQLite recovery copies: a rebuilt file can preserve a stale computation

**Result.** In our two recorded SQLite builds, a completed backup, VACUUM INTO,
and a compatible-schema INSERT SELECT * each carried forward an existing stale
STORED generated value. The destination passed integrity_check. The same paths
also copied an inconsistent VIRTUAL-column index, which full checking detected.
An explicit projection of ordinary input columns recomputed the value and index.

This is not a claim that backup creates corruption, or that current SQLite still
allows the historical BLOB mutation used to prepare the inputs. A copy can
faithfully preserve an already inconsistent state. The contribution is a tested
distinction between raw record transfer and expression evaluation, including
the surprising fact that a SQL INSERT can take the raw-transfer path.

## Why this extends the existing corpus

[Hesela's runtime-dependency analysis](https://hesela.com/analyses/sqlite-index-runtime-dependencies/)
already shows that changed application callbacks and stored computations can
disagree. It also contrasts a backup with replaying one particular SQL dump.
That result does not establish what every SQL-to-SQL copy does.

The adjacent [derived-value experiment](../derived/REPORT.md) supplies a different
input: unchanged built-in hex(), with a base BLOB altered through the older
incremental API. The [backup acceptance analysis](https://hesela.com/analyses/backup-verification-is-not-a-restore-test/)
separates intact copies from application recovery. This continuation connects
the three: **neither the word rebuild nor the presence of INSERT establishes
that generated values were recomputed.**

No new public article or near-duplicate glossary entity is proposed. These
results belong next to the existing stored-column and recovery-method sections.

## Construction and observations

Each fresh temporary database contains two rows, with four-byte payloads AAAA
and CCCC. The final column is derived AS (hex(payload)), tested separately as
STORED and VIRTUAL, with and without an index on derived. The untouched second
row is a control.

The recorded system build, SQLite 3.45.1, changes the first byte of row 1 to B
through the native incremental BLOB API. Open, write, close and COMMIT must all
succeed. Separate SQL UPDATE inputs perform the same payload change while
maintaining the derivation. No raw database bytes are patched.

After the writer closes, either retained build processes each source into a
fresh destination. Both builds then reopen that destination read-only. We
record complete ordered rows, independent equality checks, forced index/scan
answers, checker results, native return codes, SQL and query bytecode.

The table shows the indexed historical-BLOB inputs. Both processors (3.45.1 and
3.54.1) and both source journal settings produce these answers. The current
payload is 42414141. Hexadecimal strings here are encodings, not cryptographic
hashes. The expected new-value index answer is row 1.

| Copy path | STORED derived text | STORED integrity | VIRTUAL new-value index query | VIRTUAL integrity |
| --- | --- | --- | --- | --- |
| Backup API | 41414141 | ok | no row | index mismatch |
| VACUUM INTO | 41414141 | ok | no row | index mismatch |
| INSERT SELECT * | 41414141 | ok | no row | index mismatch |
| Explicit input columns | 42414141 | ok | row 1 | ok |
| SELECT * WHERE 1 (control) | no rows (rejected) | ok | no row | ok |

The last row is deliberately **not** a successful copy: the attempted INSERT
fails and leaves an empty table. Its ok integrity result does not certify
completeness. Every positive SQL UPDATE seed remains consistent after each of
the four successful copy methods.

The native matrix has 160 configurations: two processors, two source journal
settings, two generated-column kinds, index present/absent, two seed operations,
and five copy/control statements. There are 128 completed copies and 32 expected
rejections. Of those designed successful copies, 24 retain a STORED mismatch
and 12 retain a VIRTUAL index mismatch. These counts describe this constructed
matrix, not population failure rates. Two retained captures agree exactly
except their timestamps.

## Backup completion and semantic acceptance are separate

For each backup, sqlite3_backup_step(-1) returns SQLITE_DONE (101), remaining
pages reaches zero, and sqlite3_backup_finish returns SQLITE_OK (0). We record
two source pages without an index and three with one. This establishes the
bounded copy sequence's completion, not a derivation invariant.
[Native backup contract](https://sqlite.org/c3ref/backup_finish.html)

For STORED, the old generated text and its index agree with each other, but not
with hex(payload). For indexed VIRTUAL, a table scan evaluates the current
payload while the index still selects the old answer. Full checking reports an
index mismatch in that case; quick_check returns ok. We check the equation and
both query paths instead of substituting one checker for all three.
[Generated-column contract](https://sqlite.org/gencol.html),
[checker scopes](https://sqlite.org/pragma.html#pragma_integrity_check)

## Why VACUUM and one INSERT preserve the old answer

The official VACUUM documentation promises a compact copy with the source's
logical content, not an application-specific repair.
[VACUUM INTO](https://sqlite.org/lang_vacuum.html#vacuuminto)

The reviewed VACUUM implementations first create corresponding tables and
indexes, then copy their contents with INSERT SELECT *. The INSERT implementation
has a compatible-schema transfer optimization that moves existing table and
index records. Matching generated-column types and expressions are checked;
re-evaluating each stored answer is not the purpose of that transfer.
[3.45.1 VACUUM source](https://raw.githubusercontent.com/sqlite/sqlite/version-3.45.1/src/vacuum.c),
[3.54.1 VACUUM source](https://raw.githubusercontent.com/sqlite/sqlite/version-3.54.1/src/vacuum.c),
[3.45.1 INSERT source](https://raw.githubusercontent.com/sqlite/sqlite/version-3.45.1/src/insert.c),
[3.54.1 INSERT source](https://raw.githubusercontent.com/sqlite/sqlite/version-3.54.1/src/insert.c)

Our standalone star-transfer bytecode contains raw-record operations and no
PureFunc expression evaluation. The explicit-column control contains hex(1)
evaluation instead. Together with the source review, this supports the
mechanism behind the observed contrast. We do not claim to trace every
internal VACUUM opcode or to establish identical behavior for all builds.

These are the two successful SQL controls, with recovered.objects already
created using the matching schema and, where applicable, matching index:

```sql
INSERT INTO recovered.objects SELECT * FROM main.objects;

INSERT INTO recovered.objects(id,payload,label)
SELECT id,payload,label FROM main.objects NOT INDEXED;
```

The second supplies only the ordinary inputs. It rebuilds this fixture's derived
answer and associated index without changing the source. It is not a generic
migration recipe for schemas with triggers, foreign keys, custom functions,
collations, unique conflicts or additional database objects.

## A no-op filter is not a substitute for an explicit projection

Appending WHERE 1 to the star transfer causes both builds to reject it:
the destination has three insertable columns but four values are supplied.
The generated column contributes to SELECT *, but is not ordinarily writable.

This makes the transfer qualification observable: a seemingly harmless SQL
change can remove the special transfer path, yielding an error, not automatic
recomputation. We retain the failed EXPLAIN and INSERT results, plus the empty
destination and unchanged source. Do not classify a structurally valid but
empty destination as a restored database.

## Prevention is not repair

The earlier packet documents 3.54.1 rejecting incremental BLOB opens on tables
with generated columns. It also attributes the relevant 2024 maintainer report.
Our new processing runs start from old-build inputs; we do not attempt the same
mutation with the newer build or present it as newly affected.
[Maintainer history](https://sqlite.org/forum/forumpost/cc82420f4cac4142),
[newer BLOB guard](https://raw.githubusercontent.com/sqlite/sqlite/version-3.54.1/src/vdbeblob.c)

The newer processor still copies the existing values and index entries in these
paths. Preventing the creation of another inconsistent record does not certify
previously stored images, nor select an application's intended repair policy.

## Reproduction, provenance and limits

observations-a.json and observations-b.json retain all cases; findings.json
points to individual records, and table.md is generated from validated output.
The separate validator specifies expected states, return codes and matrix
membership. A fresh test run reproduces the complete matrix. Mutation controls
ensure altered answers, incomplete backups, missing cases and missing source
identities cannot pass acceptance.

Ten primary-source receipts record URLs, retrieval times, status, size and
SHA-256 without redistributing the documents. Engine source IDs, exact library
hashes, compile options, Python/platform identities and harness hashes are in
the captures. Source tags explain behavior; a distribution-patched binary is
not claimed to be byte-identical to its upstream tag.

All databases are synthetic, disposable and closed before copying. DELETE and
WAL are source settings; this is **not** concurrent live-WAL copying. Source
main-file hashes remain unchanged across processing and all read-only
inspections. Each destination is inspected with both libraries, but this is
cross-build observation by one harness, not independent researcher replication.

No crash, power interruption, hardware failure, prevalence estimate, performance
benchmark, security exploit, new defect or exact first-fixed release is claimed.
The deterministic built-in expression deliberately excludes runtime callback
drift. A two-row example cannot establish universal restoration safety.

The practical acceptance question is specific: must this copy preserve stored
history, or recompute designated expressions from trusted inputs? Preserve the
original, make that policy explicit, retain the exact copy procedure and
runtime, and compare expected rows and consumer queries on a disposable output.
