Skip to content

docs: ADR 0004 — reject declarative partitioning; keep partial indexes + compaction (#418) - #433

Merged
CheeryProgrammer merged 1 commit into
mainfrom
docs/adr-partitioning
Jul 19, 2026
Merged

docs: ADR 0004 — reject declarative partitioning; keep partial indexes + compaction (#418)#433
CheeryProgrammer merged 1 commit into
mainfrom
docs/adr-partitioning

Conversation

@CheeryProgrammer

Copy link
Copy Markdown
Contributor

What & why

Closes #418 (scale). Documents the engineering decision not to add declarative table partitioning, with the reasoning, so it isn't re-litigated.

Investigating true nodes/edges partitioning by status surfaced two independent Postgres limitations, each breaking a core invariant:

  1. Nodes → lost FK integrity. A partitioned nodes can't keep nodes.id table-level unique (the partition key must be in the PK), so edges.from_id/to_id → nodes.id can't be DB-enforced.
  2. Edges → broken atomic upsert. The "one current edge per (from,to,type)" partial unique index (WHERE status='current') can't be a parent-level index on a partitioned edges, so InsertEdge's atomic ON CONFLICT (from_id,to_id,type) WHERE status='current' DO UPDATE — the idempotency behind link/remember — stops working.

So partitioning and "keep integrity + the atomic edge upsert" are mutually exclusive here.

Decision

Keep the already-shipped, no-compromise mechanism: #230 (current-tier partial indexes → hot index stays the size of live memory) + #385 (kb compact → reclaim heap bloat). At genuinely huge history (≫10M superseded rows) the sound path is app-level *_archive tables + UNION in the history read paths (as-of #200, retention #363), not partitioning — a separate deliberate project if ever needed.

Recorded in ADR 0004 + SYSTEM.md (§10). kb partition is not added.

Docs-only.

🤖 Generated with Claude Code

…s + compaction (#418)

Investigating true nodes/edges partitioning by status surfaced two
independent Postgres limitations that each break a core invariant:

1. A partitioned `nodes` can't keep `nodes.id` table-level unique (the
   partition key must be in the PK), so the edges→nodes FK can't be
   enforced by the DB.
2. The "one current edge per (from,to,type)" partial unique index can't
   be a parent-level index on a partitioned `edges`, so InsertEdge's
   atomic `ON CONFLICT ... WHERE status='current'` upsert — the
   idempotency behind link/remember — stops working.

So partitioning and "keep integrity + the atomic edge upsert" are
mutually exclusive here. The practical goal (small hot working set) is
already met without compromise by #230 (current-tier partial indexes) +
#385 (kb compact). At genuinely huge history the sound path is app-level
*_archive tables + UNION in the history read paths, not partitioning.

Records the decision in ADR 0004 + SYSTEM.md so it isn't re-litigated.
kb partition is not added; #418 is superseded.

Closes #418

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CheeryProgrammer
CheeryProgrammer merged commit 50499a1 into main Jul 19, 2026
5 checks passed
@CheeryProgrammer
CheeryProgrammer deleted the docs/adr-partitioning branch July 19, 2026 23:02
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.

True declarative table partitioning for nodes/edges (current vs historical) — deferred from #385

1 participant