sqlite-collation · shipping · also SQLite collating sequence, application-defined collation

SQLite collation

A SQLite collation is a named text-comparison rule used to determine ordering and equality in database operations.

Related Observatory article: Read on hesela.com

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

related
SQLite expression index, SQLite quick_check, Backup verification

Citations

  1. SQLite C API: Define New Collating Sequences (accessed 2026-10-18)
  2. SQLite REINDEX: rebuild scope and name resolution (accessed 2026-10-18)
  3. Hesela: SQLite index runtime experiment (accessed 2026-10-18)
  4. SQLite WITHOUT ROWID: table storage and primary-key structure (accessed 2026-10-22)
  5. SQLite optimizer overview, section 8.1: unary plus removes affinity (accessed 2026-10-22)
  6. Hesela: WITHOUT ROWID access-path observations and controls (accessed 2026-10-23)
  7. SQLite EXPLAIN QUERY PLAN: scan semantics and unstable diagnostic format (accessed 2026-10-22)
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.

JSON: /data/terms/sqlite-collation.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. SQLite collation. Hesela. 2026-10-23. https://hesela.dev/terms/sqlite-collation/