Skip to content

fix(sysview): hide temporary tables from information schema - #26298

Merged
XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
iamlinjunhong:m-25405
Jul 30, 2026
Merged

XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
iamlinjunhong:m-25405

Conversation

@iamlinjunhong

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:

issue #25405

What this PR does / why we need it:

fix(sysview): hide temporary tables from information schema

@iamlinjunhong
iamlinjunhong requested a review from a user July 28, 2026 06:05
@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 →

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jul 28, 2026

@gouhongshen gouhongshen 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.

Codex automated review

The original prefix-collision and incomplete metadata-view blockers are fixed. The prior whitespace examples are also fixed, but the legacy classifier remains blocking because it classifies request-wide SQL rather than the statement that created each table. Focused tests could not run because cgo/libmo.dylib is absent.

P1 - Classify the creating statement, not the entire COM_QUERY (pkg/catalog/temp_table.go:51)

Author response: a7311f6 replaces the prior ltrim/LIKE check with a whitespace-tolerant regexp and tests newlines, tabs, and repeated spaces; those exact cases are fixed. Why this remains blocking: rel_createsql comes from ctx.GetRootSql(), while TxnCompilerContext.GetRootSql() falls back to ses.GetSql(), which doComQuery sets to the entire multi-statement input. For the supported request CREATE TEMPORARY TABLE t(...); CREATE TABLE p(...), permanent table p therefore has relkind r but rel_createsql beginning with CREATE TEMPORARY TABLE, so this predicate hides p from SHOW/information_schema and excludes it from snapshot/data-branch enumeration. Reversing the statements makes an old-version temporary row miss the anchored regexp; legal comments between keywords do likewise. Persist or classify statement-specific canonical DDL with a migration/drain contract for legacy rows, and cover both multi-statement orders and comments.

@gouhongshen gouhongshen 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.

Codex automated review

The earlier broad-prefix collision and incomplete information_schema coverage blockers are fixed: all four metadata views now use the shared predicate and are upgraded. The prior legacy SQL-format and request-wide-statement blocker is also addressed for normal names by parsing statements and persisting canonical per-statement DDL. One distinct legacy-name impersonation blocker remains.

P1 - Do not hide a permanent legacy table that mimics a temporary physical name (pkg/sql/plan/function/func_mo_is_legacy_temporary_table.go:103)

Author response: cdd5f3cc7 replaces the request-prefix regexp with parsed statement/alias matching, and newly created tables persist statement-specific canonical DDL. Why this remains blocking: pre-upgrade rows still retain request-wide rel_createsql and lack a durable temporary marker. Before upgrading, a legal request such as CREATE TEMPORARY TABLE t (...); CREATE TABLE __mo_tmp_123e4567e89b12d3a456426614174000_db_t (...) creates a permanent relkind = 'r' row whose stored SQL contains the temporary statement (the old create path used GetRootSql). The new function decodes that permanent name to logical alias t and returns true on the first statement at line 103, so the shared predicate removes the permanent table from SHOW/information_schema and snapshot/data-branch enumeration. This is distinct from the earlier broad-prefix finding: it requires the exact generated-name layout plus a matching legacy multi-statement request, and is introduced by the new statement-association classifier. Close it with a non-spoofable durable classifier/migration or an enforced namespace contract that also safely handles existing permanent rows; add this legacy regression.

@gouhongshen gouhongshen 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.

Codex automated review

All previous blockers are resolved: durable relkind classification fixes broad-prefix collisions; all four metadata views and upgrade paths are covered; statement-specific DDL fixes formatting/request-wide ambiguity; and the latest change preserves temp-shaped permanent tables using explicit CREATE precedence and rename metadata. Focused tests could not run because cgo/libmo.dylib is absent.

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

Reviewed updated exact head b7d40a627fc99b8ab87cde9b20d160df92e8894e. The previous metadata-view, legacy-format, multi-statement, and permanent-name collision blockers are fixed. One direct DML regression from the new durable marker remains.

P1 — INSERT IGNORE into every newly created temporary table now fails

MarkTableDefTemporary changes the resolved TableDef.TableType from ordinary r to temporary_table. The modern insert binder at pkg/sql/plan/bind_insert.go:1287-1292 treats every non-ordinary/non-index table type as a vector/text index table when the statement is not ODKU. Plain INSERT happens to survive because build.go:83-86 permits its legacy fallback, but INSERT IGNORE is encoded as a one-element nil OnDuplicateUpdate; it is neither ODKU nor eligible for that fallback. The user therefore receives unsupported DML: insert into vector/text index table for a normal temporary table.

I reproduced this deterministically by marking the existing planner mock table with the new catalog helper, setting its resolved session IsTemporary bit, and planning insert ignore into nation values (...). The focused new relkind, canonical-DDL, and legacy-classifier tests pass, while this probe fails exactly at the guard above.

Please treat SystemTemporaryTable / IsTemporary as a normal user DML target in the modern insert routing (without opening the internal vector/index table types), and add planner plus BVT coverage for plain INSERT, INSERT IGNORE, and ODKU against a temporary table with the persisted marker.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

Reviewed updated exact head b7d40a627fc99b8ab87cde9b20d160df92e8894e. The previous metadata-view, legacy-format, multi-statement, and permanent-name collision blockers are fixed. One direct DML regression from the new durable marker remains.

P1 — INSERT IGNORE into every newly created temporary table now fails

MarkTableDefTemporary changes the resolved TableDef.TableType from ordinary r to temporary_table. The modern insert binder at pkg/sql/plan/bind_insert.go:1287-1292 treats every non-ordinary/non-index table type as a vector/text index table when the statement is not ODKU. Plain INSERT happens to survive because build.go:83-86 permits its legacy fallback, but INSERT IGNORE is encoded as a one-element nil OnDuplicateUpdate; it is neither ODKU nor eligible for that fallback. The user therefore receives unsupported DML: insert into vector/text index table for a normal temporary table.

I reproduced this deterministically by marking the existing planner mock table with the new catalog helper, setting its resolved session IsTemporary bit, and planning insert ignore into nation values (...). The focused new relkind, canonical-DDL, and legacy-classifier tests pass, while this probe fails exactly at the guard above.

Please treat SystemTemporaryTable / IsTemporary as a normal user DML target in the modern insert routing (without opening the internal vector/index table types), and add planner plus BVT coverage for plain INSERT, INSERT IGNORE, and ODKU against a temporary table with the persisted marker.

fixed

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

Re-reviewed at f1ae36d. The prior temporary-table INSERT blocker is closed: marked/session-resolved temporary tables now stay on the ordinary DML path, while internal index table types remain rejected. Planner coverage includes plain INSERT, INSERT IGNORE, and ODKU, with matching distributed regression coverage. I also rechecked the durable marker/legacy catalog classification and upgrade-view changes. Relevant catalog, planner/function, sysview, bootstrap, frontend, and disttae test packages pass locally.

@mergify

mergify Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-30 09:47 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-30 10:27 UTC · at 37e1f36b29b6acc790f53a7799465efbceeceeb1

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

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

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

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

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants