-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql/schemachanger: incorrect behavior for multi-add-column #83018
Copy link
Copy link
Open
Labels
A-schema-changer-implRelated to the implementation of the new schema changerRelated to the implementation of the new schema changerC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Description
Consider the following case:
CREATE TABLE t (i INT PRIMARY KEY);
SET use_declarative_schema_changer = unsafe_always;
BEGIN;
ALTER TABLE t ADD COLUMN j INT NOT NULL DEFAULT 30;
ALTER TABLE t ADD COLUMN k INT NOT NULL DEFAULT 40;
COMMIT;
The first ADD COLUMN stmt will build, plan, and execute the statement phase. (no problem!)
Then, the second ADD COLUMN will build, and plan from the state reached after the
statement phase from the first ADD COLUMN stmt.
That plan looks like this.
There are two issues spotted from that graph:
- Recall that the basic idea of
ADD COLUMNis to create and backfill a new primary index, and finally swap it with the old primary index. However, because we had twoADD COLUMNstmts, the graph shows three primary index element (the original oneidx1, the one created for the firstADD COLUMNstmtidx2, and another one created for the secondADD COLUMNstmtidx3). This is not expected though -- we'd like to modify and reuseidx2when building the secondADD COLUMNstmt. - In the stmt phase of the graph,
idx1-- the original primary index -- transitioned from PUBLIC to VALIDATED as a result of theMarkDroppedPrimaryIndexWriteAndDeleteOnly. This is incorrect as we should only turnidx1to non-public when we're ready to do the primary index swap, which happens after the new primary index (i.e.idx2, assuming issue 1 above is fixed) has been backfilled, merged, and validated.
Jira issue: CRDB-16799
Epic CRDB-31472
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-changer-implRelated to the implementation of the new schema changerRelated to the implementation of the new schema changerC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)