Repository navigation
fix: refresh prepared DDL plans after schema changes - #26021
Conversation
# Conflicts: # pkg/sql/plan/utils.go
# Conflicts: # pkg/frontend/computation_wrapper.go
# Conflicts: # pkg/sql/plan/visit_plan_rule_test.go
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? |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
One blocking correctness regression found in prepared CLONE execution under database remapping.
P1 - Prepared CLONE loses database remapping (pkg/frontend/mysql_cmd_executor.go:1890)
GetDatabase() is the actual current database, while DefaultDatabase() applies the saved remap for unqualified names. remapDbInStmt has no CloneTable case, so CLONE relies on DefaultDatabase(). This new serialization then qualifies both source and destination with the actual database and marks them explicit, causing every refreshed EXECUTE to bypass remapping and clone from/create in the wrong database or fail. Preserve the effective remapped database semantics when creating the fresh CLONE AST.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Previous P1 on prepared CLONE remapping is fixed: cloneSQL now captures the remapped effective default database, with unit and BVT coverage. No other prior blockers exist; the follow-up merge had no conflict-resolution delta. Focused Go test could not run because go is unavailable in this environment.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking correctness issue remains on latest head 9b04ddccbbf6.
A prepared statement rebuilt against transaction-local DDL remains cached after that transaction rolls back:
create table t(a int);
prepare s from 'select * from t';
begin;
alter table t add column b int;
execute s;
rollback;
execute s;I reproduced this on the latest head with binary COM_STMT_PREPARE/EXECUTE. The final EXECUTE still reports columns [a b], while the rolled-back table has only [a].
recordSessionDDL advances ddlVersion after successful DDL, and EXECUTE stores the workspace-derived PreparePlan, ColDefData, cached compile, and matching generation. The full ROLLBACK path does not advance that generation, so the next transaction reuses state derived from a discarded workspace.
Please capture workspace.GetHaveDDL() before the transaction operator is cleared and, after a successful full rollback, advance the session DDL generation when that transaction contained DDL. This should cover explicit ROLLBACK, commit-failure/error rollback, and text/binary prepared statements retained across rollback. It should remain conditional on transaction-local DDL, rather than invalidating every rollback.
The prepared CLONE remap issue from the previous review is fixed by 6afe565744; this request is for the remaining rollback lifecycle gap.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes at d309dbb463 for the following production blockers:
-
Failed rollback can preserve a prepared plan built from discarded transaction-local DDL.
rollbackUnsafeadvancesddlVersiononly whenTxnOperator.Rollbacksucceeds. On error or panic it discards the frontend transaction without advancing the generation. DistTAE rollback can calltxn.delTransaction()and still returnloadCleanupErr, so the workspace may already be gone. Aborted DDL never reachesCatalogCache, leaving no other invalidation signal. Please advance the generation wheneverhaveDDLis true and this frontend transaction is discarded, regardless of rollback result. The current failed-rollback test incorrectly expects version 0; please also cover the subsequent prepared execution. -
DDL executed through
backSessiondoes not invalidate the upstream user session. BothrecordSessionDDLandadvanceDDLVersionAfterDiscardedTxnDDLonly handle a direct*Session. Stored-procedure SQL executes through*backSession, while the outerCALLis not catalog-changing. A procedure that drops and recreates a table can therefore leave the caller prepared plan and binary metadata reusable until asynchronous logtail delivery. Please centralize scoped generation propagation through the upstream session chain and add background or stored-procedure commit and rollback coverage. -
Stable prepared queries on subscription databases now execute synchronous catalog SQL on every
EXECUTE.preparedSubscriptionSchemaChangedcallsResolvebefore the cheap catalog-cache check. ProductionResolveperforms subscription account and publication catalog queries through a background executor. The benchmark uses an in-memory resolver and does not measure this cost. Please use a cheap subscription generation or high-watermark signal and resolve only when change is possible; also deduplicate collected dependencies. -
Historical snapshot subscription dependencies can rebuild forever. Collection drops the scan or view snapshot, while validation resolves the current subscription with a nil snapshot. If the historical object is v1 and the current publication is v2, every execution detects a change, rebuilds against historical v1 again, and repeats. Please preserve the dependency snapshot or identity, or define an immutable-snapshot strategy, with a test proving the second unchanged execution does not rebuild.
The overall dependency plus session-generation direction is valid and materially improves #25986, but these invalidation gaps and the subscription hot-path regression need to be closed before merge. CI status is intentionally not part of this review.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 08a674c22181576cd0457434a0444c81d2e6ef50. The previously reported rollback lifecycle, upstream background-session propagation, subscription hot-path, and historical-snapshot identity issues are addressed. Focused race tests, full affected-package tests, build/vet, and the issue #25986 embedded regression all pass.
Merge Queue Status
This pull request spent 1 hour 27 minutes 9 seconds in the queue, with no time running CI. ReasonPull request #26021 has been dequeued Queue conditions are not satisfied:
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. Requeued — the merge queue status continues in this comment ↓. |
# Conflicts: # pkg/pb/plan/plan.pb.go
Merge Queue Status
This pull request spent 1 hour 11 minutes 23 seconds in the queue, with no time running CI. ReasonPull request #26021 has been dequeued Queue conditions are not satisfied:
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. Requeued — the merge queue status continues in this comment ↓. |
# Conflicts: # pkg/sql/plan/query_builder.go
Merge Queue Status
This pull request spent 27 minutes 41 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Requeued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 2 hours 16 minutes 59 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
# Conflicts: # pkg/frontend/computation_wrapper.go # pkg/frontend/mysql_cmd_executor.go # pkg/frontend/types.go
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25986
What this PR does / why we need it:
Prepared schema-changing statements did not record their target tables as schema dependencies. As a result, repeated
EXECUTEcalls could reuse DDL plans built from stale table definitions and skip duplicate or missing object validation.This change collects the target table metadata for prepared
ALTER TABLE,CREATE INDEX, andDROP INDEXplans. Existing schema-version checks can then rebuild the prepared plan whenever the table definition changes, while preserving compile-cache reuse for unchanged prepared queries.The regression coverage verifies repeated add/drop column and create/drop index operations, including a drop-column case with a secondary index.
Validation:
go build -mod=readonly ./pkg/sql/plango vet -mod=readonly ./pkg/sql/plango test -count=1 -timeout=180s ./pkg/sql/plango test -count=1 -timeout=180s -run 'TestInitExecuteStmtParam' ./pkg/frontendmo-testerprepared DDL BVT: 29/29 passed