Repository navigation
Description
Why do you want to refactor this code?
Direction decision: make on-demand derivation the long-term authority for ordinary-view output metadata. Cross-request caching is optional and evidence-gated. Durable asynchronous metadata refresh is not the target architecture for this series.
This tracker replaces the earlier open-ended evaluation in #29433 with a design-first roadmap. The direction is selected; the detailed implementation contracts still require approval in #29436. No kernel implementation, activation, fresh runtime reproduction, or benchmark is claimed by this planning update.
Problem and verified current structure
The original user-visible bug is documented in #26227: after source-column DDL, query results and DESC/information_schema can disagree. That issue reports reproduction at an older commit; it has not been rerun at this planning baseline.
Source inspected at b9013dc6bb058ec74935a62ac3a35f57d13c2f98:
- bindView reparses/binds stored SQL. It also reads persisted view columns at the CTAS-default boundary, so query planning is not entirely independent of those columns.
- SHOW COLUMNS and information_schema column definitions read stored column metadata; subscriptions have another metadata provider.
- mo_view_refresh persists generations/status/retries/leases, and refreshOneView regenerates and replaces column/definition metadata. This is not materialized-view data refresh.
- Refresh gates are structurally false, but inactive mutation paths still acquire lifecycle locks and revalidation markers. Disabled refresh does not mean zero runtime coupling.
- Existing ordinary/prepared plan consumers already have identity/version validation facilities. They are reuse candidates, not proof that a new metadata cache is snapshot-safe.
The required outcome is consistent observable metadata, not mandatory persistence of every derived column change. A durable asynchronous copy adds coordination, DDL fan-out, recovery state, and stale/pending-read policy. On-demand derivation can instead use the schema visible to the requesting statement.
Describe the solution you'd like
Architectural contract
- Persist facts, derive outputs. Persist stable view definition, identity, ownership/security attributes, and creation environment. Preserve creation-time star expansion and explicit column names. Derive output columns through the same authoritative inference/provenance rules used by view creation, not a parallel simplified algorithm.
- One visibility boundary. Given the same definition, binding context, and visible schema snapshot, all required consumers use the same derived schema, with explicit surface-specific presentation rules. Current reads obey their transaction/statement snapshot; historical reads are not silently upgraded to latest metadata. Include own-transaction DDL.
- Read-only correctness. Metadata reads do not execute the view data query, rewrite catalog definitions, enqueue durable refresh, or depend on worker health. Failed derivation must not silently present stale stored columns as current. Define invalid-view single-object/bulk semantics before implementation.
- Request-owned baseline. Start with bounded statement-local reuse, immutable results, cycle/depth/work limits, correct cleanup and cancellation. Keep view/CTAS provenance behavior consistent. Audit both planning and metadata-reading consumers.
- Security and context remain authoritative. Preserve tenant isolation, approved definer/invoker semantics, subscriptions, saved parsing environment, snapshot identity, and protocol gates. Schema reuse cannot cache authorization decisions or bypass metadata visibility/rewrite rules.
- Optional cache only. If measured workloads justify it, add a bounded disposable CN-local cache. Validate the full dependency closure (including intermediate views and base objects), object identities/versions, and request visibility. View-own-version or TTL alone is insufficient. Bypass unsupported cases; restart/eviction affects cost only. No new durable queue/lease/cluster protocol solely for caching.
- Do not silently change the raw catalog contract. S1 must decide how direct mo_catalog.mo_columns consumers receive compatible semantics. An adapter/virtualization boundary or explicit compatibility contract must be approved; changing only SHOW while leaving required consumers stale is incomplete.
- Preserve independent infrastructure. Retiring view refresh does not authorize deleting persisted-expression protocol floors, snapshot/tenant guards, or shared admission/barrier infrastructure merely because it has a View-prefixed name.
Data flow and ownership
request visibility + authorization + persisted view definition -> common read-only derivation/binding boundary -> immutable output schema + dependency evidence -> planner/CTAS/protocol metadata and introspection adapters.
The request owns initial derivation/memoization state. A selected future cache is owned by its local CN and never owns live transaction/session resources. Catalog state remains authoritative for identity/definition/visibility, not a background task completion flag.
Phased work and dependency graph
- [Subtask]: Approve the on-demand View metadata contract and consumer migration design #29436 — S1: Approve the on-demand View metadata contract and consumer migration design
- [Subtask]: Introduce a read-only on-demand View schema derivation boundary #29437 — S2: Introduce a read-only on-demand View schema derivation boundary
- [Subtask]: Unify planner, CTAS, and reusable-plan consumers on derived View metadata #29438 — S3: Unify planner, CTAS, and reusable-plan consumers on derived View metadata
- [Subtask]: Serve View introspection metadata through on-demand derivation #29439 — S4: Serve View introspection metadata through on-demand derivation
- [Subtask]: Validate on-demand View metadata across DDL, security, restore, and version boundaries #29440 — S5: Validate on-demand View metadata across DDL, security, restore, and version boundaries
- [Subtask]: Benchmark on-demand View metadata and decide whether cross-request caching is needed #29441 — S6: Benchmark on-demand View metadata and decide whether cross-request caching is needed
- [Subtask]: Conditionally add a bounded disposable cache for derived View metadata #29442 — S7: Conditionally add a bounded disposable cache for derived View metadata
- [Subtask]: Roll out on-demand View metadata and retire refresh-specific runtime maintenance #29443 — S8: Roll out on-demand View metadata and retire refresh-specific runtime maintenance
- [Subtask]: Retire legacy View refresh catalog artifacts after the compatibility window #29444 — S9: Retire legacy View refresh catalog artifacts after the compatibility window
Required sequence:
- [Subtask]: Approve the on-demand View metadata contract and consumer migration design #29436 -> [Subtask]: Introduce a read-only on-demand View schema derivation boundary #29437 -> [[Subtask]: Unify planner, CTAS, and reusable-plan consumers on derived View metadata #29438, [Subtask]: Serve View introspection metadata through on-demand derivation #29439 in parallel] -> [[Subtask]: Validate on-demand View metadata across DDL, security, restore, and version boundaries #29440, [Subtask]: Benchmark on-demand View metadata and decide whether cross-request caching is needed #29441] -> [Subtask]: Roll out on-demand View metadata and retire refresh-specific runtime maintenance #29443 -> [Subtask]: Retire legacy View refresh catalog artifacts after the compatibility window #29444.
- Benchmark harness/baseline work in [Subtask]: Benchmark on-demand View metadata and decide whether cross-request caching is needed #29441 may start after S1; final evidence requires the migrated consumers.
- [Subtask]: Conditionally add a bounded disposable cache for derived View metadata #29442 is conditional on [Subtask]: Benchmark on-demand View metadata and decide whether cross-request caching is needed #29441. It blocks [Subtask]: Roll out on-demand View metadata and retire refresh-specific runtime maintenance #29443 only if the approved benchmark decision makes it a rollout requirement. Otherwise defer/close it as not needed without delaying correctness delivery.
- Final catalog cleanup in [Subtask]: Retire legacy View refresh catalog artifacts after the compatibility window #29444 is deferred until the compatibility window permits it; retaining a documented compatibility stub is acceptable.
Mandatory design decisions before implementation
S1 owns closure of: direct-catalog freshness/representation; invalid-view behavior by surface; the consumer and provenance contract; legacy views with missing environment or historical star expansion; snapshot/own-DDL semantics; security/subscription mapping; and exact mixed-version/rollback eligibility. It also sets numeric resource and performance budgets. No blocking decision is delegated to an implementation guess.
The versioned design must link this tracker and its approved revision. This issue series is a roadmap, not a substitute for that approval.
Validation and success criteria
- After source DDL visible to a new statement, required query/CTAS/introspection surfaces agree under equivalent visibility; test type/width/scale/nullability/default/expression metadata, aliases, nested/shared dependencies, and frozen star semantics.
- Validate same-name DROP/CREATE, metadata-only/COPY changes, cancellation, cycles, concurrent DDL, tenant authorization, subscriptions, named/historical snapshots, restore/clone/PITR, and old/new binary operation where applicable.
- Cover ordinary and prepared/cached/cursor consumers with correct snapshot semantics. Do not require an already-running historical reader to expose a later schema.
- Use independent public SQL and typed inference oracles. Each implementation task owns focused tests; S5 closes cross-component boundaries. Use deterministic scheduling rather than sleeps, and no fresh pass claims without exact-head evidence.
- Benchmark selective and bulk metadata reads, repeated introspection, nested dependency shapes, cold/warm paths, memory/allocation cost, and DDL overhead against approved budgets before selecting a cache.
- Complete read migration before stopping compatibility maintenance; validate rollback before allowing an old reader to use potentially stale stored columns. Keep legacy tables until supported mixed-version/restore/upgrade paths no longer require them.
- After retirement eligibility, metadata correctness is independent of refresh-worker availability and no refresh-only DDL/global-lock/state maintenance remains. Unrelated safeguards are preserved.
Scope boundaries
Ordinary-view output metadata only. This is not materialized-view data refresh, a generic distributed metadata framework, a rewrite of independent provenance semantics, or a commitment to cross-request caching. Partition behavior, charset/collation changes, stored procedures, UDFs, and warning compatibility are not expanded by this series; preserve existing context where required without taking ownership of unrelated fixes.
Describe alternatives you've considered
- Durable asynchronous maintenance: efficient scanning of already-materialized metadata, but requires reverse invalidation, pending-read policy, retries/leases, recovery, and compatibility coordination. Not the selected long-term direction; any still-required durable contract must be identified explicitly in S1 rather than carried forward by default.
- Synchronous dependent-view maintenance during DDL: can atomically update persisted output metadata, but amplifies DDL work/locking with dependency fan-out and invalid-view handling. Reconsider only if a concrete raw-catalog contract cannot be satisfied otherwise.
- On-demand with immediate global caching: may reduce repeat binding, but adds validity/lifetime/resource complexity before need is proven. Rejected as the default starting point; S7 is evidence-gated.
On-demand derivation trades eager maintenance/recovery for read-time binding cost. Full-schema introspection can be more expensive. This design direction is not a claim of universal performance superiority or verified MySQL/TiDB implementation equivalence.
Additional information
Relationship to existing issues
- [Bug]: View metadata stays stale after source column type changes #26227 remains the original stale-view-metadata bug and behavioral acceptance source. Its current implementation scope is persistence-oriented; reconcile it explicitly with this roadmap before claiming the bug is resolved. Do not automatically close it.
- [Bug]: View projection loses ENUM/SET ordering and CTAS type metadata #26226/[Bug]: View metadata drops source defaults and breaks View CTAS inserts #26232 own the output-metadata/provenance contract to reuse; this series changes metadata authority/lifecycle, not those independent rules.
- [Subtask]: Define catalog metadata barrier wire and snapshot contract #29003/[Subtask]: Implement HAKeeper catalog metadata capability barrier #29004 are closed prior wire/barrier tasks; audit and retain shared assets that still serve other protocols.
- [Subtask]: Implement durable View metadata generations and recovery #29005/[Subtask]: Validate and harden on-demand View metadata execution and plan reuse #29006/[Subtask]: Activate and validate the View metadata lifecycle #29007 are open tasks for the previous durable recovery/metadata-authority/activation route. They are not prerequisites of this on-demand roadmap. Their view-refresh-specific direction is superseded in this tracker; reconcile disposition with owners rather than implementing both architectures or silently closing them. This planning update does not edit or close those issues.
- [Bug]: CREATE ACCOUNT globally serializes on the View metadata gate and times out concurrent account operations #28079, [Bug]: Unrelated CREATE/DROP and ALTER transactions deadlock on inverted View/SNAPSHOT catalog gates #28317, [Bug]: retrying interrupted 4.2→main upgrade stalls on missing mo_view_refresh #29396, and [Bug]: Slow DROP DATABASE blocks unrelated database DDL on the global SNAPSHOT lifecycle gate #29400 provide relevant lifecycle/upgrade failure scenarios, not proof that this refactor fixes every report. [Bug]: information_schema.columns exposes columns hidden by row-column rewrite rules #29095 is relevant to metadata rewrite visibility.
Only this parent and the new subtasks are being updated/created for the design request. Code, old issues, production configuration, and activation status are unchanged.
Activity
[-][Refactoring]: Reassess persistent ordinary-view metadata refresh in favor of on-demand derivation[/-][+][Refactoring]: Make on-demand derivation the authority for ordinary View metadata[/+]fix: make View metadata migration idempotent (#29468)
perf: add S6 view benchmarks and defer regexp map allocation (#31035)
fix(view): preserve restore semantics and extend S5 conformance (#30953)
fix: consolidate stopped-upgrade cleanup and stabilize CI (#32307)