Skip to content

Reduce retained catalog schema memory after replay - #32948

Merged
mergify[bot] merged 9 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/compact-catalog-schema
Nov 21, 2026
Merged

mergify[bot] merged 9 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/compact-catalog-schema

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32426

What this PR does / why we need it:

After #32611 removed the full column-batch merge, each live catalog version still retained both the engine attribute graph and the planner definition. This change retains a canonical planner definition, the original constraint bytes and the engine fields that cannot be reconstructed from the planner. Relations borrow the published planner for reads and build private definitions for consumers that require ownership. Old readers retain their catalog version across DDL. Failed ALTER restores the previous schema and version.

Linux memory comparison. The base was e765c5fd44. The measurements below used b3139f9e09, whose Git tree matches the original PR commit 3a3f034bdf. With Go 1.27.4 on linux/amd64, each binary ran in three independent cgroup v2 services with a 16 GiB limit, swap disabled, the same CPU set, GOMAXPROCS=4 and GOMEMLIMIT=12GiB. Runs were interleaved. The deterministic fixture contained 630,124 tables and 4,410,868 columns (six varchar columns plus a hidden rowid per table). The harness prebuilt sorted input batches of up to 147,029 rows and invoked the production consumeReplayColumns and CatalogCache.InsertColumns paths across batch boundaries.

Median of three runs Base Candidate Change
Live Go heap above process baseline after input release and GC 3.586 GiB 2.793 GiB −22.13%
Cgroup peak through input preparation, replay, cleanup and GC 6.138 GiB 5.425 GiB −11.62%
Cgroup peak including the subsequent engine/planner readback of every table 6.138 GiB 6.297 GiB +2.59%
Whole-process maximum RSS including readback 6.193 GiB 6.354 GiB +2.61%
Column batch application 5,019 ms 4,813 ms −4.10%

All six runs verified every table, planner and engine column metadata, zero remaining input-pool ownership and zero cgroup OOM events. The exhaustive readback builds private projections in the candidate and reads retained definitions in the base. A separate 40,000-table aligned control measured a 22.12% reduction in retained heap. First Relation open in a fresh transaction measured 1,801 → 1,856 ns/op (+3.05% median over three processes per revision, 1,000 opens per process), with nine allocations per open on both revisions.

SQL and ownership validation. Both service binaries restarted successfully from byte-identical copies of one persisted snapshot. Both exposed 2,049 user tables and 14,339 columns and produced identical sampled rows, composite key, secondary index and decimal default. Both read 18,096 catalog column rows during SQL restart. Linux single-process cache tests, focused replay ownership/cancellation and ALTER rollback tests passed on the candidate. Multi-CN replay and durable restart tests passed on both revisions. The previous same-tree Darwin validation also passed cache, disttae and pb/plan normal and race tests.

Remaining QA coverage. The scaled input is synthetic. The current and two earlier development records contained generated fixtures and heap profiles. The original QA data, workload and reconnect topology were unavailable for offline replay. The original 16 GiB incident remains open for verification. Costs for projecting many schemas concurrently and end-to-end logtail transport at incident scale remain unmeasured.

After synchronizing with main at d2e71035db, Linux validation at 6734419e13 passed the build, the pb/plan, disttae/cache and disttae unit tests, multi-CN replay and durable restart tests, and the license-header check for all 35 changed Go files.

At e2d594e1ab, catalog type reconstruction explicitly checks whether the planner ID fits the engine OID and whether that OID supports a default type. The original engine type remains available for unsupported types. Existing strict callers keep their panic contract. The Linux build, types/cache/disttae unit tests, multi-CN replay and durable restart tests passed. The pinned CI tools checked the six changed packages with molint and golangci-lint (zero issues), and license-eye accepted all 37 changed Go files.

Review follow-up

Statistics refresh and ANALYZE now read the published planner schema under an existing catalog publication guard. Collection releases the guard before object I/O. Primary-key lookup reconstructs only the selected attributes and their private expression metadata. Empty collection skips allocation of per-column statistics buffers.

The catalog replay changes from #32964 release the delayed callbacks on reset or after ordered application, simplify the cross-batch carry path, and clean up the replay test pools. The ownership design records publication, borrowing, private copies, ALTER rollback, and reconstruction costs. Catalog schema ownership design

Allocation per component call on 256 user columns Before After
Stats catalog lookup and schema access 197,376 B 352 B
Single primary-key projection 63,512 B 216 B

The same synthetic schema served as both controls. The new paths allocated the same number of bytes on 16 and 256 user columns. These measurements cover the two component reads.

Validation on Darwin/arm64 with Go 1.27.1 covered type, planner, and cache unit packages, configured incremental lint, and focused race tests for schema ownership, stats publication, ALTER rollback, replay failures, reconnect, multi-CN replay, and durable restart. The stats regression test compares borrowed and owned definitions on a persisted object with a sparse physical column sequence number. Relation-level tests cover zero, single, and hidden composite keys along with mutation isolation. The delayed-queue test fails both release assertions with the prior implementation and passes with this change.

Incremental license-eye accepted all 40 changed Go files. Independent design and review gates completed on GPT-6.2-sol/xhigh and GPT-6.1-terra/max, respectively.

Table-status metadata follow-up

The table-status path uses the planner definition already obtained for relation admission. It reads the opened relation's schema version and scans its columns without rebuilding private engine definitions. The allocator lookup uses the same normalized name as CREATE. A view, a physical row ID, and a hidden synthetic primary key do not supply a user allocator. A visible column may use the fake primary-key name. The two tagged diagnostic files were removed. The normal candidate and ALTER-copy tests cover their ownership assertions. Catalog schema ownership, revision 2

The MySQL-protocol control checked return values through the function, SHOW TABLE STATUS, and information_schema.tables for ordinary tables, views, lowercase and mixed-case auto-increment columns, and a visible column named __mo_fake_pk_col. Both the merge base and the reviewed head returned 0 for the mixed-case columns after two inserts. The fixed revision returns 3 across all three entry points.

User columns SQL median on merge base SQL median on reviewed head SQL median after fix Built-in allocations on reviewed head → after fix
6 5.65 ms 17.37 ms 5.62 ms 6,616 → 864 B/op
256 20.45 ms 256.22 ms 10.30 ms 170,344 → 864 B/op

The SQL runs each read 8,192 rows naming one ordinary table. Medians use four warm queries per width, in separate embedded-cluster processes on the same Darwin/arm64 host. The allocation control invokes the actual built-in with a catalog-built relation and fixed relation resolution. These local measurements cover metadata reads.

Focused race tests passed for allocator column selection, relation-name ownership, candidate defaults, ALTER-copy and rollback, and index access admission. The saved BVT's statements, output column names and row values matched via MySQL protocol. The two-CN allocator lifecycle and indexed and temporary-table status tests also passed. Incremental golangci-lint, molint, and all 40 changed Go license headers passed. The independent design and code review gates completed.

Metadata performance finding · Tagged probe finding

Remove intermediate schema projections

Catalog DROP and the deletion phase of ALTER use the existing planner columns to form catalog keys. ALTER still materializes the private schema it needs to recreate the catalog and restore the previous version on statement rollback. A published catalog item now holds its schema directly. At that revision, owned planner copies worked from the planner definition. Engine copies merge the ordered residual fields directly into the output attributes. This removes the intermediate prototype, dense scratch arrays, and the unused projection from catalog deletion. Column-only replay uses read-only attributes for equivalence and retains the existing validation. Constraint validation still runs before publication, and consumers of engine definitions still receive private decoded constraints.

On Go 1.27.1 Darwin/arm64, three interleaved runs compared the same published catalog items against daac1a097507. Fixtures had 6 or 256 user columns plus the physical row ID. The complex fixture also had primary-key and index constraints, a default expression, and a stored generated expression.

Fixture User columns Projection Median ns/op before → after B/op before → after Allocations/op before → after
plain 6 planner 1,101.0 → 628.4 6,536 → 4,360 18 → 12
plain 6 engine 943.7 → 395.1 4,936 → 1,768 24 → 11
plain 256 planner 26,113.0 → 15,019.0 196,896 → 133,600 20 → 14
plain 256 engine 25,336.0 → 12,388.0 162,680 → 62,376 524 → 261
constraint and expression 6 planner 2,037.0 → 1,489.0 7,488 → 5,312 30 → 24
constraint and expression 6 engine 1,904.0 → 1,301.0 6,183 → 2,964 47 → 33
constraint and expression 256 planner 26,410.0 → 16,402.0 197,848 → 134,552 32 → 26
constraint and expression 256 engine 26,680.0 → 13,246.0 163,924 → 63,572 547 → 283

Focused race tests covered column-only replay, old-reader and ALTER rollback, invalid constraint rejection, decoded-wire isolation, and planner and attribute fidelity. MySQL-protocol regression checks passed for DROP failure and rollback, ALTER, and allocator lifecycle. Two-CN catalog replay, reconnect, and durable restart also passed. Configured incremental golangci-lint, molint, and the license header check passed. These measurements cover component projections. The final revision has no new incident-scale or end-to-end cgroup peak measurement.

Race validation also passed for the full cache package, for 100 repetitions each of concurrent read-only encoding and column-only replay with readers and GC, and for multi-CN replay, reconnect, and durable restart.

Catalog schema ownership, revision 3

CI follow-up for the arena timer

