cockroachdb / cockroachdb/cockroach

schemachanger: ADD COLUMN, DROP COLUMN, ALTER PK in one transaction

Open
#110,995 0 comments 0 reactions 0 assignees View on GitHub
C-bug O-schema-testing T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Today, we have supported multiple ADD COLUMN, DROP COLUMN, and ALTER PK commands in *one* ALTER TABLE statement. The algorithm (explained [here](https://github.com/cockroachdb/cockroach/pull/99526)) does not extend well to multiple ALTER TABLE statements in one transaction. The main difficulty is due to the fact that the current algorithm is "online" in that it eagerly attempts to handle new primary index creation for each ALTER TABLE at StatementPhase. Maintaining this "online-ness" for multiple ALTER TABLE statements, while StatementPhase transitions relevant elements to various statuses, is very hard to think and reason about, and therefore prone to bugs.

One potential solution is to only do minimal bookkeeping in StatementPhase (i.e. what columns to add, to drop, etc.) and delay the creation of primary index chain to PreCommitPhase, effectively turning the algorithm into an "offline" one. This will be much easier to reason about and implement.

Jira issue: CRDB-31706

Epic CRDB-31472

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.