Skip to content

fix: derive current View metadata on demand - #29139

Merged
XuPeng-SH merged 50 commits into
matrixorigin:mainfrom
ck89119:issue-29005-main
Sep 28, 2026
Merged

XuPeng-SH merged 50 commits into
matrixorigin:mainfrom
ck89119:issue-29005-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #29005. Part of #26227.

What this PR does / why we need it:

This adopts the on-demand binding design suggested in review. The semantic View definition remains authoritative; DESC and information_schema.columns bind it against the caller's current catalog snapshot instead of relying on a persisted derived column snapshot.

Read path

  • Extract a shared read-only View column descriptor from the existing authoritative View schema generator.
  • Use it for DESC / SHOW [FULL] COLUMNS, including LIKE and WHERE filtering.
  • Add a private mo_view_columns metadata operator for information_schema.columns. Visible View candidates are selected by the existing role-aware metadata boundary before binding.
  • Run the correlated descriptor serially on the origin CN with the request compiler context; internal SQL and subscription publisher paths carry their own request context.
  • Generate subscription View metadata on the publisher from the same definition and expose it under the subscriber-local database identity.
  • Keep View and CTAS default policies independent; CTAS nullability now uses the rebound View boundary rather than persisted View columns.

Compatibility and bounds

  • Add protocol version 100 (99 is used by row-lock admission; 98 by FORMAT/MAKEDATE/MAKETIME integer signatures; 97 by decimal division; 96 by vector scan) and the additive 4.0.10 tenant migration for the new information_schema.columns definition (after main's 4.0.9 snapshot-quota cluster upgrade); a persisted V58 definition continues to work on newer CNs until migration.
  • Keep system Views and ordinary tables on their existing catalog paths.
  • Preserve creation-time expanded *, SQL mode, default database, security and snapshot semantics from persisted ViewData.
  • Limit one scan to 65,536 View descriptions, one View to 4,096 columns, and one persisted definition to 16 MiB; cancellation is checked during binding/output.
  • The metadata function is private to the information_schema.columns definition; direct SQL use is rejected.
  • Remove the superseded durable recovery coordinator, dependency-recovery migration, work queues, leases, generations and completion fencing from this PR.

Validation

  • Full owning-package suites passed for bootstrap, frontend, planner, compile, table functions, upgrade integration, sysview and process.
  • Focused race tests passed, including real two-CN metadata reads.
  • Real SQL coverage passed for current type/default/nullability, invalid dependency and repair, prepared execution, metadata authorization, subscription metadata, and two-CN visibility.
  • go vet passed; incremental golangci-lint passed with 0 issues; make err-check passed.
  • Changed production statement coverage: 200/226 = 88.50%.
  • New BVT view/view_metadata_on_demand.sql was generated from real SQL, reviewed, and passed original mo-tester comparison twice on the same clean owned service (18/18, twice).

Notes

Public metadata admission no longer depends on a background recovery protocol. For an invalid visible View, batch information_schema.columns scans warn and skip that View while retaining valid rows; direct DESC/SHOW COLUMNS reports the invalid dependency. Cancellation, protocol and internal failures remain fatal. A filtered-out or unauthorized View is not bound. Fixing the dependency makes the next read succeed without recovery state.

@ck89119 ck89119 changed the title fix: fence View metadata recovery and reconcile scoped restores fix: persist bounded View metadata recovery generations Sep 20, 2026

@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.

Deep review of exact head 28e2a61edc24561601526098e9f89585525d0f24 against 3f0a68bd8034d37e098765920f328985c308c9ff. Request changes for two current CI failures introduced by the latest commit, detailed inline.

The previously reported subscription snapshot regression is fixed. I reran the same real-SQL subscriber/publisher probe on this head: current newly added View, historical retained View, historical post-snapshot added View (0 rows), and historical post-snapshot dropped View (1 row) all passed. The earlier design, V58 rolling-upgrade, charset/collation, and PR-description comments also remain resolved.

The new CI run has owning UT and compose/proxy BVT passing, but SCA fails at the new hiddenRows.Close() and pessimistic BVT fails three SHOW CREATE TABLE information_schema.columns checks because the new CTE changed the generated DDL without corresponding result updates. Coverage/CI Required fail downstream. Please fix both checks and rerun them.

Performance evidence from the previous head remains relevant to this mostly metadata-scoping update: on one warm single-CN fixture, V58/current median was 6.1→11.3 ms for one View, 6.3→21.0 ms for a shared-dependency View, and 7.0→33.8 ms for a 55-object scan. This shows overhead; it is not a production-scale benchmark or a separate blocker. I found no additional confirmed resource/cancellation defect in the changed paths.

Comment thread pkg/util/sysview/predefined.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.

Deep review of exact head e4dd1bdef6b3f604b02eba5ee7ef9707f67974cb against b1b68925d7f6fb32153e788b5285f424222e85ca. Request changes: two new, independently reproduced P2 regressions in UDF-backed View metadata, detailed inline.

All four previous inline comments are now addressed: V58 subscription compatibility, charset/collation parity, deferred row cleanup, and all three SHOW CREATE result updates. The prior design-gate discussion is also closed. The definition-authoritative/on-demand design is proportionate and avoids the superseded recovery framework; the remaining problems are incomplete binding-context contracts, not a reason to reintroduce that framework.

Validation at this head:

  • Focused tests passed in seven affected packages. Real SQL TestViewDescriptionPublicSQL and TestViewDescriptionSubscription passed, including prepared reads, source changes/repair, historical snapshots, V58 migration, privileges and charset parity.
  • Reviewer-only two-CN subscription probe passed normally and with -race: non-admin metadata reader, TP/AP scheduling, 1/4 concurrent UNION branches, repeated on the same instance; teardown completed.
  • Live SHOW CREATE output matched all three changed .result rows exactly, including DDL length 20832. Focused sqlclosecheck passed with 0 issues.
  • A separate UDF probe used the same current binary/catalog with V58/current COLUMNS definitions. V58 public-other-database and internal-executor controls passed; current public-other-database and internal-executor cases failed. Current public access while using the View's definition database passed.

No additional confirmed cleanup/cancellation defect was found. Earlier performance evidence remains a non-blocking caution: warm metadata reads grew from roughly 6–7 ms to 11–34 ms depending on dependency/scan shape; this is not production-scale capacity evidence. Prefer workload measurements and focused optimization, not another speculative cache/recovery layer. The PR body should also say protocol 98, matching code.

I did not wait for pending CI or change production code. Please fix both UDF context boundaries and add public/internal regression coverage; treating these valid Views as skippable invalid Views would not fix the contract.

Comment thread pkg/sql/plan/view_regeneration.go Resolved
Comment thread pkg/sql/compile/sql_executor_context.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.

Deep review of exact head 123aef39abd291f21068384b287e4ae09bb771e1, with no subagents. Request changes for one independently reproduced P2 UDF-context defect, detailed inline.

Historical comments:

  • The definition-authoritative/on-demand design and invalid-View error-contract decision remain resolved. The design avoids adding another durable recovery/cache system.
  • The four older inline findings remain addressed: V58 subscription-View compatibility, charset/collation parity, deferred hiddenRows cleanup, and all three SHOW CREATE expected-result updates.
  • The latest two I_S UDF reproducers are fixed: the existing public same/other/no-default-database and no-frontend internal-executor test passed locally at this head. However, the intended database-context contract is not closed across DESC/SHOW COLUMNS: its dependency-recording wrapper loses the new resolver interface.

Validation and closure:

  • Reused exact-head successful required CI; the UT log explicitly records PublicSQL, Privileges, TwoCN, Subscription, and UdfDatabaseContext passing. Previous two-CN TP/AP concurrent subscription-metadata race evidence remains relevant to unchanged isolation/ownership paths; it was not rerun or relabeled as a fresh race run.
  • A separate reviewer-only real-SQL probe passed the same-database DESC and cross-database I_S controls, but failed both cross-database DESC/SHOW FULL COLUMNS. Adding a different same-named UDF in the caller database changed the reported column from BIGINT to VARCHAR(7), confirming wrong resolution rather than a missing-function-only error.
  • Traced private child contexts/processes, partial-batch cleanup, borrowed transactions, cancellation/error propagation, publisher snapshots, prepared dependencies, authorization-before-binding, and scan/expansion/column bounds. No additional confirmed lifecycle defect.

Performance remains a non-blocking caution, not a claimed optimization: earlier warm single-CN V58/current metadata measurements were approximately 6–7 ms versus 11–34 ms depending on dependency/scan shape. These are historical focused measurements, not fresh production-scale capacity proof. Prefer filtered/large-catalog workload measurements and targeted optimization, not speculative caching.

Integration note: this PR and #29387 both currently allocate MORPC v98 for different capabilities. Reconcile the allocation, gates, and tests in whichever lands second; these reviews are scoped to each current head independently. Production code was not modified.

Comment thread pkg/sql/plan/view_regeneration.go Resolved

@aptend aptend 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.

Deep re-review at exact head 5f212fd, following all prior reviews and seven resolved inline threads. I compared the incremental UDF-resolution fix after 123aef3 with the full 56-file on-demand View metadata contract. The DESC/SHOW dependency wrapper now forwards the definition-database resolver, the frontend and internal-executor paths bind UDFs under the View's persisted database/snapshot, and the real SQL regression covers cross-database/no-default callers, conflicting same-name UDFs and prepared SHOW. The earlier V58 subscription, charset, hiddenRows and SHOW CREATE regressions remain closed in the full diff. I found no confirmed new blocking correctness, lifecycle or authorization issue.

Exact-head TestViewDescriptionUdfDatabaseContext and TestViewDescriptionSubscription passed in an isolated worktree with native dependencies; focused plan/compile/sysview tests passed. This approval does not waive CI or merge readiness: the current required Ubuntu UT run failed in TestIssue23861FulltextSnapshotRestore (outside this patch), and the PR is currently conflicting with the advancing main branch. Rebase/resolve and rerun required checks before merge; any changed head needs a fresh review.

# Conflicts:
#	pkg/sql/compile/sql_executor.go
#	pkg/sql/compile/sql_executor_context_test.go
#	pkg/sql/plan/pushdown.go
# Conflicts:
#	pkg/bootstrap/service_statistics_upgrade_test.go
#	pkg/bootstrap/upgrade.go
#	pkg/bootstrap/versions/v4_0_9/upgrade.go
#	pkg/bootstrap/versions/v4_0_9/upgrade_test.go
#	pkg/cnservice/tenant_upgrade_test.go

@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.

Deep review at exact head a3362bc7e0586cc88c1ca8893808afb3a3f523d9: APPROVE. The previous design, rollout, charset/collation, hiddenRows cleanup, SHOW CREATE result, UDF database-context and DESC/SHOW dependency-wrapper findings are all resolved; GitHub shows the corresponding review threads resolved, and the current real-SQL test covers public and internal paths, no/default/other database callers, conflicting same-name UDFs, prepared SHOW and subscription parity. The 4.0.10 tenant migration follows main’s 4.0.9 cluster upgrade and protocol 100 is allocated after row-lock 99; the earlier FORMAT collision in #29387 is no longer live because that PR merged to main on 2026-09-27. The definition-authoritative, on-demand design remains proportionate and avoids a second durable cache/recovery mechanism. Exact-head required CI, UT, SCA, coverage, Connector/J, PROXY and pessimistic BVT pass. Performance caveat: prior focused warm single-CN measurements showed roughly 6–7 ms → 11–34 ms depending on View dependency/scan shape; this is evidence of overhead, not a production-scale capacity benchmark or proof of performance improvement. No additional blocking issue found.

@mergify

mergify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-28 09:33 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-28 09:38 UTC · at ac02c8957644308edb19e68a44751c3844252465

This pull request spent 4 minutes 49 seconds in the queue, with no time running CI.

Reason

Pull request #29139 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/feature kind/refactor Code refactor size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Implement durable View metadata generations and recovery

5 participants