Skip to content

fix(planner): invalidate SHOW metadata after target replacement - #29451

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

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-29006-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 28, 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 #29006; part of #26227.

Scope was revalidated against the approved on-demand View metadata design merged in #29139. This PR fixes a demonstrated stale-metadata path under that design; it does not implement the original durable authority/lease/recovery checklist or automatically close #29006.

What this PR does / why we need it:

SHOW COLUMNS records its target as a catalog dependency only when the target is already a View. A prepared SHOW against an ordinary table therefore misses replacement of that target by a View and can keep reading persisted View columns instead of using on-demand binding.

Reproduced through two real SQL sessions:

  1. Prepare and execute SHOW against a table with VARCHAR(5).
  2. Another session replaces the table with a View, then widens its source to VARCHAR(60).
  3. The prepared SHOW still returns VARCHAR(5), while information_schema.columns reports 60.

Record the target dependency for every SHOW COLUMNS plan, preserving the existing View source dependencies. The existing prepared-plan and COM_QUERY validation paths then handle target identity/version changes. No new protocol fields, feature gates, background workers, leases, or global caches are introduced.

Tests cover ordinary/FULL/LIKE/WHERE plans, dependency copy/wire/PREPARE propagation, preservation of View source dependencies, and an ordinary SELECT control. The existing public SQL fixture now exercises binary and SQL PREPARE plus COM_QUERY across table → View → table replacement and rejects a missing target. The existing BVT adds a two-session SQL PREPARE regression.

Validation

Go 1.26.4, Darwin arm64, repository mo-cgo-test wrapper:

  • Pre-fix planner UT and real binary prepared reproduction failed for the intended stale-metadata reason; post-fix tests pass.
  • Full ./pkg/sql/plan and ./pkg/tests/upgrade suites passed.
  • Focused frontend catalog-dependency, prepared-schema, and cursor-fetch tests passed.
  • Final TestViewDescriptionPublicSQL passed after adding the row-error assertion.
  • go vet, incremental golangci-lint v2.6.2 built with Go 1.26.4, and make -j2 build passed.
  • Changed production statements: 2/2 covered (100%).
  • mo-tester generated the result, which was reviewed; normal comparison passed 30/30 twice on the same clean, test-owned standalone instance. Database teardown was verified after each run; the service was stopped.

The on-demand design preserves the caller's visible catalog snapshot; it does not require retroactively invalidating an already-materialized cursor after unrelated DDL. This focused fix leaves shared barrier, recovery, and COMMIT protocols unchanged.

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

@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 feb577b121ad07c57f0fb7b350620294a6e4ec4e, merge-base d99187d7b3bfda8744088b3ae8cf16739b690aa0. APPROVE: no blocking findings. Reviewed directly without subagents.

Design. The fix belongs at the dependency producer: an ordinary SHOW target determines plan-time formatting and the choice of metadata row source, so it must be tracked before it can be replaced by a View. Moving target capture outside the View-only condition closes that omission using the existing validation/rebuild machinery. It aligns with the approved on-demand metadata design and #29006's revised scope. This ordinary bug fix needs no additional state machine or feature design document.

Closure checked. I read every changed hunk and followed target resolution -> dependency capture/deduplication -> plan deep copy/wire/PREPARE -> prepared schema validation and COM_QUERY checkModify -> rebuild/error handling. Target identity/version and database identity are captured, existing View source dependencies remain, and subscription/publisher identity is retained by ObjectRef copying and consumed by existing validators. The new capture uses the same caller-visible resolution as SHOW; it does not open a new transaction or select a different snapshot. DescribeView child-context cleanup and error propagation remain intact.

The new entry is plan-owned, deduplicated and released with the plan. No new worker, wait, retry, global cache or cross-request description owner is introduced. Missing targets continue to fail rather than yielding stale/empty metadata. Already-materialized cursors are outside this dependency-capture change; the broader cursor/authorization/snapshot matrix is not newly proven by this PR.

Independent QA. On Darwin/arm64, Go 1.26.4 with verified matching native inputs:

  • TestShowColumnsTracksTargetDependency passed (all six subtests), including FULL/LIKE/WHERE, copy/wire/PREPARE propagation, View source retention and ordinary SELECT control.
  • TestViewDescriptionPublicSQL passed, including the PR's two-session table -> View -> table replacement and missing-target checks.
  • I extended that same isolated fixture with an adjacent challenge: after the missing-target error, recreate the target and reuse the same prepared handles; then CREATE/DROP a unique index while keeping the target table itself. Binary PREPARE, SQL PREPARE and COM_QUERY all recovered and refreshed SHOW's Key from empty -> UNI -> empty. The complete test passed in 12.14s; the replacement/challenge subtest took 0.23s. Reviewer additions remain local and do not modify this PR.

Reused CI run 36417143965 after checking its head. The UT checkpoint confirms successful planner shards and actual upgrade-package execution, not just compilation. The compose BVT log confirms view_metadata_on_demand.sql ran 30/30, zero failed/ignored/abnormal, in 0.874s. The author also reports full owning-package validation and two normal BVT comparisons with teardown on the same instance.

Engineering/performance. The production change is +5/-1 lines. Ordinary-table SHOW adds one dependency and one corresponding validation lookup; it does not invoke the View binder for ordinary tables or disable general SELECT caching. The tests reuse existing planner/public-SQL/BVT fixtures and add distinct reuse/identity oracles. No material performance regression or overengineering found; no throughput improvement is claimed.

There are no previous human or inline review comments on this PR. This approves the demonstrated SHOW dependency fix; #29006's broader acceptance map should remain open, as the PR description already states.

@mergify mergify Bot added the queued label Sep 28, 2026
@mergify

mergify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-28 13:28 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-09-28 13:37 UTC · at feb577b121ad07c57f0fb7b350620294a6e4ec4e

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

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/native-dependency-check.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

@mergify mergify Bot added dequeued and removed queued labels Sep 28, 2026
@mergify mergify Bot removed the dequeued label Sep 28, 2026
@XuPeng-SH
XuPeng-SH merged commit 3dc291c into matrixorigin:main Sep 28, 2026
20 of 21 checks passed
@ck89119
ck89119 deleted the issue-29006-main branch September 29, 2026 02:56

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/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Validate and harden on-demand View metadata execution and plan reuse

3 participants