cockroachdb / cockroachdb/cockroach
schemachanger: `Replace` discards element initial state, breaking rollback
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
`builderState.replaceElement`, overrides an existing element state with `initial=ABSENT` and discards the element's true prior state. This is a problem for rollback because it relies on the elements initial status to revert the mutations (`scpb.CurrentState.Rollback`). Therefore, a Replace'd element is driven to `ABSENT` rather than restored to its pre-change value.
This is currently masked: every Replace caller (`CREATE OR REPLACE FUNCTION`, `TRUNCATE` function/trigger reference rewrites, owner changes) lands only in non-revertible phases, so the wrong rollback path is never taken. It becomes a live correctness bug once transactional DDL lets a Replace share a job with a revertible post-commit phase (e.g. a backfill): a failed job "reverts" but leaves the Replace'd payload in its mid-transaction state.
We should fix this in the element/rollback model.
Jira issue: CRDB-67833
Epic CRDB-65516
Contributor guide
Assessment
This issue has not been assessed yet.