Repository navigation
Description
Parent Issue
Parent issue: #29433
Detail of Subtask
Phase S2. Depends on: #29436
Implement the approved common derivation boundary, initially without cross-request caching or persistent refresh writes.
Deliverables:
- Derive the complete output schema through the authoritative binding/provenance rules used for view creation. Return immutable derived columns plus dependency/visibility evidence; do not patch only selected type fields.
- Use a request-owned context carrying the visible schema snapshot, transaction-local catalog changes, effective account, saved default database/SQL mode/name rules, security semantics, subscription mapping, and historical-snapshot identity.
- Preserve stabilized SQL, explicit view column names, and persisted identity/ownership. Reading must not rewrite ViewSql or alter the catalog object.
- Add bounded statement-local memoization for repeated/shared nested dependencies. Detect cycles, enforce depth/work/memory limits, and release all state on success, error, and cancellation.
- Capture dependencies needed to prove safe reuse, including intermediate views and base objects. Existing persisted direct dependencies alone are not a transitive cache validity proof.
- Distinguish invalid definitions, unsupported persisted protocols, unavailable dependencies, cancellation, and retryable schema changes using the approved public error mapping.
Acceptance criteria:
- Derivation runs no view data query, launches no background worker, writes no metadata rows, and enqueues no durable work. Avoid unneeded optimizer/statistics work; any required catalog I/O is bounded and measured.
- Type/width/scale/nullability/default/expression semantics match the authoritative contract, including aliases, joins, nested views, and explicit column lists.
- Statement-local reuse cannot cross incompatible snapshots or survive own-transaction DDL into a later statement with stale results.
- Deterministic unit tests cover shared dependencies, cycles, cancellation, schema replacement, context isolation, and release paths. Cache-free execution is the reference oracle.
- New code remains behind the rollout boundary approved in S1; this task does not change default public behavior.
Describe implementation you've considered
Factor/reuse the read-only inference portion of RegenerateViewDefinition/genViewTableDef and the existing binding resolver. Do not call refreshOneView or guarded catalog replacement from a metadata read. Keep derived results separate from shared mutable TableDef instances.
Additional information
Current anchors: pkg/sql/plan/view_regeneration.go; pkg/sql/plan/build_ddl.go; pkg/sql/plan/view_dependency.go; pkg/sql/compile/view_metadata_recovery.go context adapters. Preserve the useful context semantics without importing recovery-worker lifecycle ownership.
Planning baseline: b9013dc6bb058ec74935a62ac3a35f57d13c2f98. This issue records future work, not completed implementation or fresh test evidence. All production work is subject to the approved versioned design from S1. Ordinary views only; materialized-view refresh and unrelated SQL compatibility work are out of scope.
Activity