[Bug]: Prepared SHOW CREATE TABLE is not invalidated by cross-session COPY ALTER

オープン
#33,353 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@matrix-meow がすでに取り組んでいます。

2026年11月27日 から。

評価

この issue はまだ評価されていません。

説明

kind/bug needs-triage

Description

Tested on MatrixOne main c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (version() = 8.0.30-MatrixOne-v1.3.0, git_version() = c0cef5c), single CN.

A SQL-level prepared SHOW CREATE TABLE is not invalidated by COPY ALTER committed in another session. Repeated EXECUTE continues returning the definition captured at PREPARE time, even though direct SHOW CREATE, a new PREPARE, and prepared SHOW COLUMNS all see the current schema.

The same missing dependency also lets a snapshot-qualified prepared SHOW CREATE succeed after its named snapshot has been dropped.

Minimal two-session reproduction

-- S0
CREATE TABLE t(a INT,b INT);

-- S1
PREPARE p_create FROM 'SHOW CREATE TABLE t';
PREPARE p_columns FROM 'SHOW COLUMNS FROM t';
EXECUTE p_create;
EXECUTE p_columns;

-- S2, using autocommit; wait for the ALTER to commit successfully
ALTER TABLE t ALGORITHM=COPY,ADD COLUMN c INT DEFAULT 7;

-- S1
EXECUTE p_create;

Actual result: the prepared result still contains only a and b; there is no c.

Expected result: EXECUTE rebuilds or invalidates the old plan and returns the current definition containing c INT DEFAULT 7.

The initial executions are intentional: they warm the logical/compiled-plan reuse path before the cross-session DDL.

Positive controls

After the stale EXECUTE above, all of these see column c:

-- S1
SHOW CREATE TABLE t;
EXECUTE p_columns;
PREPARE fresh_create FROM 'SHOW CREATE TABLE t';
EXECUTE fresh_create;

A same-session COPY ADD also refreshes the prepared statement correctly. The defect therefore requires the PREPARE session and DDL session to be different; it is not an uncommitted-DDL artifact or a general catalog-cache delay.

Other affected COPY operations

The same stale-result behavior was reproduced after each of these cross-session operations:

ALTER TABLE t ALGORITHM=COPY,DROP COLUMN b;
ALTER TABLE t ALGORITHM=COPY,RENAME COLUMN b TO b_renamed;
ALTER TABLE t ALGORITHM=COPY,CHANGE COLUMN b b_changed BIGINT;
ALTER TABLE t ALGORITHM=COPY,MODIFY COLUMN payload VARCHAR(32);

For DROP/RENAME/CHANGE, the old prepared result retains the old column. For MODIFY, it retains VARCHAR(8) instead of the new VARCHAR(32). Direct SHOW CREATE and fresh PREPARE controls return the correct new definition in every case.

Snapshot lifecycle symptom

For a snapshot-qualified prepared SHOW CREATE:

  1. While the named snapshot exists, the old prepared statement correctly returns the historical definition, matching direct historical reads.
  2. After another session drops that snapshot, the old prepared SHOW CREATE still executes successfully and returns the PREPARE-time definition.
  3. In contrast, the old prepared SELECT, direct SHOW CREATE, and a fresh PREPARE all report that the snapshot no longer exists.

This is included in the same report because it has the same empty-dependency root cause; it is not a claim that historical reads while the snapshot exists are wrong.

Root cause

pkg/sql/plan/build_show.go:buildShowCreateTable resolves the table and generates the complete DDL, then rewrites SHOW CREATE into a literal query of the form:

SELECT '<table>', '<CREATE TABLE text>'

That literal SELECT has no table scan from which normal dependency extraction can recover the target table, and this path does not call setShowMetadataDependencies.

In addition, collectPrepareDdlSchemas in pkg/sql/plan/build_dcl.go handles ALTER/CREATE/DROP and related statements but has no ShowCreateTable case. The resulting Prepare.Schemas is empty, so the cross-session EXECUTE schema validation in pkg/frontend/computation_wrapper.go has no object to invalidate. The preparing session's own DDL generation does not advance when another session commits the ALTER.

Prepared SHOW COLUMNS captures its target through setShowMetadataDependencies, explaining the positive control. Snapshot-qualified SHOW CREATE is likewise reduced to literals, so the named-snapshot lifecycle check is bypassed as well.

Validation

All five COPY operation shapes were reproduced in two independent fresh-database runs, with the direct/fresh/prepared-SHOW-COLUMNS controls and base-row checks. The snapshot lifecycle sequence was also independently repeated. Every ALTER itself succeeded; this report concerns stale metadata after successful DDL, not data loss or failure atomicity.

Duplicate check

Open and closed searches covered PREPARE/EXECUTE with SHOW CREATE, stale plans, dependency/invalidation, COPY ALTER, and snapshot lifecycle. No matching issue was found.

Closed #25986 fixed prepared schema-changing DDL that reused stale validation state; it does not cover the SHOW CREATE literal-rewrite entry point, which is still absent from collectPrepareDdlSchemas. Closed #26882 concerns COM_QUERY view plan caching, and closed #29180 concerns Connector/J server-prepared SELECT * result metadata. Neither owns this SQL-level prepared SHOW CREATE path. Open architecture trackers such as #32278 do not contain this reproduction.

主要言語
Go
スター
1.9k
フォーク
312
平均マージ
21時間 57分
マージ済み PR(30日)
730

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

matrixorigin/matrixone のほかの issue

matrixorigin/matrixone の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。