Skip to content

Release 2.5.0 — SQL dialect expansion: multi-table joins, subqueries, additive ALTER TABLE#23

Merged
pango07 merged 2 commits into
mainfrom
feat/sql-dialect-2.5
Jul 11, 2026
Merged

Release 2.5.0 — SQL dialect expansion: multi-table joins, subqueries, additive ALTER TABLE#23
pango07 merged 2 commits into
mainfrom
feat/sql-dialect-2.5

Conversation

@pango07

@pango07 pango07 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Three of the four SQL-dialect roadmap items (LARVA-DESIGN.md §14), re-judged against the §7 admission bar in July 2026 and shipped together. Secondary index blobs are the remaining item and come next as 2.6.0.

3+ table joins & self-joins

  • INNER/LEFT JOIN across any number of tables: left-deep hash joins in statement order; each ON compares a column of the joined table with a column of any table already in scope.
  • Self-joins are ordinary now — the parser requires a distinct alias per occurrence (FROM staff e JOIN staff m ON e.managerId = m.id), so columns can always be attributed. Missing aliases get a DUPLICATE_TABLE_NAME error that shows the fix.
  • RIGHT/FULL/CROSS stay excluded by name.

Uncorrelated subqueries

WHERE id IN (SELECT …), NOT IN, and scalar comparisons (total > (SELECT AVG(total) FROM orders)) — implemented exactly as §14 planned: inner-query-first. The subquery executes against the same snapshot as the outer statement and its AST node is rewritten into plain literals before planning, which buys two properties for free:

  • IN (SELECT …) lists participate in zone-map pruning like literal lists.
  • A commit retry that re-plans also re-evaluates the subquery against the fresh snapshot — the same re-execution semantics every write already has.

Nesting works; shape errors are precise (SUBQUERY_MULTIPLE_ROWS, SUBQUERY_SHAPE); correlated references keep their original name error plus a pointer at JOIN; EXISTS gets a redirect hint. Derived tables (subqueries in FROM) remain excluded. A subquery in VALUES reads database state, so it is excluded from the tier-A fast-append classification and takes the ordered path.

Additive ALTER TABLE

  • ALTER TABLE t ADD COLUMN name type — a schema-only commit: existing chunks are untouched and absent keys read as NULL at every read path (queries, upsert planning, export). Cost is one log/manifest write regardless of table size.
  • DROP COLUMN, RENAME, ADD CONSTRAINT, NOT NULL, DEFAULT, UNIQUE/PRIMARY KEY on added columns: each rejected by name with the reason (most: waiting on a migration design that respects time travel).
  • Additive schema drift auto-migrates at connect: adding a plain nullable column to defineSchema and redeploying just works — it is exactly ADD COLUMN, so connect applies it instead of failing. Everything else still fails loudly with SCHEMA_DRIFT.
  • Mixed-version caveat documented in §7: pre-2.5 clients reading an ALTERed store fail loudly (UNKNOWN_COLUMN) on queries that touch the added column in old chunks — never silently wrong.

Tests — 275 checks (was 240)

  • sql-smoke: 101 → 134 (multi-join/self-join walkthroughs, subquery semantics incl. NOT IN over empty sets and correlated-error wording, full ALTER catalog, upsert reading an ALTERed column on a pre-ALTER row, drift auto-migration).
  • group-commit: 73 → 75 (subquery INSERT and SQL-ALTERed-column INSERT both stay off the tier-A queue and resolve via the ordered path).
  • Full gauntlet run locally: stress (zero lost updates), property (model holds), s3-adapter 17, api-smoke 30, cli-smoke 19.

Docs synced: design doc §7/§8/§14, content/sql.mdx (new subquery + ALTER sections), docs/larva-for-agents.md (→ /llms.txt), quickstart/agent prompt, READMEs, CLAUDE.md.

Self-review plus an independent gpt-5.5 (codex) correctness review; four findings triaged pre-PR:

  • Fixed: tier-A classification excludes subquery VALUES and columns unknown to the code schema; upsert DO UPDATE SET NULL-fills ALTERed columns; drift auto-migration re-verifies after its commit (concurrent conflicting addition race).
  • Documented as deliberate semantics (design doc §7): NOT IN (SELECT …) drops NULLs (Larva is two-valued throughout — no SQL NULL-poisoning trap); a rebase after a disjoint conflict keeps subquery values read from the planning snapshot (ordinary snapshot isolation, same as transactions).

🤖 Generated with Claude Code

pango07 and others added 2 commits July 10, 2026 20:36
…itive ALTER TABLE

- INNER/LEFT JOIN across any number of tables, including self-joins
  (left-deep hash joins; distinct alias per occurrence enforced)
- Uncorrelated subqueries: IN (SELECT ...), NOT IN, scalar comparisons —
  inner-query-first rewrite into literals, so IN lists zone-map-prune and
  commit retries re-evaluate against the fresh snapshot; correlated refs
  get a pointed error
- ALTER TABLE ... ADD COLUMN (plain nullable only): schema-only commit,
  absent keys read as NULL at every read path; DROP/RENAME rejected by
  name with the time-travel reason
- Additive schema drift auto-migrates at connect: add a plain column to
  defineSchema, redeploy, done
- sql-smoke: 101 -> 132 checks (271 total); design doc §7/§8/§14 and all
  agent-facing docs updated

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ation guards

From self-review + independent gpt-5.5 pass:
- appendSchema excludes subquery VALUES and columns unknown to the code
  schema (both must plan on the ordered path)
- planInsert NULL-fills ALTERed columns so DO UPDATE SET can read them
- connect() re-verifies drift after the auto-migration commit (a racing
  process may have added the same column with a different definition)
- IN (SELECT ...) drops NULLs from the resolved list — two-valued
  semantics made explicit and documented in design doc §7, along with
  rebase-keeps-snapshot-values (ordinary snapshot isolation)
- +2 regression checks (275 total)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
larva-db Ready Ready Preview, Comment Jul 11, 2026 3:49am

Request Review

@pango07 pango07 merged commit 2705e2d into main Jul 11, 2026
4 checks passed
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