# VACUUM can detach a healthy FTS5 index from its documents

Hesela research supplement | 2026-11-01 | Native, designed examples
Status: research draft for the existing SQLite runtime-dependencies article.
Not a new vulnerability claim, incident-frequency estimate or independent peer review.

## Result in one paragraph

In both tested builds (SQLite 3.45.1 and 3.53.1), ordinary VACUUM on a content
table with unaliased rowids and no ordinary index changed document identifiers
from 1/3/8 to 1/2/3. The external FTS5 index still associated charlie with 3:
asking for charlie returned hotel. PRAGMA integrity_check, quick_check and the
internal FTS5 check passed. The explicit external-content check rejected the
mismatch with extended error 267. VACUUM INTO and a completed backup API copy
preserved the original mapping in these fixtures. The distinction is the result,
not an inconvenient exception to omit.

## Why this adds to the existing corpus

The existing article at
https://hesela.com/analyses/sqlite-index-runtime-dependencies/
already explains changed runtime semantics, missing trigger maintenance,
REPLACE behavior and copy-versus-recomputation boundaries. Research PR3297 adds
token-equivalent changes and an internal checksum collision.

This supplement starts from a healthy, trigger-maintained index. No source
document is edited during maintenance. The failure is a changed identity
mapping, not a changed tokenizer, omitted trigger, checksum collision, damaged
sector or interrupted operation. It links a documented storage-maintenance
permission to an observable wrong-document answer.

Three guarantees must remain distinct:
- Preserving the multiset of document bodies.
- Preserving the identifier-to-document mapping consumed by another structure.
- Keeping that structure consistent with the current mapping.

Only the first survives the failing VACUUM fixture. Rebuilding FTS restores the
third but does not restore the second.

## Nine-case control matrix, repeated on two builds

The initial content is exactly (1, alpha), (3, charlie), (8, hotel).
The FTS tokenizer is unicode61, detail=full. Each cell is one designed case per
build; this is not a random sample or a failure-rate denominator.

| Content schema | Operation | After: alpha/charlie/hotel rowids | MATCH charlie body | External check |
|---|---|---|---|---|
| Implicit rowid, no ordinary index | VACUUM | 1/2/3 | hotel | Rejects 267 |
| Implicit rowid, no ordinary index | VACUUM INTO | 1/3/8 | charlie | Pass |
| Implicit rowid, no ordinary index | Backup API | 1/3/8 | charlie | Pass |
| Implicit rowid, body index | VACUUM | 1/3/8 | charlie | Pass |
| Implicit rowid, body index | VACUUM INTO | 1/3/8 | charlie | Pass |
| Implicit rowid, body index | Backup API | 1/3/8 | charlie | Pass |
| id INTEGER PRIMARY KEY | VACUUM | 1/3/8 | charlie | Pass |
| id INTEGER PRIMARY KEY | VACUUM INTO | 1/3/8 | charlie | Pass |
| id INTEGER PRIMARY KEY | Backup API | 1/3/8 | charlie | Pass |

All nine cases per build pass both PRAGMAs and the internal FTS5 check.
All retained document-body multisets are unchanged. Six audit entries prove the
insert/update/delete triggers ran before maintenance; maintenance adds none.
In the failing case, rowid-only MATCH hotel still returns 8, while fetching its
body raises 267 because there is no longer a document at 8. Plain document
scans still return all three bodies. Projected columns therefore matter.

## The source connection

[1] SQLite's VACUUM documentation, section 3, permits rowid changes when the table
does not declare an INTEGER PRIMARY KEY. Its section 2.1 describes INTO as a
separate compacted copy. It does not make hidden rowids a persistent application
identifier.

[2] The rowid-table documentation explicitly distinguishes the rowid alias from
an unaliased storage identifier.

[3] FTS5 external-content lookup resolves an index rowid through content_rowid.
This explains why a valid posting can now retrieve the wrong document. Its
integrity and rebuild commands have different scopes.

[6] Pinned upstream vacuum.c sets DBFLAG_VacuumInto for INTO, creates ordinary
tables and indexes, transfers their contents, and copies trigger/view/virtual
table definitions afterwards. Trigger presence in the schema is consequently
not evidence of trigger execution during that transfer.

[7] Pinned insert.c, xferOptimization, retains an explicit integer key. Its
new-rowid branch requires no ordinary destination index AND no VacuumInto flag.
Otherwise it reads the source rowid. This directly explains both negative
controls: the incidental index and INTO preserve the mapping in the measured
build. This is implementation evidence, not a promise that an extra performance
index is a permanent identity mechanism.

The source is fixed to SQLite GitHub commit
189e44dfecdc7868bb860dfb5d98eab371318c37, tag version-3.45.1.
SOURCES.json has downloaded-byte hashes and exact source line locators.
The executing distribution build has an alt1 source ID; the upstream source
explains its measured behavior, but is not asserted byte-identical to its binary.
The second runtime is recorded separately in results-sqlite3531.json.
comparison.json retains one difference in the compared fields: the missing-body
diagnostic changes from a generic malformed-image message to an explicit missing
row 8 message. The extended code and scientific outcomes agree. Binary hashes,
raw schema formatting, backup page counts and runtime metadata are not equated.
No source inspection of the newer implementation is claimed.

## Practical acceptance policy

1. Inventory which consumers persist rowids, including external FTS5, application
   maps and exported identifiers. A successful text-only comparison is insufficient.
2. For a durable key, use and verify a true rowid alias such as id INTEGER PRIMARY
   KEY, and configure content_rowid='id'. Keep normal write-maintenance triggers.
   [5] INT PRIMARY KEY is not equivalent; the inline INTEGER PRIMARY KEY DESC
   exception also matters. This packet tests the simple declaration only.
3. Preserve the original before changing schema or rebuilding. Run maintenance
   and recovery acceptance on a disposable copy with a recorded engine identity.
4. Check complete known-answer searches, identifier/body pairs and the explicit
   external-content integrity command. Do not interpret a generic PRAGMA pass as
   an application-level certificate.
5. If current content is authoritative, an FTS rebuild can restore its search
   representation. It cannot reconstruct old IDs or repair external references
   to them. Those require a trusted old mapping or application-specific migration.

The internal and external checks for this fixture are:
```sql
INSERT INTO ft(ft) VALUES('integrity-check');
INSERT INTO ft(ft,rank) VALUES('integrity-check',1);
```
A passing external check is not a historical-content proof. The preceding
token-equivalence/checksum-witness packets document separate reasons it can
accept changed representations. Here it correctly detects the maintenance error.

## Reproduce and inspect

Python with sqlite3 and FTS5 is sufficient; no third-party package is required.
Run only the generated, private temporary fixtures, never production data.

```sh
python3 observe.py --output fresh-results.json
python3 -m unittest -v test_observe test_comparison
python3 -O -m unittest -v test_observe test_comparison
```

observe.py refuses an existing output. It creates three schema variants, exercises
all maintenance triggers, closes/reopens each input, runs three maintenance/copy
paths, records exact query outcomes, then rebuilds a separate disposable copy.
Every diagnostic uses a rolled-back savepoint. File SHA-256 is checked before
and after observation, copying and repair. Each backup receipt ends at
SQLITE_DONE (101), zero pages remaining and a positive total. The retained
capture contains schema, SQL, full source ID, compile options, metadata, document
digests, original/output hashes and every result/error.

Tests validate nine exact contracts, exact same-runtime repeats, twelve altered
evidence controls and refusal to overwrite a seed. Python -O must not disable
the checks. MANIFEST.json binds each portable package member to its bytes.
No manifest hash is asserted to establish historical provenance by itself.

## Limits

Nine deliberately selected cases per build, not eighteen independent population
samples. Two native engine builds executed by the same research agent, not an
independent replication. Closed/reopened files, DELETE journal, no auto-vacuum,
no concurrent writer, crash, power-loss or throughput measurement. Results do
not establish behavior for every version, schema, virtual table or transfer
optimization. INT PRIMARY KEY and the DESC exception are documentation notes,
not additional measured configurations. No probability or confidence interval
is appropriate for this deterministic counterexample.

## Primary sources

1. https://sqlite.org/lang_vacuum.html - VACUUM, sections 2.1 and 3.
2. https://sqlite.org/rowidtable.html - Rowid Tables, section 2.0.
3. https://sqlite.org/fts5.html - External Content Tables, pitfalls, integrity-check, rebuild.
4. https://sqlite.org/backup.html - Backup API, section 1.
5. https://sqlite.org/lang_createtable.html - ROWIDs and the INTEGER PRIMARY KEY.
6. https://github.com/sqlite/sqlite/blob/189e44dfecdc7868bb860dfb5d98eab371318c37/src/vacuum.c
7. https://github.com/sqlite/sqlite/blob/189e44dfecdc7868bb860dfb5d98eab371318c37/src/insert.c

No DOI applies to these implementation/documentation sources.
SQLite source files retain their public-domain notices. Hesela prose, synthetic
fixtures and observations are original work; repository reuse policy applies.
No third-party paper or vendor dataset is republished.
