Skip to content

fix(sql): keep temporary table aliases consistent - #30864

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/cfbcbef2f9e2a14d981ed731acbbb75fcad81bcda3f398cc39754fa7e90dc056
Oct 25, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/cfbcbef2f9e2a14d981ed731acbbb75fcad81bcda3f398cc39754fa7e90dc056

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 22, 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:

#30583

What this PR does / why we need it:

Temporary-table aliases were keyed by database + "." + alias, so dotted database and alias names could collide. A temporary alias could also remain after its physical relation was removed by another session, leaving the name unusable.

This change uses one length-prefixed key for all temporary-table alias maps and lifecycle paths. Confirmed missing temporary databases or relations forget the alias while preserving existing IF EXISTS and error semantics, including DROP executed by stored procedures. This logical cleanup removes rollback history and generation-owned hidden index aliases without queuing a physical DROP that could target a replacement table. Independent temporary indexes reuse their root generation prefix; legacy names never authorize an inferred sibling cleanup.

Validation:

  • Frontend and compile owning-package unit tests; frontend package race tests.
  • Focused missing-table planner, background-adapter and generated-child ownership tests, including legacy names, transient lookup failures, rollback, reused names and capacity recovery. Each focused race test passed 100 repetitions.
  • Incremental frontend static analysis: 0 issues.
  • Normal mo-tester comparison for temp_ddl_transactions.sql on a native service: 124/124 statements in each of two rounds on the same instance, with zero failed/ignored/abnormal statements and zero test databases remaining after each round. Includes external database removal followed by stored-procedure DROP error, recreation and successful DML.

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

@MatrixAdventurer

Copy link
Copy Markdown
Contributor

pkg/frontend/temporary_ddl.go:96-117(RetireTemporaryTable 新增的缺表清单回收启发式)存在误删无关临时表的风险。按 TrimSuffix(physical, alias) 得到的前缀扫描 tempTablesRev 的做法,仅当归属是真实子索引时成立:这套隔离依赖 temporaryDDLSession 生成的带 generation 物理名(__mo_tmp_<sid>_<db>_<gen>_<alias>),但会话注册表里同时存在无 generation 的物理名——旧协议会话(supportsSessionTemporaryDDL < MORPCVersion55 时 sessionTemporaryDDLOwner 直接返回 false,建表走 physicalTemporaryTableName)以及 executor 事务/CTAS/内部 SQL 路径创建的表都是 __mo_tmp_<sid>_<db>_<alias>。对这类表执行 DROP 遇到 ErrBadDB/OkExpectedEOB/ErrNoSuchTable 时,ddl.go:4939-4960 的 retireMissingTemporary 会以 indexes=nil 直接触发本启发式,前缀只剩 __mo_tmp_<sid>_<db>_,结果把同库中其余健康临时表(含其索引)全部从 tempTablesRev/tempTables/tempTableIdentities 移除,别名失效,用户后续查询报 no such table 甚至解析到同名永久表。建议:在 PublishTemporaryTable/建索引时显式记录"根→子表"归属关系并按记录精确回收;或仅当 physical 名确含本表 generation 组件时才启用前缀扫描,无 generation 的物理名只回收根别名本身。

@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 24, 2026
@XuPeng-SH

XuPeng-SH commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 57d460d6a5b4518d24c538e4e11c481423484056

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 57d460d6a5b4518d24c538e4e11c481423484056

Assessment: request_changes

Reviewed all 17 changed files and affected callers. Shared alias encoding and separating logical cleanup from physical retirement are appropriate, but missing-table recovery remains incomplete for stored procedures and hidden indexes.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/frontend/compiler_context.go:734: Another session drops and recreates the backing database, then the owning session calls a stored procedure containing DROP TEMPORARY TABLE without IF EXISTS.
    Impact: backSession does not implement MissingTemporaryTableForgetter, so planning leaves the stale upstream alias registered. CALL returns 'no such table', but subsequent CREATE TEMPORARY TABLE still reports 'table already exists'. Forward the forgetting operation through the background-session adapter to complete the intended recovery.
    Evidence: Confirmed through real SQL: CALL returned error 1146 and recreation returned error 1050; direct DROP on the same connection then allowed recreation and successful DML. See public-sql-v2.log and checks/1792883229832811926-3.json. The focused background-session planner probe independently fails in background-focused.log.

  • P2 pkg/frontend/temporary_ddl.go:91: Create a temporary table and an independent index, let another session drop/recreate its database, then DROP the stale root alias.
    Impact: ForgetMissingTemporaryTable removes only the root. The generation-scoped child cleanup remains in RetireTemporaryTable, which the missing-root path no longer calls. Hidden aliases accumulate and eventually prevent new temporary tables at the 1,024-entry limit, despite no live roots. Reuse safe child-ownership cleanup without scheduling physical deletion.
    Evidence: The production planner probe confirms that the root disappears while its generated child alias remains. The lifecycle probe reaches 1,024 retained aliases, zero live roots and zero retired entries, then fails CheckTemporaryTableCapacity. See frontend-focused.log and checks/1792883147312686485-3.json.

