Skip to content

adapter: track ALTER SOURCE's source in the purified statement's dependencies - #38638

Open
tonydu-mz wants to merge 1 commit into
tonydu/sql-660-create-table-from-source-and-alter-source-drive-the-sourcesfrom
tonydu/alter-source-plan-validity
Open

adapter: track ALTER SOURCE's source in the purified statement's dependencies#38638
tonydu-mz wants to merge 1 commit into
tonydu/sql-660-create-table-from-source-and-alter-source-drive-the-sourcesfrom
tonydu/alter-source-plan-validity

Conversation

@tonydu-mz

Copy link
Copy Markdown
Contributor

Motivation

ALTER SOURCE is purified off the coordinator thread. Its target source is
carried in the AST as an UnresolvedItemName, so name resolution never records
it and the statement's resolved_ids, from which PlanValidity's dependency
set is built, does not contain it.

A source dropped concurrently with that off-thread purification therefore
passed the validity check when the purified statement came back, and planning
then called get_entry on the missing id, panicking the coordinator with
"catalog out of sync" (plan_purified_alter_source_add_subsource,
plan_purified_alter_source_refresh_references).

Description

Extend the purified statement's dependency ids with the source that
mz_sql::pure::statement_source resolves (introduced in #38564, where the same
resolution feeds the pre-purification authorization check). With the id
tracked, PlanValidity::check detects the drop and the coordinator repurifies
the original statement, ending in a clean unknown-item error instead of a
panic. For CREATE TABLE ... FROM SOURCE the source is already in
resolved_ids, so the extension is a no-op there.

Verification

The race needs a drop landing between purification spawn and completion; there
is no deterministic hook for that in sqllogictest. Verified by code trace:
PlanValidity::check uses try_get_entry and returns
ConcurrentDependencyDrop for a missing id, and the PurifiedStatementReady
handler repurifies on validity failure. ALTER SOURCE IF EXISTS on a
never-resolving name contributes no phantom dependency (statement_source
returns None).

Stacked on #38564.

### Motivation

`ALTER SOURCE` is purified off the coordinator thread. Its target source is
carried in the AST as an `UnresolvedItemName`, so name resolution never records
it and the statement's `resolved_ids`, from which `PlanValidity`'s dependency
set is built, does not contain it.

A source dropped concurrently with that off-thread purification therefore
passed the validity check when the purified statement came back, and planning
then called `get_entry` on the missing id, panicking the coordinator with
"catalog out of sync" (`plan_purified_alter_source_add_subsource`,
`plan_purified_alter_source_refresh_references`).

### Description

Extend the purified statement's dependency ids with the source that
`mz_sql::pure::statement_source` resolves (introduced in #38564, where the same
resolution feeds the pre-purification authorization check). With the id
tracked, `PlanValidity::check` detects the drop and the coordinator repurifies
the original statement, ending in a clean unknown-item error instead of a
panic. For `CREATE TABLE ... FROM SOURCE` the source is already in
`resolved_ids`, so the extension is a no-op there.

### Verification

The race needs a drop landing between purification spawn and completion; there
is no deterministic hook for that in sqllogictest. Verified by code trace:
`PlanValidity::check` uses `try_get_entry` and returns
`ConcurrentDependencyDrop` for a missing id, and the `PurifiedStatementReady`
handler repurifies on validity failure. `ALTER SOURCE IF EXISTS` on a
never-resolving name contributes no phantom dependency (`statement_source`
returns `None`).

Stacked on #38564.
@tonydu-mz
tonydu-mz marked this pull request as ready for review September 3, 2026 15:33
@tonydu-mz
tonydu-mz requested a review from a team as a code owner September 3, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant