Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ and repair-candidate log from development is preserved in

## Unreleased

- introduced incompatible database/storage format 2; new binaries reject
format-1 databases instead of attempting an implicit conversion;
- store REAL and DOUBLE as exact eight-byte IEEE-754 binary64 little-endian
values, preserving finite bit patterns including signed zero and subnormals;
- align row starts and lengths to eight bytes, align fixed-width fields to
their natural widths, and validate zero padding during decoding;
- reserve every user table's logical page 0 for a checksummed `MSTB` header,
with heap and overflow pages starting at page 1;
- encode overflow lengths as U32, retain aligned U64 identifiers in the 48-byte
pointer, and protect the pointer with an additional CRC-32C;
- encode numeric SQL index components in little-endian and compare typed keys
numerically, including floating-point range and covering-index scans;
- add byte-golden, malformed-input, sorting, reopening and compatibility tests
through `test.ps1 -StorageV2` and the cumulative acceptance launcher.

## 1.1.1 — 2026-10-31

- added bounded x64 byte-hash and lexicographic-comparison primitives for long
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ MiniSQL is a transactional relational database management system written in
[MiniLang](https://github.com/MiniLangProject/MiniLangCompilerPy) and compiled
to native Windows x64 PE or Linux x64 ELF applications.

**Current development tree: storage format 2.** This unreleased change stores
REAL/DOUBLE as binary64LE, aligns rows, reserves table page 0 for metadata, uses
U32 overflow lengths and little-endian numeric index keys. Existing format-1
databases are rejected and must be recreated. See the
[storage-v2 specification](docs/formats/storage-v2.md) and
[compatibility rules](docs/formats/FORMAT_COMPATIBILITY.md).

Browse the committed [GitHub-friendly API documentation](docs/api/markdown/README.md),
or download the repository and open the [offline HTML reference](docs/api/html/index.html).
Both documentation trees are generated directly from the MiniLang sources with
Expand All @@ -28,14 +35,21 @@ The strict MiniDoc configuration rejects missing documentation; use `--check`
to validate it without rewriting the committed reference.

The frozen M0-M50 plan is complete. The accepted 1.0 baseline revision is
`M48-M50R3`; MiniSQL 1.1.1 retains database and wire format version 1. The
current tree was revalidated on 2026-09-02: Windows passed all
`M48-M50R3`; released MiniSQL 1.1.1 retained database and wire format version 1.
That baseline was revalidated on 2026-09-02: Windows passed all
**106/106 cumulative phases**, including crash recovery, genuinely parallel
same-database reads, concurrent clients, TLS integration, replication, fuzzing,
soak tests, and deterministic release packaging; the focused Linux gate passed
all storage, client/server, concurrent scheduling, authentication, and native
TLS checks under WSL2.

Those historical results do not certify the new storage-v2 development changes.
Their focused binary-format gate is `./test.ps1 -StorageV2 -Target linux-x64`
or `./test.ps1 -StorageV2 -Target windows-x64` on the corresponding host. The
same five new format tests are included in the cumulative row/storage phase.
The [storage-v2 validation report](docs/acceptance/STORAGE_V2_2026-11-24.md)
records the focused native results and the platform limits of this development check.

> MiniSQL is an independently developed database engine. Version 1.0 has a
> substantial project-specific test suite, but it has not received an
> independent security or production audit. Validate it against your own
Expand Down
10 changes: 5 additions & 5 deletions config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,23 @@
},
"databaseFormatVersion": {
"type": "integer",
"minimum": 1
"const": 2
},
"tableFileFormatVersion": {
"type": "integer",
"minimum": 1
"const": 2
},
"indexFileFormatVersion": {
"type": "integer",
"minimum": 1
"const": 2
},
"walFormatVersion": {
"type": "integer",
"minimum": 1
"const": 1
},
"rowFormatVersion": {
"type": "integer",
"minimum": 1
"const": 2
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions config/minisql.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
"walSegmentBytes": 16777216,
"textEncoding": "utf-8",
"defaultCollation": "binary",
"databaseFormatVersion": 1,
"tableFileFormatVersion": 1,
"indexFileFormatVersion": 1,
"databaseFormatVersion": 2,
"tableFileFormatVersion": 2,
"indexFileFormatVersion": 2,
"walFormatVersion": 1,
"rowFormatVersion": 1
"rowFormatVersion": 2
},
"safety": {
"allowRemoteWithoutAuthentication": false,
Expand Down
85 changes: 85 additions & 0 deletions docs/acceptance/STORAGE_V2_2026-11-24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Storage-v2 development validation — 2026-11-24

## Scope and baseline

This report covers the incompatible storage-format update based on MiniSQL
commit `7fdab6bd49e8ac344632528109efd7e06e635afd`. The requested changes are binary
REAL/DOUBLE storage, aligned rows, a mandatory table metadata page 0, U32 overflow
lengths, and little-endian numeric SQL index components with semantic ordering.
See [the format overview](../formats/storage-v2.md) for the persisted contract.

Validation used MiniLang Compiler 1.3.10, compiler source commit
`8e64c9cfda92199b68ac5d3974fea445f12f6c39`, with native Linux x64 executables.
Test fixtures were isolated under ignored `build/` directories. Existing
databases were not converted or used as mutable fixtures.

## Focused binary-format gate

All five suites passed after the final SQL conversion and index corrections.

The internal cross-platform runner is exposed through `test.ps1 -StorageV2`.
The native Linux invocation is:

```sh
python tests/run_storage_v2.py --target linux-x64 --compiler ../MiniLangCompilerPy/mlc_win64.py
```

| Suite | Coverage |
|---|---|
| `storage_v2_metadata` | Metadata byte goldens, exact version tuple, old versions, mixed versions, flags and reserved fields |
| `storage_v2_rows` | IEEE-754 goldens, 128 finite bit patterns, signed zero, subnormals, natural alignment, zero padding, malformed rows, slot bounds/overlap and failure atomicity |
| `storage_v2_table` | Exact page-0 metadata, first data page 1, immutable header after growth, corruption, all physical open modes and legacy rejection |
| `storage_v2_overflow` | U32 boundary without allocating 4 GiB, independent pointer CRC golden, reserved bytes, damaged/truncated pointers and legacy rejection |
| `storage_v2_indexes` | I64 limits, 255/256, finite floating order, escaped/composite keys, uniqueness, splitting/ranges/reopen, covering results and signed-zero SQL conversions |

The runner writes per-test compiler/runtime logs and machine-readable
`results.json`. A native pass requires both exit status 0 and the test's exact
success banner. Cross-compilation is explicitly recorded as `COMPILE_PASS` and
does not count as native execution.

## Existing regression suites

The following 17 suites passed natively during implementation:

| Area | Passing suites |
|---|---|
| Configuration and catalog | `m8_config`, `m8_catalog` |
| Heap, rows, overflow and tree | `m9_row_codec`, `m9_heap_file`, `m10_overflow`, `m11_btree` |
| WAL, transactions and recovery | `m6_wal`, `m6_transaction`, `m7_checkpoint`, `m7_recovery` |
| SQL and schema integration | `m15_sql_engine`, `m23_index_integration`, `m24_schema_evolution` |
| Maintenance and migration | `m25_maintenance`, `m26_offline_migration` |
| Database contracts and encryption | `m50_release_contract`, `m79_security_at_rest` |

The SQL and index integration suites were rerun after the signed-zero correction.
Maintenance covers VACUUM, REINDEX and interrupted-maintenance recovery. Migration
covers 4096-to-8192-byte page rewrites. Encryption coverage includes encrypted new
table headers, WAL, key rotation and encrypted backup/restore.

## Signed-zero regression found during review

The strengthened index test first reproduced loss of `-0.0` in a DOUBLE key, a
REAL key and an INCLUDE value before the index was built. SQL numeric promotion
and text conversion discarded the sign before row serialization. A second
reviewed path reconstructed a covered equality key from the search literal,
which cannot preserve the stored value's sign.

The correction preserves floating inputs during conversion, restores a negative
zero sign for explicitly negative zero text, retains stored key bits, and reads
actual B+ tree entries for covered equality scans. The numeric comparator treats
both zero signs as equal; transient byte-hashed constraint keys normalize them.
The regression checks range and equality scans, composite equality, INCLUDE,
uniqueness and reopening against the heap's original binary64 bytes.

## Static and platform checks

- The repository's four static acceptance phases pass, including its 87-module
catalog, Apache headers, declaration documentation, configuration contracts and
independent Python binary/CRC reference vectors.
- `git diff --check` reports no whitespace errors.
- `storage_v2_rows` compiles for Windows x64 as a PE executable. Its CRT imports
include `_copysign`, `_finite`, `frexp` and `ldexp`. It was not executed on Windows.

The historical 106-phase Windows release acceptance was not rerun in this Linux
workspace. Existing release-evidence documents remain historical evidence. The
normal cumulative launcher now includes the five focused storage-v2 tests in
its row/storage phase; this report makes no new full-Windows-release claim.
72 changes: 60 additions & 12 deletions docs/formats/FORMAT_COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
# MiniSQL 1.0 format compatibility
# Format compatibility: unreleased storage v2

MiniSQL 1.0 freezes database format version 1 and wire protocol version 1.
Individual files also carry their own magic, version, database identity, object
identity and checksums. Global configuration values are never used to reinterpret
an existing file.
The current development tree requires **database format 2**. Its product
version is still **1.1.1**; the earlier format-1 builds bearing that version and
their dated release evidence are unchanged. Persisted version fields, rather
than the product-version string, determine compatibility.

The M48 `wal.log.durable` marker is auxiliary and may be recreated. It does not
change `wal.log` encoding. Unknown future versions must be rejected rather than
guessed.
## Version boundaries

Automatic HA adds auxiliary `leader.epoch` and controller-owned `leader.lease`
records. Their v1 layouts are documented in `ha-fencing-records-v1.md`. They do
not alter database pages, WAL, backup archives, or wire protocol v1. Ordinary
non-HA databases do not require either record.
| Component | Current version |
|---|---:|
| Database metadata envelope and database format | 2 |
| User-table file header | 2 |
| Physical row record | 2 |
| Overflow pointer and chain page | 2 |
| B+ tree metadata/node payload | 2 |
| SQL index key and INCLUDE payload | 2 |
| Common page header | 1 |
| Paged-file superblock | 1 |
| WAL record framing | 1 |
| Generic protected-envelope header structure | 1 |
| Catalog envelope | 1 |
| Wire protocol | 1 |

The slotted-page payload uses the aligned v2 allocation contract, selected by
the database/table format. Its common page-header version remains 1. The
generic protected-envelope structure has no independent outer version field:
the U16 at offset 8 is the enclosed format's version, which is 2 for `db.meta`.

## Accepted and rejected input

- A database created by this storage-v2 implementation opens only when all
required identities, supported versions, reserved fields and checksums agree.
- Existing database-format-1 files are rejected, including empty databases and
databases from earlier 1.1.1 builds. No compatibility decoder or automatic
upgrade is provided.
- Legacy table files without the required metadata page 0, row records with
version 1, overflow version 1, and B+ tree version 1 are rejected.
- Unknown versions or unsupported flags are rejected. Configuration defaults
cannot override persisted identity or reinterpret existing bytes.
- There is no supported downgrade of storage-v2 databases to format-1 engines.

Schema versions remain separate from physical row-format versions: compatible
column evolution inside a storage-v2 database does not enable reading a
row-format-1 record.

## WAL, backups and auxiliary records

Unchanged WAL framing does not make old and new page images interchangeable.
Storage-v2 recovery operates on the current database and its matching page
images. Backup and WAL-archive framing also keep their existing versions, but
their contained database must pass the storage-v2 checks. No legacy-backup
import path is introduced by this patch.

The durable-WAL marker and HA epoch/lease records retain their independent
layouts and do not select a storage generation. Existing statistics and
security-sidecar compatibility rules apply only after the enclosing database
has passed the database-format gate.

The offline page-size rewrite operates between databases supported by the
current engine. It creates a new storage-v2 database; it is not a format-1 to
format-2 conversion tool. See [UPGRADE.md](../release/UPGRADE.md) for the
development-build policy.
122 changes: 80 additions & 42 deletions docs/formats/README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,80 @@
# MiniSQL persisted format index

All fixed-width fields use canonical little-endian encoding unless a format
explicitly says otherwise. Unknown versions, non-zero reserved fields, checksum
failures, and contradictory identities are fail-closed.

- [Protected envelope v1](protected-envelope-v1.md) — M2
- [Common page v1](page-v1.md) — M4
- [Paged file v1](paged-file-v1.md) — M4
- [Database metadata v1](database-meta-v1.md) — M8
- [Table file v1](table-file-v1.md) — M8
- [Index file v1](index-file-v1.md) — M11
- [WAL record v1](wal-v1.md) — M6
- [Checkpoint metadata v1](checkpoint-v1.md) — M7
- [Database/catalog envelope v1](catalog-v1.md) — M8
- [Catalog bootstrap v1](catalog-bootstrap-v1.md) — M8
- [Row v1](row-v1.md) — M9
- [Slotted-page payload v1](slotted-page-v1.md) — M9
- [Heap forwarding v1](heap-forwarding-v1.md) — M9
- [Overflow pointer/page v1](overflow-v1.md) — M10
- [B+ tree index v1](btree-v1.md) — M11
- [Schema history v1](schema-history-v1.md) — M14/M24
- [DDL journal v1](ddl-journal-v1.md) — M14/M24
- [Statistics v1](statistics-v1.md) — M17
- [Wire protocol v1](wire-protocol-v1.md) — M18/M21
- [Backup manifest v1](backup-manifest-v1.md) — M20
- [Security catalog v1](security-catalog-v1.md) — M21
- [Encryption envelope and records v1](encryption-envelope-v1.md) — M79
- [Maintenance journal v1](maintenance-journal-v1.md) — M25

Existing paged files MUST derive page size and format identity from persisted
metadata and file headers, never from changed global defaults. M22-M24 do not
change page, WAL, or wire format. M25 introduces only the maintenance journal;
M26 rewrites into a fresh database rather than mutating format identity.

- `audit-log-v1.md`

- `secure-transport-v1.md`

- `wal-archive-v1.md`
- [WAL durable marker v1](wal-durable-marker-v1.md) — M48
- [MiniSQL 1.0 format compatibility](FORMAT_COMPATIBILITY.md) — M50
# MiniSQL persisted formats

This index describes the **unreleased storage-v2 development state**. The
product version remains **1.1.1** for this patch; that product label alone does
not identify the database format. Earlier release evidence and milestone
documents describe their original format-1 builds.

All fixed-width numeric storage fields use little-endian encoding. Current
storage-v2 readers reject unsupported versions, noncanonical padding,
checksum failures and contradictory identities. Page sizes and format versions
come from persisted metadata, not from changed global defaults.

## Current storage generation 2

| Component | Version / contract | Specification |
|---|---|---|
| Database metadata | `MSDBM001` envelope version 2; database/table/index/WAL/row tuple `2/2/2/1/2` | [Database metadata v2](database-meta-v2.md) |
| User-table file | Mandatory identity header on page 0; data pages start at 1 | [Table file v2](table-file-v2.md) |
| Rows | Version 2; aligned fields and binary64 REAL/DOUBLE | [Row v2](row-v2.md) |
| Slotted-page payload | Eight-byte-aligned allocations, selected by table format 2 | [Slotted-page payload v2](slotted-page-v2.md) |
| Overflow | Version 2; U32 total length and separate pointer CRC | [Overflow pointer/page v2](overflow-v2.md) |
| Index keys and leaf values | Typed little-endian numeric keys; INCLUDE payload version 2 | [SQL index keys and values v2](index-file-v2.md) |
| B+ tree metadata and nodes | Version 2 | [B+ tree v2](btree-v2.md) |

Legacy database format 1 is explicitly rejected. There is no implicit
conversion, legacy import, or in-place upgrade in this development patch.
See [format compatibility](FORMAT_COMPATIBILITY.md) and the
[development upgrade guide](../release/UPGRADE.md).

## Structural wrappers that remain version 1

These versions identify their own framing. A version-1 wrapper can carry
version-2 table or row content and does not make that content readable by an
older MiniSQL binary.

| Wrapper | Current interpretation |
|---|---|
| [Protected envelope v1](protected-envelope-v1.md) | Same 32-byte CRC-protected header structure; each enclosed format selects its own version field. `db.meta` uses 2. |
| [Common page v1](page-v1.md) | Same 64-byte header; page type 6 identifies the new user-table header. |
| [Paged file / superblocks v1](paged-file-v1.md) | Same pair of 4096-byte superblocks; table/index payload versions are checked separately. The page-offset formula in the original spec is for plaintext records. |
| [WAL records v1](wal-v1.md) | Same 80-byte framing; page images contain current storage-v2 payloads. Encrypted records use the marker described in the encryption specification. |
| [Checkpoint v1](checkpoint-v1.md) | Same two 256-byte checkpoint slots. |
| [WAL durable marker v1](wal-durable-marker-v1.md) | Same optional durable-prefix record. |
| [Encryption envelope and records v1](encryption-envelope-v1.md) | Same nonce/ciphertext/tag framing; paged-file stride is `pageSize + 28` when encrypted. |
| [Heap forwarding v1](heap-forwarding-v1.md) | Same 24-byte record; row references in storage-v2 user tables must target pages 1 or later. |

## Other independently versioned formats

The catalog envelope remains `MSCAT001`, version 1, with scalable `BLB2`
continuation pages. The current relationship to `db.meta` is described in
[database metadata v2](database-meta-v2.md#catalog-companion). The original
[catalog](catalog-v1.md) and [bootstrap](catalog-bootstrap-v1.md) notes are
retained as historical M8 sketches.

- [Schema history v1](schema-history-v1.md)
- [Schema extensions v1](schema-extensions-v1.md)
- [DDL journal v1](ddl-journal-v1.md)
- [Maintenance journal v1](maintenance-journal-v1.md)
- [Security catalog v1](security-catalog-v1.md)
- [Backup manifest v1](backup-manifest-v1.md)
- [WAL archive v1](wal-archive-v1.md)
- [Audit log v1](audit-log-v1.md)
- [HA fencing records v1](ha-fencing-records-v1.md)
- [Sort-spill framing v1](sort-spill-v1.md), whose current row payloads use row format 2
- [Wire protocol v1](wire-protocol-v1.md)
- [Secure transport v1](secure-transport-v1.md)

Optimizer statistics currently write sidecar version 5; this is independent of
database storage generation 2. The [statistics-v1 note](statistics-v1.md)
describes the historical baseline, not the current writer's complete layout.
Milestone-specific limits in older sidecar notes remain historical; current
serializers are authoritative for those independently evolved formats.

## Archived storage-v1 material

[Database metadata](database-meta-v1.md), [table files](table-file-v1.md),
[rows](row-v1.md), [slotted pages](slotted-page-v1.md),
[overflow](overflow-v1.md), [index files](index-file-v1.md), and
[B+ trees](btree-v1.md) are retained for historical reference. Their presence
does not indicate legacy read or conversion support.
Loading