The PR was rebased onto official main at 96bfaa437bd9d535f22b6bd981ad00e277a4a91e. It includes the upstream arena fixture and shared mmap timer fixes for the runtime fatal shown by TestArenaPoolCountCap. The six PR patches are unchanged according to git range-diff. Failed Ubuntu UT · Upstream fix and incident

Local validation on 1214f5a125e4070bfb95beb987ffaa71c46b6260 used Go 1.27.1 on Darwin/arm64 with mo-cgo-test -race -tags matrixone_test -short. The objectio and malloc packages passed, along with focused planner, catalog replay, schema ownership, and ALTER rollback tests. All 41 changed Go license headers and the Loom artifact check passed. The original Linux fatal did not reproduce in the local baseline tests. The rebased Linux CI result is pending.

Catalog metadata reads for extrema and sequences

MO_TABLE_COL_MIN/MAX uses the published planner column positions for canonical DistTAE relations. NEXTVAL validates the relation kind from the published catalog metadata. Other relations retain their existing metadata validation. The unused private planner projection and its copy helpers were removed. The previous planner projection benchmarks describe the earlier revision.

The embedded MySQL-protocol tests covered 256-column empty and persisted tables, case-insensitive extrema and a missing column, 8,192 consecutive sequence values, and rejection of a non-sequence relation. Multi-CN catalog replay, reconnect, and durable restart passed. The local Linux/amd64 Go 1.27.1 checks passed across the seven affected Go packages with -race, and incremental static analysis passed.

Metadata operation Before After
256-column extrema lookup 59,648 B/op, 258 allocs/op 0 B/op, 0 allocs/op
Six-column sequence kind validation 2,508 B/op, 21 allocs/op 0 B/op, 0 allocs/op

The benchmark measures the metadata operations. Catalog schema ownership at this revision

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: e2d594e1ab6db1f472dd01dfa603b7c5e39966e1

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: e2d594e1ab6db1f472dd01dfa603b7c5e39966e1

Assessment: request_changes

Reusing the planner schema reduced retained heap by 22.13% in the author's replay fixture. Projection, ALTER rollback, reconnect, multi-CN replay, and durable restart checks passed. Remove avoidable full-schema allocations from read paths and complete the design record for schema ownership.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee7f-fdcb-7b83-ad57-3b17a0e9d494 · slot 1 · generation 1

  • P2 pkg/vm/engine/disttae/cache/schema_candidate.go:109: A statistics refresh reads a published schema, or a DDL lock requests the primary key of an existing table.
    Impact: Both paths now allocate scratch space proportional to the full schema. Statistics refresh also clones the planner graph before checking whether any objects have flushed. Primary-key lookup pays the full-width cost even when it returns one attribute.
    Evidence: The same 256-column fixture allocated 180,832 bytes per owned planner projection, 62,680 bytes per single-key projection, and zero per planner borrow. See projection-probe.stdout and checks/1795114854278808577-2.json. Reuse the immutable planner for read-only statistics and construct selected engine attributes directly from the canonical columns and sparse residuals.

  • P2 pkg/vm/engine/disttae/txn_table_delegate.go:70: This major refactor changes schema ownership across catalog replay, relation handles, and planner consumers. It exceeds the 500-line production-change threshold in the pinned feature-design-review.md.
    Impact: The PR describes borrowing and ALTER rollback at a high level. The required design record still lacks the rules that distinguish read-only borrowers, shallow planner copies, and callers that need private nested metadata, along with the lifetime of those views during replay and rollback.
    Evidence: The pinned policy requires a revisioned record that closes ownership, state transitions, and resource costs. The PR description and linked issue provide the replay rationale and measurements. Extend the existing PR design section with the borrow and copy boundaries, the publication and rollback rules, and the expected cost of the remaining projections.

Validation:

  • Isolation preflight and git diff --check passed. See preflight.stdout, patch-check.stdout, and receipts 1795114575296563438-3 and 1795114575294009504-2.

  • Focused type, planner-copy, catalog projection, column-only replay, and ALTER isolation checks passed. See type-go.stdout, focused-go.stdout, additional-go.stdout, and alter-probe.stdout with receipts 1795114760397321548-2, 1795114843642184393-2, 1795114813729614072-2, and 1795114890309690824-2.

  • TestCatalogReplayMultiCN, TestCatalogReplayReconnect, and TestDatabaseDefaultsDurableRestart passed through the supplied isolated executor. See focused-go.stdout and receipt 1795114843642184393-2.

Limitations:

  • The local allocation probe measured component reads on synthetic schemas. End-to-end DDL latency and concurrent statistics memory were outside its scope.

  • The author-reported replay comparison used an earlier revision of the PR and synthetic metadata. The original QA workload and 16 GiB reconnect incident were outside the reproduced scope.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

