Repository navigation
fix: support cloning into temporary tables - #27070
Conversation
|
The attempt-2 Ubuntu UT job completed successfully on the same head, so #27073 no longer blocks this PR. The independently reproduced infrastructure issue remains open for triage. |
72d049f to
1b76b5b
Compare
|
@XuPeng-SH Regarding review Addressed in The rebuilt distributed regression covers both SQL forms. The normal form is rejected and the name is immediately reusable; the Please re-review the updated head. |
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed exact head afb9255ed8fe0aebc31bbd1812614eca74c843bb. The two prior blockers are closed at the semantic entry point: temporary clones now reject both TO ACCOUNT and COPY GRANTS before execution/state publication, including IF NOT EXISTS precedence. I also rechecked the temporary destination ownership path end to end: deterministic physical main/hidden-index names, restoration through the registered physical relation, late-error/commit-error alias rollback, preservation of pre-existing aliases, and disconnect cleanup via an independent executor scoped to the owning tenant. The distributed regression covers isolation, shadowing, late failure, allocator state, temporary sources, fulltext/IVF hidden tables, both rejected option families, and account-disconnect cleanup. Focused CGo-enabled frontend/compile regressions pass locally; exact-head coverage and BVT checks are green.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking: temporary-clone alias ownership is still not transaction-aware.
statementCanBeExecutedInUncommittedTransaction explicitly allows CloneTable, and getBackExecutor uses the shared user transaction when TxnOptions().ByBegin is true. On a successful CREATE TEMPORARY TABLE dst CLONE src, createTable registers the alias immediately and this new defer sees err == nil, so it intentionally keeps the alias. A later user ROLLBACK discards the engine workspace (including the physical temporary relation), but rollbackUnsafe only advances the DDL version and never restores/removes session temporary aliases. Therefore this deterministic public path recreates the original ghost:
BEGIN;
CREATE TEMPORARY TABLE temp_dst CLONE src;
ROLLBACK;
SELECT * FROM temp_dst; -- physical relation is gone
CREATE TEMPORARY TABLE temp_dst(id INT); -- alias still returns 1050The same ownership gap applies when the shared transaction ends in a known commit failure. Statement-error cleanup cannot close a transaction-terminal path. Please make temporary alias publication transaction-aware (preferably a shared temp-DDL journal/snapshot used by all temporary table creation/drop paths, not another CLONE-specific condition): commit preserves the committed mapping, while rollback/known failed commit restores the pre-transaction mapping. Add a public regression matrix for explicit BEGIN + commit, rollback, and pre-existing/IF NOT EXISTS controls; the current BVT only covers autocommit statement failure.
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head . The temporary-clone destination now consistently uses the session-owned physical relation, late failures remove only aliases introduced by the failed statement, and disconnect cleanup runs through an independent executor with the owning tenant identity and safely quoted names. The unsupported and combinations fail before execution or alias publication. Focused exact-head frontend and compile regressions pass locally; all required checks are green. No blocker found.
aunjgr
left a comment
There was a problem hiding this comment.
Corrected review summary for exact head afb9255ed8fe0aebc31bbd1812614eca74c843bb: the temporary-clone destination consistently uses the session-owned physical relation; late failures remove only aliases introduced by the failed statement; disconnect cleanup uses an independent executor with the owning tenant identity and safely quoted names; and TO ACCOUNT plus COPY GRANTS are rejected before execution or alias publication. Focused exact-head frontend and compile regressions pass locally, and all required checks are green. No blocker found.
|
@XuPeng-SH Regarding review Addressed in The public regression now covers explicit clone commit, clone rollback plus physical-row/alias reuse, pre-existing Verification on the rebuilt head: isolated BVT 163/163; focused tests |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head b32b55d. The shared temporary-table alias journal closes the prior transaction-ownership blocker across statement rollback, full rollback, normal commit, and known commit failure, including aliases mutated through shared/background sessions. I also rechecked clone cleanup ordering, pre-existing IF NOT EXISTS ownership, temporary DROP rollback/commit, reverse-map restoration, transaction-generation isolation, and the deliberately conservative unknown-commit path. Full pkg/frontend and pkg/sql/compile tests passed; focused lifecycle tests passed under race; an independent repeated-mutation regression passed 20/20 under race; git diff --check is clean. No remaining blocking issue found.
Merge Queue Status
This pull request spent 4 hours 1 minute 52 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27070 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.
Failing checks:
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27042
What this PR does / why we need it:
Root cause
CREATE TEMPORARY TABLE dst CLONE srccreated the destination under its generated session-local physical name, but the clone operator and indexed-table restore path still opened the user alias. The block clone therefore returnedno such tableafterCreateTablehad already published the alias. Transaction rollback removed the physical table, while the session alias remained and made every laterCREATE TEMPORARY TABLE dst ...report that the table already existed.Three adjacent ownership gaps could produce the same class of stale state:
RollbackLastStatement, fullROLLBACK, and known commit failure even though their physical relations were discarded.TO ACCOUNTandCOPY GRANTScombinations without a coherent temporary-table ownership model. The former separates the physical tenant from the owning session; the latter creates persistent privilege rows whose identity and cleanup do not match a session-owned physical relation.Changes
TO ACCOUNTorCOPY GRANTSbefore clone execution creates any state.bdbd613fde; resolve the overlap with fix: make IF NOT EXISTS table clone a no-op #27056 by retaining upstream's authoritativecreateTablecallback/no-op handling and removing this PR's duplicate mutable scope state and duplicate permanent-destination tests.Issue-to-test proof
TestConstructTableCloneUsesPhysicalTemporaryDestinationasserts the operator receives the generated physical name.TestScopeRestoreTemporaryCloneValidatesPhysicalDestinationcovers missing session/alias state and proves database and physical-relation lookup errors are preserved.TestScopeCreateTemporaryTableRollsBackAliasAfterLateFailureandTestRemoveFailedTemporaryCloneAliascover compile-side rollback, new-alias removal, pre-existing-alias preservation, and success. The BVT injects a late clone failure, asserts no physical catalog row, and immediately reuses the alias.TestSessionTempTableTransactionJournalproves statement-local inverse restoration, full transaction rollback, commit preservation, and generation isolation.TestTempTableAliasesFollowTransactionLifecycledrives the real transaction terminal paths for commit, rollback, statement rollback, known commit failure, and unknown commit result.temporary_table_clone.sqlproves a committed clone remains queryable, a rolled-back clone leaves no physical row or alias and permits immediate reuse,IF NOT EXISTSpreserves pre-existing mappings across commit/rollback, and transactional drop restores on rollback and releases on commit.TestSessionCloseDropsTemporaryTablesAsOwningTenantasserts account/user/role execution options and identifier quoting; the BVT closes a live account session and polls until the physical temporary relation is gone.TestHandleCloneTableRejectsUnsupportedTemporaryOptionsBeforeExecutionpasses nil execution dependencies and coversTO ACCOUNT,COPY GRANTS,IF NOT EXISTS ... COPY GRANTS, and combined-option precedence, proving rejection precedes all execution/state creation. The BVT exercises the sys-to-account snapshot form and bothCOPY GRANTSforms; it proves immediate name reuse, preservation of a pre-existing temporary table, session close, and absence of a target-account physical relation or alias.temporary_table_clone.sqladditionally covers exact schema/rows, same-session duplicate creates andIF NOT EXISTS, second-session isolation, drop/reuse, source shadowing, empty and auto-increment sources, temporary sources, unsupported FK/partition failure atomicity, FULLTEXT/IVFFLAT hidden tables, unsupported option atomicity, and disconnect cleanup.Tests run
GOWORK=off go list -mod=readonly ./pkg/sql/compile ./pkg/frontendgo build -mod=readonly ./pkg/sql/compile ./pkg/frontendgo vet -mod=readonly ./pkg/sql/compile ./pkg/frontend.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/sql/compile.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m ./pkg/frontend-race -count=100, including the new alias-journal and transaction-terminal tests..agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/sql/compile.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m ./pkg/frontendmake buildIF NOT EXISTS, and temporary drop commit/rollback all matched the intended mapping and physical-relation lifecycle.matrixorigin/mo-testermain: 163/163 statements passed. The generated output and checked-in result were manually checked against the intended SQL semantics.Residual risks
Session-close physical cleanup remains asynchronous by design, is bounded by a one-minute context, and logs per-table failures while continuing cleanup. The distributed regression waits for and observes successful cleanup. An unknown commit outcome deliberately retains the alias because the physical relation may have committed; this keeps it reachable for session use or disconnect cleanup rather than risking an untracked physical leak.
TO ACCOUNTandCOPY GRANTSremain explicit invalid-input boundaries for temporary clone destinations because their cross-tenant and persistent privilege state cannot be owned coherently by a session-local relation.