Repository navigation
fix: isolate session temporary physical tables - #31027
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
073a9a6 to
a32f745
Compare
4615f6c to
cc752bf
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 2849de2779e270b2187af25ff1741f540179b7e8
Assessment: request_changes
Reviewed the complete 25-file delta. Centralized resolution checks and an explicit maintenance capability are reasonable, but four base-confirmed regressions remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
-
P2
pkg/sql/plan/temporary_table_access.go:75: Create a temporary table with an inline unique index, insert a row, rename the table, then insert another row.
Impact: The rename changes the registered root name while retaining the index name. Ownership inferred from the old prefix rejects the owner's INSERT with error 1146. Preserve index ownership across root renames.
Evidence: TestReviewTemporaryIndexOwnershipAfterAlter/rename fails at HEAD and passes at the base; COPY ALTER and TRUNCATE controls pass. Reproducer: CREATE TEMPORARY TABLE t(id INT PRIMARY KEY,v VARCHAR(32),UNIQUE INDEX uk(v)); INSERT INTO t VALUES(1,'hello'); ALTER TABLE t RENAME TO renamed; INSERT INTO renamed VALUES(2,'world'). Logs: review-alter.log and base-alter.log. -
P2
pkg/sql/plan/query_builder.go:13778: Create a temporary table with inline FULLTEXT ft(body) ASYNC, or FULLTEXT2 ft(body) with its experimental flag enabled.
Impact: Nested ISCP registration carries a temporaryDDLSession without GetSessId. Its internal process uses the zero session UUID, so this filter hides the newly created root and CREATE fails with 'tableID is 0'. Propagate the staged owner's identity into catalog resolution.
Evidence: TestReviewTemporaryIndexBoundaries/inline_async_fulltext and /inline_fulltext2 fail at HEAD and pass at the base; inline synchronous FULLTEXT passes. Logs: review-boundaries.log and base-boundaries.log. sql_executor.go copies SessionId only from sessions implementing GetSessId. -
P2
pkg/sql/plan/temporary_table_access.go:61: ISCP initializes or reindexes a temporary index through ProcessInitSQL.
Impact: The background SqlContext has no frontend session or temporary-table capability, so the new gate rejects authorized maintenance SQL as 'no such table'. Foreground session lending does not cover this path. Give the existing background index owner narrowly authorized access.
Evidence: TestReviewTemporaryBackgroundIndexInitialization invokes the real ProcessInitSQL entry point with FULLTEXT2 FORCE_SYNC. The temporary case fails at HEAD; the permanent control and both base cases pass. Logs: background-head-v3.log and background-base-v4.log. -
P2
pkg/frontend/temporary_ddl.go:41: A session owns a temporary table and accesses an ordinary permanent table named __mo_tmp.
Impact: Every generated temporary name matches this prefix, so OwnsTemporaryTable incorrectly claims the permanent table. Resolve marks it temporary and CREATE VIEW over it fails with error 1352. Keep exact ownership separate from derived-index authorization.
Evidence: TestReviewTemporaryIndexOwnershipAfterAlter/permanent_prefix_view fails at HEAD and passes at the base. Reproducer: CREATE TABLE __mo_tmp(id INT); CREATE TEMPORARY TABLE t(id INT); CREATE VIEW permanent_view AS SELECT * FROM __mo_tmp. Logs: review-alter.log and base-alter.log.
Validation:
-
Preflight passed. Rebuilt native prerequisites through repository make cgo and verified 200 exported inputs against HEAD. Source remained unchanged; git diff --check passed.
-
The PR's two-session integration test and focused tests across plan, util, sqlexec, frontend, and compile passed.
-
Additional probes reproduced all four findings at HEAD and passed with verified base production overlays.
-
Ownership microbenchmark with a long ordinary table name and 1,024 temporary mappings: HEAD 26,766 ns/op, 65,536 B/op, 1,024 allocations; base 9.023 ns/op, zero allocations. This measures the shared lookup, not SQL latency.
-
All 21 receipts, commands, source fingerprints, logs, overlay hashes, and superseded diagnostics are reconciled in /home/xupeng/.local/state/mo-bot/jobs/14cee487af45b431890702b8/attempt-1/validation-audit.json.
Limitations:
-
Ran focused normal-mode tests, not the full repository or race suite. Background validation invoked ProcessInitSQL directly rather than the scheduled worker loop.
-
No retained author validation artifacts were supplied. CI status summaries were available, but execution logs and the linked issue's full text were absent.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
I re-inspected the full diff at HEAD 2849de2 (25 files), the linked issue #30584, and the PR's discussion, then validated the isolation design end to end: the shared gate in pkg/sql/plan/temporary_table_access.go classifies by durable relkind with rename metadata checked before the legacy CREATE SQL parse, so permanent objects with generated-looking names stay visible; ownership is enforced per session in both the frontend and internal-executor Resolve paths; the explicit TemporaryTableAccessKey capability is correctly scoped to session reset/disconnect, orphan GC, and disttae engine catalog reads; and the mo_tables planner filter keeps the owner's own rows via the session-ID prefix (safe with the per-session plan cache) while hiding foreign temporary objects. After my initial pass, a mo-bot review (request_changes) posted four evidence-backed findings at this same head: (1) renaming a temporary root breaks ownership of its retained index names (temporary_table_access.go:75); (2) staged temporaryDDLSession values do not satisfy the GetSessId assertion in sql_executor.go because process.Session lacks that method, so nested ISCP registration compiles with the zero session UUID and the new mo_tables filter breaks inline async FULLTEXT/FULLTEXT2 creation (query_builder.go:13778) — I independently confirmed the missing GetSessId promotion in code; (3) background ISCP ProcessInitSQL on temporary indexes has no session or capability and now fails as 'no such table' (temporary_table_access.go:61); (4) the new prefix fallback in Session.OwnsTemporaryTable incorrectly claims permanent tables named like __mo_tmp, breaking e.g. CREATE VIEW over them (temporary_ddl.go:41). My own independent analysis had converged on finding (4)'s exact root cause, so per review rules I am not re-emitting any of these unaddressed findings; they remain the blocking concerns the author needs to resolve. My review found no additional defects beyond one minor documentation nit recorded below. Limitation: this environment lacks the repository's CGO headers (xxhash, roaring, usearch, jemalloc), so build and test suites could not be executed here; per policy I did not install dependencies, and verification was static review plus gofmt/vet on compilable packages.
P2 - BuildTableScanTemporaryFilter doc overstates the nil-session escape: zero-UUID internal procs filter out all temporary rows (pkg/sql/util/util.go:185)
The comment says a nil session ID deliberately leaves the scan unchanged for context-free catalog tooling and internal maintenance, but the only call site (query_builder.go) passes proc.GetSessionInfo().SessionId.String(), which is never the empty string: internal executor processes without a lent session carry the zero UUID, so they get prefix _mo_tmp_00000000000000000000000000000000 and hide every temporary row instead. That zero-UUID behavior is exactly what the mo-bot's FULLTEXT finding (query_builder.go:13778) turns into a user-facing failure, since sql_executor.go only copies SessionId from sessions implementing GetSessId and temporaryDDLSession does not expose it. The empty-string branch is effectively dead defensive code and the comment mischaracterizes which scans stay unchanged. Please update the comment to state that zero-UUID internal procs filter out all temporary objects unless they attach the TemporaryTableAccessKey capability, or make the intended context-free behavior real (for example by treating uuid.Nil as no filter) if that is the design.
|
Implemented the four regressions from review 5639822982 in local commit
The zero-UUID filtering comment from review 5639892812 was corrected as well. Validation on Darwin/arm64, Go 1.27.1, using the repository CGo wrapper:
|
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: d96e2290cd86c6d3845ceec24db0a2541a9386f0
Assessment: request_changes
Reviewed all 30 changed files, linked issues and prior concerns. The shared access gate and exact ownership design are reasonable, and the earlier concerns are addressed. One reproduced compatibility regression remains: owners cannot clone temporary AUTO_INCREMENT tables.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
- P2
pkg/sql/compile/sql_executor_context.go:690: On one connection, run CREATE TEMPORARY TABLE src(id BIGINT AUTO_INCREMENT PRIMARY KEY, v INT); INSERT INTO src VALUES(7,11); CREATE TEMPORARY TABLE dst CLONE src.
Impact: The legitimate owner receives error 1146 for src's physical name. Propagate the authenticated session into clone compilation's internal SQL before allocator queries execute, and add a temporary-source clone regression test.
Evidence: constructTableClone calls runSqlWithResultAndOptions for MAX(id) before RestoreTable attaches the session. The internal executor therefore has no owner, and this new gate rejects the source. TestReviewCloneOwnedTemporaryAutoIncrement reproduced the failure while its permanent-source control passed. Disabling only this gate in a diagnostic overlay made both cases pass. The PR's allocator test uses a permanent source and misses this boundary. Retained evidence: clone-owner.log, clone-owner-control.log and validation-audit.json.
Validation:
-
Verified exact-head CI run 40132172281: Ubuntu UT, coverage UT and proxy BVT succeeded. Reconciled checkout identity, commands, retained logs, artifacts and retrieval receipts.
-
Isolation preflight passed. Built native prerequisites through make cgo and verified 200 frozen native inputs and 46 retained artifacts.
-
Eight focused top-level tests across six packages passed, including the real two-session integration test, ownership lifecycle, reset retry, staging, ISCP access and FULLTEXT2 identity.
-
Regression receipt 1792880987453031876-3.json records exit 1 and temporary-source error 1146; diagnostic control receipt 1792881033665928900-3.json records exit 0.
-
Ordinary ownership lookup with 1,024 registered tables measured 9.169 ns/op, 0 B/op and 0 allocations/op.
-
Source remained unchanged. Evidence audit: /home/xupeng/.local/state/mo-bot/jobs/9514f15ca91dba25d9181590/attempt-1/validation-audit.json.
Limitations:
-
The gate-disabled control isolates causality; it is not a complete merge-base build or a proposed fix.
-
Broad race coverage was reused from CI. Additional mo_tables filtering costs were assessed statically, without a metadata-scan benchmark.
|
Prepared the fix for review 5640327814 in commit Clone compilation now lends the authenticated caller's session before allocator and MAX queries execute, and restores the original process context on every exit. Temporary sources work with temporary and permanent destinations, while ordinary ownership checks remain in force; no maintenance bypass is attached. The rebase also preserves main's canonical alias keys, authoritative missing-table cleanup and root-generation index naming. Staged aliases retain structured database/alias identities so collecting and publishing hidden indexes cannot mix dotted names. The existing capacity test still proves admission rejection, exact missing-family cleanup and capacity recovery using the PR's root-generation budget. Validation on Darwin/arm64, Go 1.27.1, through the repository CGo wrapper:
|
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 31e5e3c8dbc0cbbc785907169d87f935716c2eea
Assessment: request_changes
Reviewed the complete 32-file delta and supplied discussion. Shared authorization and exact session ownership are appropriate, and the earlier isolation concerns are addressed. However, the new clone-compilation session lending introduces a reproduced cross-account alias regression.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
- P2
pkg/sql/compile/operator.go:3021: A subscriber clones an AUTO_INCREMENT table through a subscription while its session owns a temporary table with the publisher's original database/table name. For example, the publisher exposes review_clone_db.src as subscribed.src, and the subscriber creates its own temporary review_clone_db.src.
Impact: CREATE TABLE review_clone_db.target CLONE subscribed.src fails with error 1146 despite SELECT from subscribed.src succeeding. The internal MAX query executes under the publisher account but retains the subscriber session's temporary aliases, rewriting the source to a physical temporary name absent from that account. Determine the effective source account before lending the session; mask inherited session identity when crossing accounts while preserving same-account temporary access.
Evidence: The added diagnostic SQL integration test first successfully clones the published table, creates the colliding subscriber temporary alias, verifies the published row remains readable, then reproduces the clone failure. boundary-probe-v2.log and receipt 1792914667608339192-3.json record the failure against unchanged candidate production code. Removing only the newly added session-lending block makes the identical scenario pass, including copied data and next AUTO_INCREMENT ID 8: clone-control-v2.log, receipt 1792914503819678293-3.json. Add this account-boundary regression to the existing clone tests.
Validation:
-
Artifacts are retained under /home/xupeng/.local/state/mo-bot/jobs/9e54bb4baf76349b427164fa/attempt-1. validation-audit.json reconciles commands, source fingerprints, exit receipts and log hashes; final audit receipt 1792914812691382576-4.json exited 0.
-
Isolation preflight passed. Native compatibility was verified through the repository provenance owner after comparing 192 tracked build-input paths and contents; receipts 1792913945646106598-4.json and 1792913945887996273-33.json.
-
Focused race validation passed 24 test roots twice across nine packages, including the public two-session SQL integration regression, clone combinations and real ProcessInitSQL execution. Receipt 1792914325929482944-4.json matches focused-race.log.
-
A correctly quoted DATA BRANCH probe rejected a foreign temporary physical table with error 1146. Receipt 1792914577474240003-3.json matches branch-probe-v2.log. Earlier diagnostic quoting failures were retained and excluded from successful validation claims.
-
Source audit confirmed the assigned head, merge-base and unchanged checkout; changed Go files passed formatting checks and git diff --check. Receipt 1792914690673092247-4.json matches source-audit.log.
-
Reviewed frozen exact-head CI success records for build, unit tests, static analysis, coverage and BVT. evidence.json.local_validation contained no retained worker gates.
Limitations:
-
Local execution used focused race tests rather than full package/repository suites. Raw CI and author logs were not supplied. The causality control is not a complete base build or a proposed final fix.
-
Performance was assessed statically: ownership lookup remains O(1), while catalog filtering adds classification work. No SQL latency or metadata-scan benchmarks were measured.
-
No multi-CN, mixed-version, scheduled maintenance-loop or GPU execution was performed. The standalone linked issue body was unavailable; its contract was assessed from the frozen PR and discussion.
|
Prepared the fix for review 5642151832 in commit Clone compilation now resolves the effective source account first, preserving publication/snapshot/caller precedence. It lends the authenticated session only when caller and source accounts match. On an account switch, or an unknown caller account, it explicitly masks any inherited internal-executor session, including when the process has no local session. The original context is restored on every exit; ordinary temporary-table authorization remains enabled. Validation on Darwin/arm64, Go 1.27.1, using the repository CGo wrapper:
No protocol, catalog-format or native-artifact changes were needed. Local public validation used the existing single-CN MySQL-protocol fixture. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: f8a2a0c8b0a93718ad5faf427e08385911820bef
Assessment: approve
Reviewed the complete 32-file delta and affected callers. The design keeps session ownership authoritative, shares resolution checks, and scopes maintenance access explicitly. Cross-account clone queries correctly mask inherited aliases. Prior review concerns are resolved; no actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Verified the frozen head, clean source, native-build provenance, and retained command/source/exit receipts against logs. Audit: /home/xupeng/.local/state/mo-bot/jobs/fc70dbd86d37cce3f9176224/attempt-1/validation-audit.json.
-
All 24 focused test roots passed twice under race detection across nine packages, including public SQL isolation, indexes, clone allocators, and subscription alias collisions.
-
The complete compile package passed normally and under race detection. Frontend race testing had one unchanged test fail because it writes into the read-only checkout; all other tests passed. That test passed with only its output paths redirected through a diagnostic overlay.
-
Four exact lifecycle/staging tests each passed 100 race iterations. An additive integration probe exercised frontend.Migrate for plain, unique-indexed, AUTO_INCREMENT, fulltext, and fulltext2 temporary tables, verifying preserved rows and subsequent writes.
-
Formatting and diff checks passed. Performance review found additional catalog-filter work and ownership checks, but no additional metadata query on ordinary relation resolution. No throughput improvement is claimed.
Limitations:
-
No dedicated throughput benchmark or local two-CN Proxy handoff was run; the migration probe used the production migration entry point in a one-CN fixture.
-
Frozen CI statuses and author reports were corroborating evidence, not independently retrieved raw CI logs. The standalone linked issue body was absent; its behavioral contract was assessed from supplied PR material and frozen sources.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
What type of PR is this?
Which issue(s) this PR fixes:
#30584
What this PR does / why we need it:
A session temporary table's generated physical relation name could be used by another session to read, modify, or drop the table. The owner then lost its data and could not reliably reuse the logical alias.
This change enforces exact session ownership when resolving temporary roots and generated index relations, hides new and legacy temporary objects from foreign mo_catalog.mo_tables scans, and preserves reset/disconnect/orphan-GC cleanup through an explicit internal capability. Ordinary permanent objects with generated-looking names remain visible.
Validation
The issue should be validated by the reporter after the PR is merged.