Validation:

  • Artifacts are retained under /home/xupeng/.local/state/mo-bot/jobs/899f56f15a79702dc7ddee8a/attempt-1. Audit matched 11 command/source/exit receipts to logs, verified native provenance and confirmed unchanged frozen source; audit receipt: checks/1792883439168305581-4.json.

  • Isolation preflight and current-revision make cgo passed. Focused frontend/compile tests passed for dotted identities, migration, rollback journals, legacy-prefix isolation, reused-name safety, direct DROP recovery and index naming.

  • Exact temp_ddl_transactions.sql/result passed normal mo-tester comparison twice on one instance: 113/113 statements each, with SQL/ISCP readiness and database teardown verified.

  • Real SQL verified dotted-name isolation and reproduced the stored-procedure defect. Planner/session probes reproduced hidden-index retention and capacity exhaustion.

  • Isolated empty-map lookup benchmark: base expression 12.13–12.21 ns, zero allocations; new encoding 68.86–75.97 ns, one 32-byte allocation. This is a measured lookup cost, not a demonstrated SQL-throughput regression.

Limitations:

  • Full owning-package and race suites were not rerun locally. Supplied CI statuses are successful, but detailed CI execution logs were not supplied.

  • Index-capacity exhaustion was demonstrated through production planner/session methods with mocked storage; stored-procedure failure was reproduced through a real SQL service.

  • The first SQL probe used invalid procedure-body syntax; that diagnostic failure was excluded and corrected in the retained v2 probe.

  • The full linked issue #30583 discussion was absent from the frozen evidence.

@XuPeng-SH

XuPeng-SH commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4d3fc54b830b0b78c623f1e84fd4ff71601c6f63

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 4d3fc54b830b0b78c623f1e84fd4ff71601c6f63

Assessment: approve

Reviewed the complete 19-file delta and affected callers. Injective alias keys, session-owned logical cleanup, and generation-scoped child cleanup restore the intended invariants without duplicating lifecycle ownership. The five earlier review concerns are addressed; no actionable unresolved defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified frozen source, matching patch, clean checkout, diff whitespace and formatting of all 17 changed Go files.

  • Isolation preflight passed. Recovered a repository-owned native build after verifying 192 matching inputs, 62 artifacts, and its build receipt/log; rejected the stale initial candidate.

  • Focused tests passed: 109 test/subtest events, including all 10 new test entrypoints. Full defines, planner and process packages passed.

  • Five exact lifecycle tests each passed 100 race-enabled repetitions. The full compiler race suite passed. Frontend results and fixture recovery are qualified below.

  • Authenticated SQL probe passed two recovery rounds on one native instance, covering direct DROP, temporary DROP, stored procedures, independent indexes, transaction recreation, DML and dotted-name isolation.

  • Isolated lookup benchmark measured 72.60–77.61 ns and one 48-byte allocation versus 12.21–12.43 ns and zero allocations for the base expression. This bounded correctness cost adds no ordinary-resolution storage I/O or goroutines.

  • Evidence audit reconciled 16 checks with commands, source fingerprints, exit statuses and retained logs. Artifacts: /home/xupeng/.local/state/mo-bot/jobs/fdf53ce5cb97c9cdb82f7547/attempt-1/validation-audit.json and review-map.md. Audit receipt: checks/1792889335515837863-2.json.

Limitations:

  • The full frontend race command failed only because unchanged Test_openNewFile_nilCtx writes into the read-only checkout. That test passed separately with a diagnostic-only t.TempDir fixture adjustment; the original package failure remains recorded. Three unrelated existing subtests skipped.

  • The complete mo-tester suite and SQL throughput benchmarks were not run locally. Author claims and supplied CI success statuses were treated as supplemental evidence.

  • The standalone linked issue #30583 discussion was absent from the frozen evidence.

@mergify mergify Bot added the queued label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-25 00:50 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-25 04:45 UTC · at 6a9deea468f79612d8431e2bd3ff1bca021a55a2

This pull request spent 3 hours 54 minutes 58 seconds in the queue, with no time running CI.

Reason

Pull request #30864 has been dequeued

Pull request from fork cannot be queued. This pull request comes 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.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, 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

@XuPeng-SH
XuPeng-SH merged commit aeaa273 into matrixorigin:main Oct 25, 2026
25 of 29 checks passed
@mergify mergify Bot added dequeued and removed queued labels Oct 25, 2026

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants