diff --git a/pkg/ccl/changefeedccl/changefeed_test.go b/pkg/ccl/changefeedccl/changefeed_test.go index 82140e09618d..38ab35952456 100644 --- a/pkg/ccl/changefeedccl/changefeed_test.go +++ b/pkg/ccl/changefeedccl/changefeed_test.go @@ -6311,14 +6311,25 @@ func TestChangefeedPredicateWithSchemaChange(t *testing.T) { } for _, tc := range []testCase{ + // The default policy is to skip schema changes which add new columns which { - name: "add column", + name: "add column no default", createFeedStmt: "CREATE CHANGEFEED AS SELECT * FROM foo", initialPayload: initialPayload, alterStmt: "ALTER TABLE foo ADD COLUMN new STRING", + afterAlterStmt: "INSERT INTO foo (a, b) VALUES (3, 'tres')", + payload: []string{ + `foo: [3, "tres"]->{"after": {"a": 3, "b": "tres", "c": null, "e": "inactive", "new": null}}`, + }, + }, + { + name: "add column", + createFeedStmt: "CREATE CHANGEFEED AS SELECT * FROM foo", + initialPayload: initialPayload, + alterStmt: "ALTER TABLE foo ADD COLUMN new STRING DEFAULT 'new'", payload: []string{ - `foo: [1, "one"]->{"after": {"a": 1, "b": "one", "c": null, "e": "inactive", "new": null}}`, - `foo: [2, "two"]->{"after": {"a": 2, "b": "two", "c": "c string", "e": "open", "new": null}}`, + `foo: [1, "one"]->{"after": {"a": 1, "b": "one", "c": null, "e": "inactive", "new": "new"}}`, + `foo: [2, "two"]->{"after": {"a": 2, "b": "two", "c": "c string", "e": "open", "new": "new"}}`, }, }, { @@ -6328,11 +6339,11 @@ func TestChangefeedPredicateWithSchemaChange(t *testing.T) { name: "add alt.status", createFeedStmt: "CREATE CHANGEFEED AS SELECT * FROM foo", initialPayload: initialPayload, - alterStmt: "ALTER TABLE foo ADD COLUMN alt alt.status", + alterStmt: "ALTER TABLE foo ADD COLUMN alt alt.status DEFAULT 'alt_closed'", afterAlterStmt: "INSERT INTO foo (a, b, alt) VALUES (3, 'tres', 'alt_open')", payload: []string{ - `foo: [1, "one"]->{"after": {"a": 1, "alt": null, "b": "one", "c": null, "e": "inactive"}}`, - `foo: [2, "two"]->{"after": {"a": 2, "alt": null, "b": "two", "c": "c string", "e": "open"}}`, + `foo: [1, "one"]->{"after": {"a": 1, "alt": "alt_closed", "b": "one", "c": null, "e": "inactive"}}`, + `foo: [2, "two"]->{"after": {"a": 2, "alt": "alt_closed", "b": "two", "c": "c string", "e": "open"}}`, `foo: [3, "tres"]->{"after": {"a": 3, "alt": "alt_open", "b": "tres", "c": null, "e": "inactive"}}`, }, }, @@ -6417,9 +6428,7 @@ func TestChangefeedPredicateWithSchemaChange(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - t.Run(tc.name, func(t *testing.T) { - cdcTest(t, testFn(tc), feedTestEnterpriseSinks) - }) + cdcTest(t, testFn(tc), feedTestEnterpriseSinks) }) } } diff --git a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row index 6a32e0ad55e8..8eacb82e694b 100644 --- a/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row +++ b/pkg/ccl/kvccl/kvfollowerreadsccl/testdata/boundedstaleness/single_row @@ -241,7 +241,7 @@ query idx=2 SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2 ---- pq: referenced descriptor ID 105: descriptor not found -events (15 found): +events (7 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 * event 3: colbatchscan trace on node_idx 2: local read @@ -249,20 +249,12 @@ events (15 found): * event 5: colbatchscan trace on node_idx 2: local read * event 6: transaction retry on node_idx: 2 * event 7: colbatchscan trace on node_idx 2: local read - * event 8: transaction retry on node_idx: 2 - * event 9: colbatchscan trace on node_idx 2: local read - * event 10: transaction retry on node_idx: 2 - * event 11: colbatchscan trace on node_idx 2: local read - * event 12: transaction retry on node_idx: 2 - * event 13: colbatchscan trace on node_idx 2: local read - * event 14: transaction retry on node_idx: 2 - * event 15: colbatchscan trace on node_idx 2: local read query idx=2 SELECT * FROM t2 AS OF SYSTEM TIME with_min_timestamp(now() - '10s', true) WHERE pk = 2 ---- pq: referenced descriptor ID 105: descriptor not found -events (15 found): +events (7 found): * event 1: colbatchscan trace on node_idx 2: local read * event 2: transaction retry on node_idx: 2 * event 3: colbatchscan trace on node_idx 2: local read @@ -270,11 +262,3 @@ events (15 found): * event 5: colbatchscan trace on node_idx 2: local read * event 6: transaction retry on node_idx: 2 * event 7: colbatchscan trace on node_idx 2: local read - * event 8: transaction retry on node_idx: 2 - * event 9: colbatchscan trace on node_idx 2: local read - * event 10: transaction retry on node_idx: 2 - * event 11: colbatchscan trace on node_idx 2: local read - * event 12: transaction retry on node_idx: 2 - * event 13: colbatchscan trace on node_idx 2: local read - * event 14: transaction retry on node_idx: 2 - * event 15: colbatchscan trace on node_idx 2: local read diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index e8c47ec5d3f7..87acf8a7be85 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -1421,7 +1421,7 @@ SELECT table_catalog, table_name, version WHERE table_catalog != 'system' AND version > 1 AND table_schema = 'public' ORDER BY 1,2 ---- table_catalog table_name version -other_db xyz 10 +other_db xyz 6 user testuser @@ -1431,7 +1431,7 @@ query TTTTTI colnames SELECT * FROM other_db.information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ---- table_catalog table_schema table_name table_type is_insertable_into version -other_db public xyz BASE TABLE YES 10 +other_db public xyz BASE TABLE YES 6 other_db public abc VIEW NO 1 @@ -1448,7 +1448,7 @@ SELECT * FROM other_db.information_schema.tables WHERE table_catalog = 'other_db ---- table_catalog table_schema table_name table_type is_insertable_into version other_db public abc VIEW NO 2 -other_db public xyz BASE TABLE YES 10 +other_db public xyz BASE TABLE YES 6 user root diff --git a/pkg/sql/logictest/testdata/logic_test/new_schema_changer b/pkg/sql/logictest/testdata/logic_test/new_schema_changer index c363b7f669ca..ee0e6a63d171 100644 --- a/pkg/sql/logictest/testdata/logic_test/new_schema_changer +++ b/pkg/sql/logictest/testdata/logic_test/new_schema_changer @@ -38,21 +38,19 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT │ │ │ └── • SameStagePrecedence dependency from PUBLIC ColumnName:{DescID: 106, Name: j, ColumnID: 2} │ │ │ rule: "column named right before column type becomes public" │ │ │ -│ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ ABSENT → BACKFILL_ONLY +│ │ └── • IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • Precedence dependency from DELETE_ONLY Column:{DescID: 106, ColumnID: 2} -│ │ rule: "column existence precedes index existence" -│ │ -│ ├── • 1 element transitioning toward TRANSIENT_ABSENT -│ │ │ -│ │ └── • TemporaryIndex:{DescID: 106, IndexID: 3} -│ │ │ ABSENT → DELETE_ONLY +│ │ ├── • Precedence dependency from DELETE_ONLY Column:{DescID: 106, ColumnID: 2} +│ │ │ rule: "column existence precedes column dependents" │ │ │ -│ │ └── • Precedence dependency from DELETE_ONLY Column:{DescID: 106, ColumnID: 2} -│ │ rule: "column existence precedes temporary index existence" +│ │ ├── • Precedence dependency from PUBLIC ColumnName:{DescID: 106, Name: j, ColumnID: 2} +│ │ │ rule: "column name and type to public after all index column to public" +│ │ │ +│ │ └── • Precedence dependency from PUBLIC ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 2} +│ │ rule: "column name and type to public after all index column to public" │ │ -│ └── • 6 Mutation operations +│ └── • 5 Mutation operations │ │ │ ├── • MakeAddedColumnDeleteOnly │ │ Column: @@ -92,34 +90,11 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT │ │ oid: 20 │ │ width: 64 │ │ -│ ├── • MakeAddedIndexBackfilling -│ │ Index: -│ │ ConstraintID: 1 -│ │ IndexID: 2 -│ │ IsUnique: true -│ │ KeyColumnDirections: -│ │ - 0 -│ │ KeyColumnIDs: -│ │ - 1 -│ │ SourceIndexID: 1 -│ │ StoringColumnIDs: -│ │ - 2 -│ │ TableID: 106 -│ │ TemporaryIndexID: 3 -│ │ -│ └── • MakeAddedTempIndexDeleteOnly -│ Index: -│ ConstraintID: 1 -│ IndexID: 3 -│ IsUnique: true -│ KeyColumnDirections: -│ - 0 -│ KeyColumnIDs: -│ - 1 -│ SourceIndexID: 1 -│ StoringColumnIDs: -│ - 2 -│ TableID: 106 +│ └── • scop.AddColumnToIndex +│ ColumnID: 2 +│ IndexID: 1 +│ Kind: 2 +│ TableID: 106 │ ├── • PreCommitPhase │ │ @@ -137,270 +112,45 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT │ DescriptorIDs: │ - 106 │ JobID: 1 -│ RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending +│ RunningStatus: PostCommitPhase stage 1 of 2 with 1 MutationType op pending │ Statements: │ - statement: ALTER TABLE foo ADD COLUMN j INT8 │ redactedstatement: ALTER TABLE ‹test›.public.‹foo› ADD COLUMN ‹j› INT8 │ statementtag: ALTER TABLE │ -├── • PostCommitPhase -│ │ -│ ├── • Stage 1 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • Column:{DescID: 106, ColumnID: 2} -│ │ │ DELETE_ONLY → WRITE_ONLY -│ │ │ -│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT -│ │ │ │ -│ │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 3} -│ │ │ DELETE_ONLY → WRITE_ONLY -│ │ │ -│ │ └── • 4 Mutation operations -│ │ │ -│ │ ├── • MakeAddedColumnDeleteAndWriteOnly -│ │ │ ColumnID: 2 -│ │ │ TableID: 106 -│ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly -│ │ │ IndexID: 3 -│ │ │ TableID: 106 -│ │ │ -│ │ ├── • SetJobStateOnDescriptor -│ │ │ DescriptorID: 106 -│ │ │ -│ │ └── • UpdateSchemaChangerJob -│ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 2 of 7 with 1 BackfillType op pending -│ │ -│ ├── • Stage 2 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ │ BACKFILL_ONLY → BACKFILLED -│ │ │ │ -│ │ │ └── • Precedence dependency from WRITE_ONLY TemporaryIndex:{DescID: 106, IndexID: 3} -│ │ │ rule: "temp index is WRITE_ONLY before backfill" -│ │ │ -│ │ └── • 1 Backfill operation -│ │ │ -│ │ └── • BackfillIndex -│ │ IndexID: 2 -│ │ SourceIndexID: 1 -│ │ TableID: 106 -│ │ -│ ├── • Stage 3 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ BACKFILLED → DELETE_ONLY -│ │ │ -│ │ └── • 3 Mutation operations -│ │ │ -│ │ ├── • MakeBackfillingIndexDeleteOnly -│ │ │ IndexID: 2 -│ │ │ TableID: 106 -│ │ │ -│ │ ├── • SetJobStateOnDescriptor -│ │ │ DescriptorID: 106 -│ │ │ -│ │ └── • UpdateSchemaChangerJob -│ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 4 of 7 with 1 MutationType op pending -│ │ -│ ├── • Stage 4 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ DELETE_ONLY → MERGE_ONLY -│ │ │ -│ │ └── • 3 Mutation operations -│ │ │ -│ │ ├── • MakeAddedIndexDeleteAndWriteOnly -│ │ │ IndexID: 2 -│ │ │ TableID: 106 -│ │ │ -│ │ ├── • SetJobStateOnDescriptor -│ │ │ DescriptorID: 106 -│ │ │ -│ │ └── • UpdateSchemaChangerJob -│ │ JobID: 1 -│ │ RunningStatus: PostCommitPhase stage 5 of 7 with 1 BackfillType op pending -│ │ -│ ├── • Stage 5 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ MERGE_ONLY → MERGED -│ │ │ -│ │ └── • 1 Backfill operation -│ │ │ -│ │ └── • MergeIndex -│ │ BackfilledIndexID: 2 -│ │ TableID: 106 -│ │ TemporaryIndexID: 3 -│ │ -│ ├── • Stage 6 of 7 in PostCommitPhase -│ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC -│ │ │ │ -│ │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ MERGED → VALIDATED -│ │ │ -│ │ └── • 1 Validation operation -│ │ │ -│ │ └── • ValidateUniqueIndex -│ │ IndexID: 2 -│ │ TableID: 106 -│ │ -│ └── • Stage 7 of 7 in PostCommitPhase -│ │ -│ ├── • 2 elements transitioning toward ABSENT -│ │ │ -│ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • SameStagePrecedence dependency from ABSENT IndexName:{DescID: 106, Name: foo_pkey, IndexID: 1} -│ │ │ rule: "dependents removed after index no longer public" -│ │ │ -│ │ └── • IndexName:{DescID: 106, Name: foo_pkey, IndexID: 1} -│ │ PUBLIC → ABSENT -│ │ -│ ├── • 3 elements transitioning toward PUBLIC -│ │ │ -│ │ ├── • Column:{DescID: 106, ColumnID: 2} -│ │ │ │ WRITE_ONLY → PUBLIC -│ │ │ │ -│ │ │ └── • Precedence dependency from PUBLIC PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ rule: "column depends on primary index" -│ │ │ -│ │ ├── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ │ │ VALIDATED → PUBLIC -│ │ │ │ -│ │ │ ├── • SameStagePrecedence dependency from VALIDATED PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} -│ │ │ │ rule: "primary index swap" -│ │ │ │ -│ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 106, Name: foo_pkey, IndexID: 2} -│ │ │ rule: "index named right before index becomes public" -│ │ │ -│ │ └── • IndexName:{DescID: 106, Name: foo_pkey, IndexID: 2} -│ │ │ ABSENT → PUBLIC -│ │ │ -│ │ └── • Precedence dependency from BACKFILL_ONLY PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3} -│ │ rule: "index existence precedes index dependents" -│ │ -│ └── • 8 Mutation operations -│ │ -│ ├── • SetIndexName -│ │ IndexID: 1 -│ │ Name: crdb_internal_index_1_name_placeholder -│ │ TableID: 106 -│ │ -│ ├── • SetIndexName -│ │ IndexID: 2 -│ │ Name: foo_pkey -│ │ TableID: 106 -│ │ -│ ├── • MakeDroppedPrimaryIndexDeleteAndWriteOnly -│ │ IndexID: 1 -│ │ TableID: 106 -│ │ -│ ├── • MakeAddedPrimaryIndexPublic -│ │ EventBase: -│ │ Authorization: -│ │ UserName: root -│ │ Statement: ALTER TABLE ‹test›.public.‹foo› ADD COLUMN ‹j› INT8 -│ │ StatementTag: ALTER TABLE -│ │ TargetMetadata: -│ │ SourceElementID: 1 -│ │ SubWorkID: 1 -│ │ IndexID: 2 -│ │ TableID: 106 -│ │ -│ ├── • MakeColumnPublic -│ │ ColumnID: 2 -│ │ EventBase: -│ │ Authorization: -│ │ UserName: root -│ │ Statement: ALTER TABLE ‹test›.public.‹foo› ADD COLUMN ‹j› INT8 -│ │ StatementTag: ALTER TABLE -│ │ TargetMetadata: -│ │ SourceElementID: 1 -│ │ SubWorkID: 1 -│ │ TableID: 106 -│ │ -│ ├── • RefreshStats -│ │ TableID: 106 -│ │ -│ ├── • SetJobStateOnDescriptor -│ │ DescriptorID: 106 -│ │ -│ └── • UpdateSchemaChangerJob -│ IsNonCancelable: true -│ JobID: 1 -│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 2 MutationType ops pending -│ -└── • PostCommitNonRevertiblePhase +└── • PostCommitPhase │ - ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase + ├── • Stage 1 of 2 in PostCommitPhase │ │ - │ ├── • 1 element transitioning toward ABSENT + │ ├── • 1 element transitioning toward PUBLIC │ │ │ - │ │ └── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} - │ │ VALIDATED → DELETE_ONLY + │ │ └── • Column:{DescID: 106, ColumnID: 2} + │ │ DELETE_ONLY → WRITE_ONLY │ │ - │ ├── • 1 element transitioning toward TRANSIENT_ABSENT - │ │ │ - │ │ └── • TemporaryIndex:{DescID: 106, IndexID: 3} - │ │ WRITE_ONLY → TRANSIENT_DELETE_ONLY - │ │ - │ └── • 4 Mutation operations + │ └── • 3 Mutation operations │ │ - │ ├── • MakeDroppedIndexDeleteOnly - │ │ IndexID: 3 - │ │ TableID: 106 - │ │ - │ ├── • MakeDroppedIndexDeleteOnly - │ │ IndexID: 1 + │ ├── • MakeAddedColumnDeleteAndWriteOnly + │ │ ColumnID: 2 │ │ TableID: 106 │ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 106 │ │ │ └── • UpdateSchemaChangerJob - │ IsNonCancelable: true │ JobID: 1 - │ RunningStatus: PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops pending + │ RunningStatus: PostCommitPhase stage 2 of 2 with 2 MutationType ops pending │ - └── • Stage 2 of 2 in PostCommitNonRevertiblePhase + └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 1 element transitioning toward PUBLIC │ │ - │ └── • PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} - │ │ DELETE_ONLY → ABSENT - │ │ - │ └── • Precedence dependency from ABSENT IndexName:{DescID: 106, Name: foo_pkey, IndexID: 1} - │ rule: "dependents removed before index" + │ └── • Column:{DescID: 106, ColumnID: 2} + │ WRITE_ONLY → PUBLIC │ - ├── • 1 element transitioning toward TRANSIENT_ABSENT - │ │ - │ └── • TemporaryIndex:{DescID: 106, IndexID: 3} - │ TRANSIENT_DELETE_ONLY → TRANSIENT_ABSENT - │ - └── • 6 Mutation operations + └── • 4 Mutation operations │ - ├── • CreateGcJobForIndex - │ IndexID: 1 - │ StatementForDropJob: - │ Statement: ALTER TABLE test.public.foo ADD COLUMN j INT8 - │ TableID: 106 - │ - ├── • MakeIndexAbsent + ├── • MakeColumnPublic + │ ColumnID: 2 │ EventBase: │ Authorization: │ UserName: root @@ -409,15 +159,9 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT │ TargetMetadata: │ SourceElementID: 1 │ SubWorkID: 1 - │ IndexID: 1 - │ TableID: 106 - │ - ├── • CreateGcJobForIndex - │ IndexID: 3 │ TableID: 106 │ - ├── • MakeIndexAbsent - │ IndexID: 3 + ├── • RefreshStats │ TableID: 106 │ ├── • RemoveJobStateFromDescriptor @@ -429,6 +173,7 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT JobID: 1 RunningStatus: all stages completed + statement ok ALTER TABLE foo ADD COLUMN j INT diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index 8680980bd52b..effa359e1604 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -7729,7 +7729,7 @@ func TestSchemaChangeWhileAddingOrDroppingTTL(t *testing.T) { CREATE DATABASE t; CREATE TABLE t.test (x INT);`, successfulChange: `ALTER TABLE t.test SET (ttl_expire_after = '10 minutes')`, - conflictingSchemaChange: `ALTER TABLE t.test ADD COLUMN y int`, + conflictingSchemaChange: `ALTER TABLE t.test ADD COLUMN y int DEFAULT 42`, expected: func(tableID uint32) string { return fmt.Sprintf(`pq: relation "test" \(%d\): cannot perform a schema change operation while a TTL change is in progress`, tableID) }, @@ -7740,7 +7740,7 @@ CREATE TABLE t.test (x INT);`, CREATE DATABASE t; CREATE TABLE t.test (x INT) WITH (ttl_expire_after = '10 minutes');`, successfulChange: `ALTER TABLE t.test RESET (ttl)`, - conflictingSchemaChange: `ALTER TABLE t.test ADD COLUMN y int`, + conflictingSchemaChange: `ALTER TABLE t.test ADD COLUMN y int DEFAULT 42`, expected: func(tableID uint32) string { return fmt.Sprintf(`pq: relation "test" \(%d\): cannot perform a schema change operation while a TTL change is in progress`, tableID) }, @@ -7751,7 +7751,7 @@ CREATE TABLE t.test (x INT) WITH (ttl_expire_after = '10 minutes');`, setup: ` CREATE DATABASE t; CREATE TABLE t.test (x INT);`, - successfulChange: `ALTER TABLE t.test ADD COLUMN y int`, + successfulChange: `ALTER TABLE t.test ADD COLUMN y int DEFAULT 42`, conflictingSchemaChange: `ALTER TABLE t.test SET (ttl_expire_after = '10 minutes')`, expected: func(tableID uint32) string { return `pq: cannot modify TTL settings while another schema change on the table is being processed` diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go index 77102061b901..2b76cbf1bb9e 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go @@ -350,6 +350,42 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { // TODO(postamar): can this even be possible? panic(pgerror.Newf(pgcode.NoPrimaryKey, "missing active primary key")) } + // As a special case, if we have a new column which has no computed + // expression and no default value, then we can just add it to the + // current primary index; there's no need to build a new index as + // it would have exactly the same data as the current index. + // + // Note that it's not totally obvious that this is safe. In particular, + // if we were to fail the schema change, we'd need to roll back. Rolling + // back the addition of this new column to the primary index is only safe + // if no value was ever written to the column. Fortunately, we know that + // the only case that this column ever gets data written to it is if it + // becomes public and the only way the column becomes public is if the + // schema change makes it to the non-revertible phase (this is true because + // making a new column public is not revertible). + // + // If ever we were to change how we encoded NULLs, perhaps so that we could + // intepret a missing value as an arbitrary default expression, we'd need + // to revisit this optimization. + // + // TODO(ajwerner): The above comment is incorrect in that we don't mark + // the marking of a column public as non-revertible. In cases with more + // than a single statement or more complex schema changes in a transaction + // this is buggy. We need to change that but it causes other tests, namely + // in cdc, to fail because it leads to the new primary index being published + // to public before the column is published as public. We'll need to figure + // out how to make sure that that happens atomically. Leaving that for a + // follow-up change in order to get this in. + if spec.def == nil && spec.colType.ComputeExpr == nil { + b.Add(&scpb.IndexColumn{ + TableID: spec.tbl.TableID, + IndexID: existing.IndexID, + ColumnID: spec.col.ColumnID, + OrdinalInKind: getNextStoredIndexColumnOrdinal(allTargets, existing), + Kind: scpb.IndexColumn_STORED, + }) + return existing + } // Drop all existing primary index elements. b.Drop(existing) var existingName *scpb.IndexName diff --git a/pkg/sql/schemachanger/scbuild/testdata/alter_table b/pkg/sql/schemachanger/scbuild/testdata/alter_table index 87e16a691690..0c99e43504c1 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/alter_table +++ b/pkg/sql/schemachanger/scbuild/testdata/alter_table @@ -25,67 +25,12 @@ ALTER TABLE defaultdb.foo ADD COLUMN j INT width: 64 isNullable: true tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] - details: - columnId: 1 - indexId: 1 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 2 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 3 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 2 - indexId: 2 - kind: STORED - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] details: columnId: 2 - indexId: 3 - kind: STORED - tableId: 104 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] - details: indexId: 1 - name: foo_pkey - tableId: 104 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] - details: - indexId: 2 - name: foo_pkey + kind: STORED tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] - details: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - sourceIndexId: 1 - tableId: 104 - temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - sourceIndexId: 1 - tableId: 104 build ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123 @@ -445,145 +390,16 @@ ALTER TABLE defaultdb.bar ADD COLUMN b INT; width: 64 isNullable: true tableId: 105 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] - details: - columnId: 1 - indexId: 1 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 2 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 3 - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 2 - indexId: 2 - kind: STORED - tableId: 104 -- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] details: columnId: 2 - indexId: 3 - kind: STORED - tableId: 104 -- [[IndexColumn:{DescID: 105, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] - details: - columnId: 1 indexId: 1 kind: STORED - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 2 - kind: STORED - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] - details: - columnId: 1 - indexId: 3 - kind: STORED - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] - details: - columnId: 2 - indexId: 1 - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 2 - indexId: 2 - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] - details: - columnId: 2 - indexId: 3 - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] - details: - columnId: 3 - indexId: 2 - kind: STORED - ordinalInKind: 1 - tableId: 105 -- [[IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + tableId: 104 +- [[IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 1}, PUBLIC], ABSENT] details: columnId: 3 - indexId: 3 + indexId: 1 kind: STORED ordinalInKind: 1 tableId: 105 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] - details: - indexId: 1 - name: foo_pkey - tableId: 104 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] - details: - indexId: 2 - name: foo_pkey - tableId: 104 -- [[IndexName:{DescID: 105, Name: bar_pkey, IndexID: 1}, ABSENT], PUBLIC] - details: - indexId: 1 - name: bar_pkey - tableId: 105 -- [[IndexName:{DescID: 105, Name: bar_pkey, IndexID: 2}, PUBLIC], ABSENT] - details: - indexId: 2 - name: bar_pkey - tableId: 105 -- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] - details: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - sourceIndexId: 1 - tableId: 104 - temporaryIndexId: 3 -- [[PrimaryIndex:{DescID: 105, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] - details: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - tableId: 105 -- [[PrimaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - sourceIndexId: 1 - tableId: 105 - temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - sourceIndexId: 1 - tableId: 104 -- [[TemporaryIndex:{DescID: 105, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - sourceIndexId: 1 - tableId: 105 diff --git a/pkg/sql/schemachanger/scdecomp/testdata/table b/pkg/sql/schemachanger/scdecomp/testdata/table index 4e8d7a968fe3..e2b92805ca77 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/table +++ b/pkg/sql/schemachanger/scdecomp/testdata/table @@ -647,10 +647,10 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - constraintId: 2 - indexId: 2 + constraintId: 1 + indexId: 1 isConcurrently: false - isCreatedExplicitly: true + isCreatedExplicitly: false isInverted: false isUnique: true sharding: null @@ -787,14 +787,14 @@ ElementState: tableId: 104 Status: PUBLIC - IndexName: - indexId: 2 + indexId: 1 name: parent_pkey tableId: 104 Status: PUBLIC - IndexColumn: columnId: 1 direction: ASC - indexId: 2 + indexId: 1 kind: KEY ordinalInKind: 0 tableId: 104 @@ -802,7 +802,7 @@ ElementState: - IndexColumn: columnId: 2 direction: ASC - indexId: 2 + indexId: 1 kind: STORED ordinalInKind: 0 tableId: 104 diff --git a/pkg/sql/schemachanger/scexec/executor_external_test.go b/pkg/sql/schemachanger/scexec/executor_external_test.go index 6fc50c3be0d3..68aa896bc220 100644 --- a/pkg/sql/schemachanger/scexec/executor_external_test.go +++ b/pkg/sql/schemachanger/scexec/executor_external_test.go @@ -280,50 +280,17 @@ func TestSchemaChanger(t *testing.T) { SourceElementID: 1, } targets := []scpb.Target{ - scpb.MakeTarget( - scpb.ToPublic, - &scpb.PrimaryIndex{ - Index: scpb.Index{ - TableID: fooTable.GetID(), - IndexID: 2, - IsUnique: true, - SourceIndexID: 1, - }, - }, - metadata, - ), scpb.MakeTarget( scpb.ToPublic, &scpb.IndexColumn{ TableID: fooTable.GetID(), - IndexID: 2, - ColumnID: 1, - OrdinalInKind: 0, - Direction: catpb.IndexColumn_ASC, - Kind: scpb.IndexColumn_KEY, - }, - metadata, - ), - scpb.MakeTarget( - scpb.ToPublic, - &scpb.IndexColumn{ - TableID: fooTable.GetID(), - IndexID: 2, + IndexID: 1, ColumnID: 2, OrdinalInKind: 0, Kind: scpb.IndexColumn_STORED, }, metadata, ), - scpb.MakeTarget( - scpb.ToPublic, - &scpb.IndexName{ - TableID: fooTable.GetID(), - IndexID: 2, - Name: "new_primary_key", - }, - metadata, - ), scpb.MakeTarget( scpb.ToPublic, &scpb.ColumnName{ @@ -352,47 +319,12 @@ func TestSchemaChanger(t *testing.T) { }, metadata, ), - scpb.MakeTarget( - scpb.ToAbsent, - &scpb.PrimaryIndex{ - Index: scpb.Index{ - TableID: fooTable.GetID(), - IndexID: 1, - IsUnique: true, - }, - }, - metadata, - ), - scpb.MakeTarget( - scpb.ToPublic, - &scpb.IndexColumn{ - TableID: fooTable.GetID(), - IndexID: 1, - ColumnID: 1, - OrdinalInKind: 0, - Direction: catpb.IndexColumn_ASC, - Kind: scpb.IndexColumn_KEY, - }, - metadata, - ), - scpb.MakeTarget( - scpb.ToAbsent, - &scpb.IndexName{ - TableID: fooTable.GetID(), - IndexID: 1, - Name: "primary", - }, - metadata, - ), } current := []scpb.Status{ scpb.Status_ABSENT, scpb.Status_ABSENT, scpb.Status_ABSENT, scpb.Status_ABSENT, - scpb.Status_ABSENT, - scpb.Status_PUBLIC, - scpb.Status_PUBLIC, } initial := scpb.CurrentState{ TargetState: scpb.TargetState{Statements: stmts, Targets: targets}, @@ -425,9 +357,6 @@ func TestSchemaChanger(t *testing.T) { scpb.Status_PUBLIC, scpb.Status_PUBLIC, scpb.Status_PUBLIC, - scpb.Status_PUBLIC, - scpb.Status_ABSENT, - scpb.Status_ABSENT, }, after.Current) ti.tsql.Exec(t, "INSERT INTO db.foo VALUES (1, 1)") }) diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table b/pkg/sql/schemachanger/scplan/testdata/alter_table index 97fe31ef1d42..3b5bf1c56346 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table @@ -6,17 +6,12 @@ CREATE TYPE defaultdb.footyp AS ENUM('a'); ops ALTER TABLE defaultdb.foo ADD COLUMN j defaultdb.footyp; ---- -StatementPhase stage 1 of 1 with 11 MutationType ops +StatementPhase stage 1 of 1 with 6 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], ABSENT] -> DELETE_ONLY [[ColumnName:{DescID: 104, Name: j, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -61,37 +56,9 @@ StatementPhase stage 1 of 1 with 11 MutationType ops TypeIDs: - 105 - 106 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - SourceIndexID: 1 - TableID: 104 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - SourceIndexID: 1 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 3 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 2 - IndexID: 3 - Kind: 2 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 2 - TableID: 104 scop.AddColumnToIndex ColumnID: 2 - IndexID: 2 + IndexID: 1 Kind: 2 TableID: 104 PreCommitPhase stage 1 of 1 with 4 MutationType ops @@ -114,45 +81,18 @@ PreCommitPhase stage 1 of 1 with 4 MutationType ops - 105 - 106 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 7 with 2 MutationType ops pending + RunningStatus: PostCommitPhase stage 1 of 2 with 1 MutationType op pending Statements: - statement: ALTER TABLE defaultdb.foo ADD COLUMN j defaultdb.footyp redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹j› defaultdb.footyp statementtag: ALTER TABLE -PostCommitPhase stage 1 of 7 with 6 MutationType ops +PostCommitPhase stage 1 of 2 with 5 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 2 TableID: 104 - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 3 - TableID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 105 - *scop.SetJobStateOnDescriptor - DescriptorID: 106 - *scop.UpdateSchemaChangerJob - JobID: 1 -PostCommitPhase stage 2 of 7 with 1 BackfillType op - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED - ops: - *scop.BackfillIndex - IndexID: 2 - SourceIndexID: 1 - TableID: 104 -PostCommitPhase stage 3 of 7 with 5 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY - ops: - *scop.MakeBackfillingIndexDeleteOnly - IndexID: 2 - TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.SetJobStateOnDescriptor @@ -161,66 +101,10 @@ PostCommitPhase stage 3 of 7 with 5 MutationType ops DescriptorID: 106 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 4 of 7 with 5 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY - ops: - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 2 - TableID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 105 - *scop.SetJobStateOnDescriptor - DescriptorID: 106 - *scop.UpdateSchemaChangerJob - JobID: 1 -PostCommitPhase stage 5 of 7 with 1 BackfillType op - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED - ops: - *scop.MergeIndex - BackfilledIndexID: 2 - TableID: 104 - TemporaryIndexID: 3 -PostCommitPhase stage 6 of 7 with 1 ValidationType op +PostCommitPhase stage 2 of 2 with 6 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED - ops: - *scop.ValidateUniqueIndex - IndexID: 2 - TableID: 104 -PostCommitPhase stage 7 of 7 with 10 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], WRITE_ONLY] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], VALIDATED] -> PUBLIC - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 - *scop.SetIndexName - IndexID: 1 - Name: crdb_internal_index_1_name_placeholder - TableID: 104 - *scop.SetIndexName - IndexID: 2 - Name: foo_pkey - TableID: 104 - *scop.MakeAddedPrimaryIndexPublic - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹j› defaultdb.footyp - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - SubWorkID: 1 - IndexID: 2 - TableID: 104 *scop.MakeColumnPublic ColumnID: 2 EventBase: @@ -234,67 +118,6 @@ PostCommitPhase stage 7 of 7 with 10 MutationType ops TableID: 104 *scop.RefreshStats TableID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 105 - *scop.SetJobStateOnDescriptor - DescriptorID: 106 - *scop.UpdateSchemaChangerJob - IsNonCancelable: true - JobID: 1 -PostCommitNonRevertiblePhase stage 1 of 2 with 7 MutationType ops - transitions: - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - ops: - scop.RemoveColumnFromIndex - ColumnID: 1 - IndexID: 1 - TableID: 104 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 3 - TableID: 104 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 1 - TableID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 105 - *scop.SetJobStateOnDescriptor - DescriptorID: 106 - *scop.UpdateSchemaChangerJob - IsNonCancelable: true - JobID: 1 -PostCommitNonRevertiblePhase stage 2 of 2 with 8 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT - ops: - *scop.CreateGcJobForIndex - IndexID: 1 - StatementForDropJob: - Statement: ALTER TABLE defaultdb.public.foo ADD COLUMN j defaultdb.footyp - TableID: 104 - *scop.MakeIndexAbsent - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹j› defaultdb.footyp - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - SubWorkID: 1 - IndexID: 1 - TableID: 104 - *scop.CreateGcJobForIndex - IndexID: 3 - TableID: 104 - *scop.MakeIndexAbsent - IndexID: 3 - TableID: 104 *scop.RemoveJobStateFromDescriptor DescriptorID: 104 JobID: 1 @@ -1209,28 +1032,16 @@ ops ALTER TABLE defaultdb.foo ADD COLUMN a INT; ALTER TABLE defaultdb.bar ADD COLUMN b INT; ---- -StatementPhase stage 1 of 1 with 22 MutationType ops +StatementPhase stage 1 of 1 with 10 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], ABSENT] -> DELETE_ONLY [[ColumnName:{DescID: 104, Name: a, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] -> PUBLIC [[Column:{DescID: 107, ColumnID: 3}, PUBLIC], ABSENT] -> DELETE_ONLY [[ColumnName:{DescID: 107, Name: b, ColumnID: 3}, PUBLIC], ABSENT] -> PUBLIC [[ColumnType:{DescID: 107, ColumnFamilyID: 0, ColumnID: 3}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 107, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY - [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC - [[IndexColumn:{DescID: 107, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 107, ColumnID: 3, IndexID: 1}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -1266,28 +1077,9 @@ StatementPhase stage 1 of 1 with 22 MutationType ops family: IntFamily oid: 20 width: 64 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - SourceIndexID: 1 - TableID: 104 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - SourceIndexID: 1 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 3 - TableID: 104 scop.AddColumnToIndex ColumnID: 2 - IndexID: 3 + IndexID: 1 Kind: 2 TableID: 104 *scop.MakeAddedColumnDeleteOnly @@ -1325,57 +1117,9 @@ StatementPhase stage 1 of 1 with 22 MutationType ops family: IntFamily oid: 20 width: 64 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - SourceIndexID: 1 - TableID: 107 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - SourceIndexID: 1 - TableID: 107 - scop.AddColumnToIndex - ColumnID: 2 - IndexID: 3 - TableID: 107 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 3 - Kind: 2 - TableID: 107 scop.AddColumnToIndex ColumnID: 3 - IndexID: 3 - Kind: 2 - Ordinal: 1 - TableID: 107 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 2 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 2 - IndexID: 2 - Kind: 2 - TableID: 104 - scop.AddColumnToIndex - ColumnID: 2 - IndexID: 2 - TableID: 107 - scop.AddColumnToIndex - ColumnID: 1 - IndexID: 2 - Kind: 2 - TableID: 107 - scop.AddColumnToIndex - ColumnID: 3 - IndexID: 2 + IndexID: 1 Kind: 2 Ordinal: 1 TableID: 107 @@ -1395,7 +1139,7 @@ PreCommitPhase stage 1 of 1 with 3 MutationType ops - 104 - 107 JobID: 1 - RunningStatus: PostCommitPhase stage 1 of 7 with 4 MutationType ops pending + RunningStatus: PostCommitPhase stage 1 of 2 with 2 MutationType ops pending Statements: - statement: ALTER TABLE defaultdb.foo ADD COLUMN a INT8 redactedstatement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹a› INT8 @@ -1403,160 +1147,28 @@ PreCommitPhase stage 1 of 1 with 3 MutationType ops - statement: ALTER TABLE defaultdb.bar ADD COLUMN b INT8 redactedstatement: ALTER TABLE ‹defaultdb›.public.‹bar› ADD COLUMN ‹b› INT8 statementtag: ALTER TABLE -PostCommitPhase stage 1 of 7 with 7 MutationType ops +PostCommitPhase stage 1 of 2 with 5 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY [[Column:{DescID: 107, ColumnID: 3}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 2 TableID: 104 - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 3 - TableID: 104 *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 3 TableID: 107 - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 3 - TableID: 107 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 107 - *scop.UpdateSchemaChangerJob - JobID: 1 -PostCommitPhase stage 2 of 7 with 2 BackfillType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED - ops: - *scop.BackfillIndex - IndexID: 2 - SourceIndexID: 1 - TableID: 104 - *scop.BackfillIndex - IndexID: 2 - SourceIndexID: 1 - TableID: 107 -PostCommitPhase stage 3 of 7 with 5 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY - ops: - *scop.MakeBackfillingIndexDeleteOnly - IndexID: 2 - TableID: 104 - *scop.MakeBackfillingIndexDeleteOnly - IndexID: 2 - TableID: 107 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 107 - *scop.UpdateSchemaChangerJob - JobID: 1 -PostCommitPhase stage 4 of 7 with 5 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY - ops: - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 2 - TableID: 104 - *scop.MakeAddedIndexDeleteAndWriteOnly - IndexID: 2 - TableID: 107 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 107 *scop.UpdateSchemaChangerJob JobID: 1 -PostCommitPhase stage 5 of 7 with 2 BackfillType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED - ops: - *scop.MergeIndex - BackfilledIndexID: 2 - TableID: 104 - TemporaryIndexID: 3 - *scop.MergeIndex - BackfilledIndexID: 2 - TableID: 107 - TemporaryIndexID: 3 -PostCommitPhase stage 6 of 7 with 2 ValidationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED - ops: - *scop.ValidateUniqueIndex - IndexID: 2 - TableID: 104 - *scop.ValidateUniqueIndex - IndexID: 2 - TableID: 107 -PostCommitPhase stage 7 of 7 with 15 MutationType ops +PostCommitPhase stage 2 of 2 with 7 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], WRITE_ONLY] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], VALIDATED] -> PUBLIC - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED - [[IndexName:{DescID: 107, Name: bar_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Column:{DescID: 107, ColumnID: 3}, PUBLIC], WRITE_ONLY] -> PUBLIC - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], VALIDATED] -> PUBLIC - [[IndexName:{DescID: 107, Name: bar_pkey, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 - *scop.SetIndexName - IndexID: 1 - Name: crdb_internal_index_1_name_placeholder - TableID: 104 - *scop.SetIndexName - IndexID: 2 - Name: foo_pkey - TableID: 104 - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 107 - *scop.SetIndexName - IndexID: 1 - Name: crdb_internal_index_1_name_placeholder - TableID: 107 - *scop.SetIndexName - IndexID: 2 - Name: bar_pkey - TableID: 107 - *scop.MakeAddedPrimaryIndexPublic - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹a› INT8 - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - SubWorkID: 1 - IndexID: 2 - TableID: 104 - *scop.MakeAddedPrimaryIndexPublic - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹bar› ADD COLUMN ‹b› INT8 - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - StatementID: 1 - SubWorkID: 1 - IndexID: 2 - TableID: 107 *scop.MakeColumnPublic ColumnID: 2 EventBase: @@ -1584,108 +1196,6 @@ PostCommitPhase stage 7 of 7 with 15 MutationType ops TableID: 107 *scop.RefreshStats TableID: 107 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 107 - *scop.UpdateSchemaChangerJob - IsNonCancelable: true - JobID: 1 -PostCommitNonRevertiblePhase stage 1 of 2 with 10 MutationType ops - transitions: - [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT - [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT - [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - ops: - scop.RemoveColumnFromIndex - ColumnID: 1 - IndexID: 1 - TableID: 104 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 3 - TableID: 104 - scop.RemoveColumnFromIndex - ColumnID: 2 - IndexID: 1 - TableID: 107 - scop.RemoveColumnFromIndex - ColumnID: 1 - IndexID: 1 - Kind: 2 - TableID: 107 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 3 - TableID: 107 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 1 - TableID: 104 - *scop.MakeDroppedIndexDeleteOnly - IndexID: 1 - TableID: 107 - *scop.SetJobStateOnDescriptor - DescriptorID: 104 - *scop.SetJobStateOnDescriptor - DescriptorID: 107 - *scop.UpdateSchemaChangerJob - IsNonCancelable: true - JobID: 1 -PostCommitNonRevertiblePhase stage 2 of 2 with 11 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT - [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 107, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT - ops: - *scop.CreateGcJobForIndex - IndexID: 1 - StatementForDropJob: - Statement: ALTER TABLE defaultdb.public.foo ADD COLUMN a INT8 - TableID: 104 - *scop.MakeIndexAbsent - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹foo› ADD COLUMN ‹a› INT8 - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - SubWorkID: 1 - IndexID: 1 - TableID: 104 - *scop.CreateGcJobForIndex - IndexID: 3 - TableID: 104 - *scop.MakeIndexAbsent - IndexID: 3 - TableID: 104 - *scop.CreateGcJobForIndex - IndexID: 1 - StatementForDropJob: - Statement: ALTER TABLE defaultdb.public.bar ADD COLUMN b INT8 - StatementID: 1 - TableID: 107 - *scop.MakeIndexAbsent - EventBase: - Authorization: - UserName: root - Statement: ALTER TABLE ‹defaultdb›.public.‹bar› ADD COLUMN ‹b› INT8 - StatementTag: ALTER TABLE - TargetMetadata: - SourceElementID: 1 - StatementID: 1 - SubWorkID: 1 - IndexID: 1 - TableID: 107 - *scop.CreateGcJobForIndex - IndexID: 3 - TableID: 107 - *scop.MakeIndexAbsent - IndexID: 3 - TableID: 107 *scop.RemoveJobStateFromDescriptor DescriptorID: 104 JobID: 1 diff --git a/pkg/sql/schemachanger/testdata/alter_table_add_column_no_default b/pkg/sql/schemachanger/testdata/alter_table_add_column_no_default new file mode 100644 index 000000000000..135aaf70f71a --- /dev/null +++ b/pkg/sql/schemachanger/testdata/alter_table_add_column_no_default @@ -0,0 +1,303 @@ +setup +CREATE DATABASE db; +CREATE TABLE db.public.tbl (i INT PRIMARY KEY); +---- +... ++database {0 0 db} -> 104 ++schema {104 0 public} -> 105 ++object {104 105 tbl} -> 106 + + +test +ALTER TABLE db.public.tbl ADD COLUMN j INT +---- +checking for feature: ALTER TABLE +increment telemetry for sql.schema.alter_table +increment telemetry for sql.schema.alter_table.add_column +increment telemetry for sql.schema.new_column_type.int8 +begin transaction #1 +# begin StatementPhase +## StatementPhase stage 1 of 1 with 5 MutationType ops +upsert descriptor #106 + ... + - columnIds: + - 1 + + - 2 + columnNames: + - i + + - j + + defaultColumnId: 2 + name: primary + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000000" + + modificationTime: {} + + mutations: + + - column: + + id: 2 + + name: j + + nullable: true + + pgAttributeNum: 2 + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + direction: ADD + + mutationId: 1 + + state: DELETE_ONLY + name: tbl + - nextColumnId: 2 + + nextColumnId: 3 + nextConstraintId: 2 + nextFamilyId: 1 + ... + partitioning: {} + sharded: {} + + storeColumnIds: + + - 2 + + storeColumnNames: + + - j + unique: true + version: 4 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "1" + + version: "2" +write *eventpb.AlterTable to event log for descriptor #106: ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN ‹j› INT8 +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 2 MutationType ops +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + - DELETE_ONLY + + - PUBLIC + + - PUBLIC + + - PUBLIC + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN ‹j› INT8 + + statement: ALTER TABLE db.public.tbl ADD COLUMN j INT8 + + statementTag: ALTER TABLE + + revertible: true + + targetRanks: + + - 0 + + - 1 + + - 2 + + - 3 + + targets: + + - elementProto: + + column: + + columnId: 2 + + pgAttributeNum: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + columnName: + + columnId: 2 + + name: j + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + columnType: + + columnId: 2 + + embeddedTypeT: + + type: + + family: IntFamily + + oid: 20 + + width: 64 + + isNullable: true + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + families: + - columnIds: + ... + formatVersion: 3 + id: 106 + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + mutations: + - column: + ... +create job #1 (non-cancelable: false): "ALTER TABLE db.public.tbl ADD COLUMN j INT8" + descriptor IDs: [106] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitPhase stage 1 of 2 with 3 MutationType ops +upsert descriptor #106 + ... + userName: root + currentStatuses: + - - DELETE_ONLY + + - WRITE_ONLY + - PUBLIC + - PUBLIC + ... + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000001" + + modificationTime: {} + mutations: + - column: + ... + direction: ADD + mutationId: 1 + - state: DELETE_ONLY + + state: DELETE_AND_WRITE_ONLY + name: tbl + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "2" + + version: "3" +update progress of schema change job #1: "PostCommitPhase stage 2 of 2 with 2 MutationType ops pending" +commit transaction #3 +begin transaction #4 +## PostCommitPhase stage 2 of 2 with 4 MutationType ops +upsert descriptor #106 + ... + oid: 20 + width: 64 + + - id: 2 + + name: j + + nullable: true + + pgAttributeNum: 2 + + type: + + family: IntFamily + + oid: 20 + + width: 64 + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - currentStatuses: + - - WRITE_ONLY + - - PUBLIC + - - PUBLIC + - - PUBLIC + - jobId: "1" + - relevantStatements: + - - statement: + - redactedStatement: ALTER TABLE ‹db›.‹public›.‹tbl› ADD COLUMN ‹j› INT8 + - statement: ALTER TABLE db.public.tbl ADD COLUMN j INT8 + - statementTag: ALTER TABLE + - revertible: true + - targetRanks: + - - 0 + - - 1 + - - 2 + - - 3 + - targets: + - - elementProto: + - column: + - columnId: 2 + - pgAttributeNum: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - columnName: + - columnId: 2 + - name: j + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - columnType: + - columnId: 2 + - embeddedTypeT: + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - isNullable: true + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + families: + - columnIds: + ... + formatVersion: 3 + id: 106 + - modificationTime: + - wallTime: "1640995200000000003" + - mutations: + - - column: + - id: 2 + - name: j + - nullable: true + - pgAttributeNum: 2 + - type: + - family: IntFamily + - oid: 20 + - width: 64 + - direction: ADD + - mutationId: 1 + - state: DELETE_AND_WRITE_ONLY + + modificationTime: {} + + mutations: [] + name: tbl + nextColumnId: 3 + ... + time: {} + unexposedParentSchemaId: 105 + - version: "3" + + version: "4" +write *eventpb.FinishSchemaChange to event log for descriptor 106 +adding table for stats refresh: 106 +update progress of schema change job #1: "all stages completed" +set schema change job #1 to non-cancellable +commit transaction #4 +# end PostCommitPhase