SQLite collation
A SQLite collation is a named text-comparison rule used to determine ordering and equality in database operations.
Application-defined collations are registered on a connection. A shared name does not guarantee that two application versions use identical comparison rules; an existing index can disagree with a changed rule. [1]
Rebuilding an index under the intended comparator can restore consistency, but changing equality can also make existing keys collide. In a two-row control, A and a became equal and rebuilding the UNIQUE index failed with SQLITE_CONSTRAINT_UNIQUE. The rolled-back fixture retained both rows and its original hash. [2] [3]
Table layout changes the available validation path. In SQLite 3.45.1 and 3.54.1 WITHOUT ROWID controls, normal equality queries and NOT INDEXED variants both reported primary-key searches and shared wrong empty answers after an order reversal. The primary-key tree stores the table rows; agreement was not an independent correctness check. [4] [6]
REINDEX main.sample restored every tested order-reversal fixture on a disposable copy, including WITHOUT ROWID. Equality stayed unchanged, unlike the separate UNIQUE-collision control. A unary-plus scan exposed the missing rows with TEXT-bound keys, but unary plus also removes affinity and can change other comparisons. Verify the expected rows and query semantics instead of treating NOT INDEXED as a universal scan guarantee. [5] [6]
A SCAN report can describe traversal of index storage, not a separate physical structure. The expected row set supplies the correctness oracle in these fixtures. EXPLAIN QUERY PLAN is a version-sensitive diagnostic, not a stable machine interface. [7]
Relations
Citations
- SQLite C API: Define New Collating Sequences
- SQLite REINDEX: rebuild scope and name resolution
- Hesela: SQLite index runtime experiment
- SQLite WITHOUT ROWID: table storage and primary-key structure
- SQLite optimizer overview, section 8.1: unary plus removes affinity
- Hesela: WITHOUT ROWID access-path observations and controls
- SQLite EXPLAIN QUERY PLAN: scan semantics and unstable diagnostic format
Sources & caveats
- Constructed fixtures on SQLite 3.45.1; callback changes deliberately violate existing index assumptions. No defect, incident-rate or cross-platform migration claim.
- 48 retained states and 720 point lookups plus 24 affinity lookups across SQLite 3.45.1 and 3.54.1 on one Linux host; identical designed matrix, not independent incidents. Comparator order deliberately reversed without changing equality.