The change preserves catalog projection behavior while retaining a canonical planner and reconstructing private engine and planner views where ownership requires it. I found no new blocking or non-blocking findings after tracing replay, column-only updates, relation construction, ALTER materialization and rollback, shared defaults, compatibility migrations, and replay cluster-key reconstruction. The existing review's two unaddressed P2 concerns cover full-schema allocations in statistics and primary-key reads and the ownership design record; they are not duplicated here. git diff --check origin/main...HEAD passed. Focused Go tests did not execute in this checkout: the normal target lacks the required jemalloc and libmo artifacts, and the CGO-disabled attempt stopped during package compilation because mpool references malloc.SimpleCAllocator and malloc.NewSimpleCAllocator. This is a local build-configuration limitation, with no failure attributed to the PR.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: e2d594e1ab6db1f472dd01dfa603b7c5e39966e1

New discussion was assessed; the previous review remains unchanged.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes. The current head fixes the previously reported table-status call, the full-schema work in stats and primary-key lookup, and removes the tagged test bridge. The ownership design is clearer, but two other real per-row consumers still pay for a complete private engine schema, and a substantial private planner projection has no production caller in the current call graph. Please address the three inline findings together so this memory optimization does not transfer excessive work to normal metadata/sequence operations or retain an unused second copy path.

Validation: compared the merge-base and this exact head on the same Darwin/arm64 host with catalog-built schemas, and exercised both affected SQL paths against independent embedded clusters via the MySQL protocol. The cloud-style query returned the expected 256 rows and the NEXTVAL probe verified all 8,192 values per run. These local timings demonstrate the regressions but are not incident-scale production measurements. Focused projection, column update, replay failure, ALTER rollback and auto-increment tests passed; focused catalog ownership, old-reader and GC tests also passed under -race, as did git diff --check; full required CI is green. The author's replay memory comparison remains a synthetic fixture on an earlier PR revision; I did not reproduce the original reconnect/OOM workload.

Comment thread pkg/vm/engine/disttae/txn_table.go Resolved
Comment thread pkg/vm/engine/disttae/txn_table.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 3c39930 against main 63e76cf, carrying forward the earlier catalog-ownership review and examining the follow-up and affected consumers. The prior findings are addressed: read-only stats and primary-key lookups avoid full-schema copies; table-status, extrema and NEXTVAL no longer project all attributes on their normal catalog path; and the unused private planner projection and tagged diagnostic bridge were removed. The ownership record describes publication, borrowed reads, private engine views and ALTER rollback. The earlier inline threads remain open in GitHub, but I verified the corresponding fixes in the current code.

I traced planner/engine ordering for extrema, physical rowid and combined-relation fallback, sequence-kind validation and transaction-local fallback, plus the changed projection tests and public SQL regressions. No new blocking issue found. Green CI and the prior/follow-up test and race evidence are reused; the local per-component allocation numbers do not establish incident-scale throughput or peak memory. The original reconnect/OOM workload remains unverified, and the earlier synthetic replay comparison showed a higher peak after exhaustive readback, as documented in the PR.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 3c399308ea9520ec9aba6b34b7637e33a33b12c5

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 3c399308ea9520ec9aba6b34b7637e33a33b12c5

Assessment: approve

The refactor retains one planner schema per catalog version and preserves the original constraint bytes for private engine views. The review confirmed that older readers retain their schema through replay and ALTER rollback. Statistics, primary-key lookup, table status, extrema and NEXTVAL now avoid full-schema copies on their canonical paths. The prior review findings are resolved.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1

Validation:

  • The frozen checkout matched the assigned head and patch after normalizing the patch's final newline. The checkout was clean and git diff --check passed. See frozen-source-normalized.log and receipt 1795230983599834004-2.

  • The frozen head passed the shared build, Ubuntu x86 unit tests, Linux arm64 static analysis, and proxy and pessimistic multi-CN BVT jobs. See review-evidence-check.log and receipt 1795231194056725714-2.

  • Reviewed the projection and rollback tests and the author-reported race, MySQL-protocol, reconnect and durable-restart results. The discussion assessment covers all 15 indexed entries.

Limitations:

  • Runtime validation relied on frozen CI and supplied evidence. Both upgrade CI jobs were skipped.

  • The 22.13% retained-heap reduction and 2.59% higher peak after exhaustive readback came from an earlier synthetic comparison. The final-head peak and the original 16 GiB reconnect incident remain unverified.

@mergify mergify Bot added the queued label Nov 21, 2026
@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as c278bb2 at 05:15 UTC

1 h 49 min in the queue, 1 h 13 min of it CI.

So far

  • ✅ Entered the queue Sat 21 Nov, 03:26 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 05:15 · c278bb2 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

queue

☑️ This pull request is already queued

This branch was previously deployed

1 inactive deployment
ci — 7e6d34e0 Deployed Nov 21, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants