Skip to content

perf: default new columnar PK tables to the fixed-width record layout - #359

Merged
MPCoreDeveloper merged 2 commits into
masterfrom
perf/fixedwidth-default
Sep 2, 2026
Merged

perf: default new columnar PK tables to the fixed-width record layout#359
MPCoreDeveloper merged 2 commits into
masterfrom
perf/fixedwidth-default

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Summary

B7+: new directory-mode Columnar tables with an explicitly declared PRIMARY KEY now default to the fixed-width record layout (out-of-line overflow) via DatabaseConfig.AutoFixedWidthRecords (default true), even when FixedWidthRecordLayout is left false. Keyed INSERT/UPDATE/DELETE become in-place overwrites.

Measured on the fair PK workload (AppendOnly, 1 run): INSERT +46%, UPDATE +23%, DELETE +16% vs the legacy variable-length layout (see #358, which now also opts the legacy arm out of this default so the comparison stays meaningful).

Scope & safety

  • Only new tables with a user-declared PK — tables without one (implicit _rowid fallback) keep the legacy layout; PageBased tables and single-file (.scdb) are untouched.
  • Existing tables are never rewritten: the per-table format flag is persisted in metadata and stays authoritative on reopen. FixedWidthRecordLayout remains the explicit force + auto-migrate switch.
  • Opt-out per database: DatabaseConfig { AutoFixedWidthRecords = false }.

Bug found & fixed while validating the blast radius

The column-ordered batch-INSERT fast path (SerializeRowExact(object[]), used by ExecuteBatchSQL) did not dispatch on the fixed-width flag and wrote legacy variable-length records into fixed-width tables → batch-inserted rows were invisible to scans (INSERT INTO dst SELECT … copied 0 rows). Fix: added a column-ordered FixedWidthCodec.SerializeRow overload and routed the array fast path through the fixed-width codec.

Tests

  • Full suite 1645/1645.
  • New DirectoryFixedWidthDefaultTests: default-on for declared-PK tables, legacy for no-PK tables, config opt-out, format persistence across reopen, explicit FixedWidthRecordLayout without PK.
  • Legacy-format fixtures (FixedWidthMigrationTests, SqlInPlaceUpdateTests variable-width growth) now opt out explicitly; KnownIssuesFixTests.Issue1 plaintext check scans the .ovf arena too (TEXT is out-of-line on fixed-width tables).

MPCoreDeveloper added 2 commits September 2, 2026 21:52
B7+: DatabaseConfig.AutoFixedWidthRecords (default true) makes CREATE TABLE on directory-mode Columnar tables with an explicitly declared PRIMARY KEY use the fixed-width record layout (out-of-line overflow) even when FixedWidthRecordLayout is left false. Effect: keyed INSERT/UPDATE/DELETE become in-place; measured on the fair PK workload (AppendOnly): INSERT +46%, UPDATE +23%, DELETE +16% vs the legacy layout.

Scope & safety:

- Applies only to tables with a user-declared PK (the implicit _rowid fallback keeps the legacy layout) and only to new tables: the per-table flag is persisted in metadata, existing files are never rewritten, and reopen stays authoritative.

- PageBased tables and the single-file (.scdb) layout are untouched by this default.

- FixedWidthRecordLayout remains the explicit force/auto-migrate switch for existing databases.

Bug fixed while validating the blast radius: the column-ordered batch-INSERT fast path (SerializeRowExact(object[]), used by ExecuteBatchSQL) did not dispatch on the fixed-width flag and wrote legacy variable-length records into fixed-width tables, so batch-inserted rows were invisible to scans (INSERT INTO ... SELECT copied 0 rows). Added a column-ordered FixedWidthCodec.SerializeRow overload and routed the array fast path through it.

Tests: full suite 1645/1645. New DirectoryFixedWidthDefaultTests cover default-on for declared-PK tables, legacy for no-PK, opt-out, reopen persistence, and explicit FixedWidthRecordLayout. Legacy-format fixtures (FixedWidthMigrationTests, SqlInPlaceUpdateTests variable-width growth, KnownIssues Issue1 plaintext) now opt out or scan the .ovf arena.
…loads

Deduplicates the two SerializeRow value loops into FixedWidthCodec.WriteSlot (Sonar quality gate: duplication on new code <= 3%).
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@MPCoreDeveloper
MPCoreDeveloper merged commit 1b488dc into master Sep 2, 2026
13 checks passed
@MPCoreDeveloper
MPCoreDeveloper deleted the perf/fixedwidth-default branch September 2, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant