Skip to content

sqlite_master is a projection of the prolly catalog, not a stored table #1852

Description

@timsehn

sqlite_master in DoltLite is a projection over the prolly catalog, not a
stored table. SQLite keeps the schema as ordinary rows in a b-tree that
writable_schema can edit directly; DoltLite keeps a content-addressed catalog
and renders sqlite_master from it. Anything that depends on the schema being a
concrete, mutable row store diverges.

Measured on db9e3e9d86 against stock SQLite.

A catalog row that is not a valid entry is ignored, not refused

CREATE TABLE t(a);
PRAGMA writable_schema=1;
INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
-- reopen
SELECT count(*) FROM t; PRAGMA integrity_check;
DoltLite: 0        ok
stock:    Error: malformed database schema (?)

The all-NULL row never becomes a catalog entry, so schema load skips it and
integrity_check sees a self-consistent store. Stock refuses to open. Gated as
capi3c-8.3, capi3-8.3.

PK-clustered tables have no sqlite_autoindex row

CREATE TABLE t(a TEXT PRIMARY KEY, b);
SELECT count(*) FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%';
DoltLite: 0    stock: 1

There is no separate index structure to name: the primary key is the storage
order. This one is a consequence of PK keying rather than of the projection, so
those gates cite #1840.

Row order is canonical, not creation order

Schema commits adopt the canonical catalog (#1596, landed in #1616), so
sqlite_master enumerates in canonical order and oids are reassigned. Tests that
bind oids or assert creation-order enumeration diverge. Note #1596 is closed, so
the ~110 gates whose reason reads "canonical adoption: sqlite_master row order
after schema commit" currently point either at #1200 (57 of them, as
engine-gap) or at nothing. #1200 is about schema SQL text canonicalisation,
which is a different thing from row order — worth re-checking whether those 57
belong here instead.

Things that do NOT diverge, checked so they are not assumed

These behave identically to stock and should not be attributed here:

  • rootpage values for an ordinary schema: both report t|2 i|3
  • poking rootpage to a bogus value: both refuse at reload with
    malformed database schema (t) - invalid rootpage
  • rewriting an index's SQL under writable_schema: both report
    row 1 missing from index i

So the ~10 gates whose reason mentions rootpage numbering are left unattributed
rather than swept in — their assertions are more elaborate than the shapes above
and need reproducing individually before anything is claimed about them.

Why this issue exists

The class was previously unattributed, and four of its gates had been pulled into
#1846 (PRAGMA no-ops) by a keyword match on writable_schema — which is merely
how those tests reach the catalog, not why they diverge. Two of them describe
DoltLite being stricter than stock, which a no-op issue actively misdescribes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions