Skip to content

[Refactoring]: Make on-demand derivation the authority for ordinary View metadata #29433

Open
4 of 9 issues completed

Description

@ck89119

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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

Required sequence:

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

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.

Sub-issues

Sub-issues

4 of 9 Issues completed
Loading 9 sub-issues

Activity

  1. self-assigned this
    on Sep 28, 2026
  2. changed the title [-][Refactoring]: Reassess persistent ordinary-view metadata refresh in favor of on-demand derivation[/-] [+][Refactoring]: Make on-demand derivation the authority for ordinary View metadata[/+] on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions