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/ccl/partitionccl/BUILD.bazel b/pkg/ccl/partitionccl/BUILD.bazel index 8ad5f57dafdd..b8ac8aca6eab 100644 --- a/pkg/ccl/partitionccl/BUILD.bazel +++ b/pkg/ccl/partitionccl/BUILD.bazel @@ -65,6 +65,7 @@ go_test( "//pkg/sql", "//pkg/sql/catalog", "//pkg/sql/catalog/bootstrap", + "//pkg/sql/catalog/catalogkeys", "//pkg/sql/catalog/descbuilder", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/desctestutils", diff --git a/pkg/ccl/partitionccl/zone_test.go b/pkg/ccl/partitionccl/zone_test.go index 8b492da54f27..52270cb4d146 100644 --- a/pkg/ccl/partitionccl/zone_test.go +++ b/pkg/ccl/partitionccl/zone_test.go @@ -21,6 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils" "github.com/cockroachdb/cockroach/pkg/sql/lexbase" @@ -314,7 +315,7 @@ func TestGenerateSubzoneSpans(t *testing.T) { directions := []encoding.Direction{encoding.Ascending /* index ID */} for i := 0; i < idx.NumKeyColumns(); i++ { cd := idx.GetKeyColumnDirection(i) - ed, err := cd.ToEncodingDirection() + ed, err := catalogkeys.IndexColumnEncodingDirection(cd) if err != nil { t.Fatal(err) } diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion index 1a083cbee038..e84db0283542 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion +++ b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion @@ -117,22 +117,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 1 tableId: 110 temporaryIndexId: 0 Status: PUBLIC @@ -280,6 +272,22 @@ ElementState: name: table_global_pkey tableId: 110 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 110 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 110 + Status: PUBLIC - Namespace: databaseId: 104 descriptorId: 110 @@ -361,22 +369,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 1 tableId: 109 temporaryIndexId: 0 Status: PUBLIC @@ -526,6 +526,22 @@ ElementState: name: table_regional_by_table_pkey tableId: 109 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 109 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 109 + Status: PUBLIC - Namespace: databaseId: 104 descriptorId: 109 @@ -617,24 +633,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 3 - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 tableId: 108 temporaryIndexId: 0 Status: PUBLIC @@ -868,6 +874,30 @@ ElementState: indexId: 1 tableId: 108 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 1 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 3 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC - Namespace: databaseId: 104 descriptorId: 108 diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning index 048072600418..1a01255106a8 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning +++ b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning @@ -90,47 +90,27 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 2 - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 3 tableId: 104 temporaryIndexId: 0 Status: PUBLIC - SecondaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 0 indexId: 2 isConcurrently: false isCreatedExplicitly: false isInverted: true isUnique: false - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 2 - - 3 - keySuffixColumnIds: - - 1 sharding: null sourceIndexId: 0 - storingColumnIds: [] tableId: 104 temporaryIndexId: 0 Status: PUBLIC @@ -353,6 +333,54 @@ ElementState: indexId: 1 tableId: 104 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 1 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 2 + kind: KEY_SUFFIX + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 2 + kind: KEY + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 3 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 3 + direction: ASC + indexId: 2 + kind: KEY + ordinalInKind: 1 + tableId: 104 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 104 @@ -434,43 +462,27 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 2 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 tableId: 105 temporaryIndexId: 0 Status: PUBLIC - SecondaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 2 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: - - 1 sharding: null sourceIndexId: 0 - storingColumnIds: [] tableId: 105 temporaryIndexId: 0 Status: PUBLIC @@ -629,6 +641,38 @@ ElementState: range: [] tableId: 105 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 2 + kind: KEY_SUFFIX + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 2 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 105 diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index b/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index index 1dfc63990974..586f0d002981 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/create_index @@ -13,7 +13,7 @@ CREATE INDEX id1 checking for feature: CREATE INDEX begin transaction #1 # begin StatementPhase -## StatementPhase stage 1 of 1 with 4 MutationType ops +## StatementPhase stage 1 of 1 with 10 MutationType ops upsert descriptor #104 ... formatVersion: 3 @@ -114,11 +114,17 @@ upsert descriptor #104 + authorization: + userName: root + currentStatuses: + + - PUBLIC + + - PUBLIC + + - PUBLIC + - BACKFILL_ONLY + - ABSENT + - PUBLIC + - DELETE_ONLY + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + jobId: "1" + relevantStatements: + - statement: @@ -135,20 +141,47 @@ upsert descriptor #104 + - 2 + - 3 + - 4 + + - 5 + + - 6 + + - 7 + + - 8 + + - 9 + + - 10 + targets: + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 2 + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 2 + + ordinalInKind: 1 + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 2 + + kind: STORED + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + secondaryIndex: + embeddedIndex: + indexId: 2 - + keyColumnDirections: - + - ASC - + - ASC - + keyColumnIds: - + - 1 - + - 2 + sourceIndexId: 1 - + storingColumnIds: - + - 3 + tableId: 104 + temporaryIndexId: 3 + metadata: @@ -183,15 +216,7 @@ upsert descriptor #104 + temporaryIndex: + embeddedIndex: + indexId: 3 - + keyColumnDirections: - + - ASC - + - ASC - + keyColumnIds: - + - 1 - + - 2 + sourceIndexId: 1 - + storingColumnIds: - + - 3 + tableId: 104 + isUsingSecondaryEncoding: true + metadata: @@ -199,6 +224,35 @@ upsert descriptor #104 + subWorkId: 1 + targetStatus: TRANSIENT_ABSENT + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 3 + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 3 + + ordinalInKind: 1 + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 3 + + kind: STORED + + tableId: 104 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + indexPartitioning: + indexId: 3 + partitioning: @@ -241,7 +295,7 @@ upsert descriptor #104 - - DELETE_ONLY + - WRITE_ONLY - PUBLIC - jobId: "1" + - PUBLIC ... formatVersion: 3 id: 104 @@ -272,8 +326,8 @@ begin transaction #5 ## PostCommitPhase stage 3 of 7 with 3 MutationType ops upsert descriptor #104 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - BACKFILL_ONLY + - DELETE_ONLY - ABSENT @@ -304,8 +358,8 @@ begin transaction #6 ## PostCommitPhase stage 4 of 7 with 3 MutationType ops upsert descriptor #104 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - DELETE_ONLY + - MERGE_ONLY - ABSENT @@ -344,8 +398,8 @@ begin transaction #9 ## PostCommitPhase stage 7 of 7 with 4 MutationType ops upsert descriptor #104 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - MERGE_ONLY - - ABSENT - PUBLIC @@ -450,7 +504,7 @@ upsert descriptor #104 - - WRITE_ONLY + - TRANSIENT_DELETE_ONLY - PUBLIC - jobId: "1" + - PUBLIC ... - money version: 4 @@ -458,7 +512,10 @@ upsert descriptor #104 - wallTime: "1640995200000000009" + modificationTime: {} mutations: - - direction: ADD + - - direction: ADD + + - direction: DROP + index: + constraintId: 3 ... version: 4 mutationId: 1 @@ -486,8 +543,14 @@ upsert descriptor #104 - - PUBLIC - - PUBLIC - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC - - TRANSIENT_DELETE_ONLY - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC - jobId: "1" - relevantStatements: - - statement: @@ -503,20 +566,47 @@ upsert descriptor #104 - - 2 - - 3 - - 4 + - - 5 + - - 6 + - - 7 + - - 8 + - - 9 + - - 10 - targets: - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 2 + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 2 + - ordinalInKind: 1 + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 2 + - kind: STORED + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - secondaryIndex: - embeddedIndex: - indexId: 2 - - keyColumnDirections: - - - ASC - - - ASC - - keyColumnIds: - - - 1 - - - 2 - sourceIndexId: 1 - - storingColumnIds: - - - 3 - tableId: 104 - temporaryIndexId: 3 - metadata: @@ -551,15 +641,7 @@ upsert descriptor #104 - temporaryIndex: - embeddedIndex: - indexId: 3 - - keyColumnDirections: - - - ASC - - - ASC - - keyColumnIds: - - - 1 - - - 2 - sourceIndexId: 1 - - storingColumnIds: - - - 3 - tableId: 104 - isUsingSecondaryEncoding: true - metadata: @@ -567,6 +649,35 @@ upsert descriptor #104 - subWorkId: 1 - targetStatus: TRANSIENT_ABSENT - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 3 + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 3 + - ordinalInKind: 1 + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 3 + - kind: STORED + - tableId: 104 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - indexPartitioning: - indexId: 3 - partitioning: @@ -589,7 +700,7 @@ upsert descriptor #104 - modificationTime: - wallTime: "1640995200000000010" - mutations: - - - direction: ADD + - - direction: DROP - index: - constraintId: 3 - createdExplicitly: true diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion index c28bc3882faf..45a4378127e9 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion @@ -145,6 +145,8 @@ upsert descriptor #108 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + - ABSENT @@ -179,6 +181,8 @@ upsert descriptor #108 + - 21 + - 22 + - 23 + + - 24 + + - 25 + targets: + - elementProto: + namespace: @@ -397,17 +401,30 @@ upsert descriptor #108 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + tableId: 108 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + ordinalInKind: 1 + + tableId: 108 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + - ASC - + keyColumnIds: - + - 2 - + - 1 + tableId: 108 + metadata: + sourceElementId: 1 @@ -538,6 +555,8 @@ upsert descriptor #108 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - - ABSENT @@ -572,6 +591,8 @@ upsert descriptor #108 - - 21 - - 22 - - 23 + - - 24 + - - 25 - targets: - - elementProto: - namespace: @@ -790,17 +811,30 @@ upsert descriptor #108 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - tableId: 108 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - ordinalInKind: 1 + - tableId: 108 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - - ASC - - keyColumnIds: - - - 2 - - - 1 - tableId: 108 - metadata: - sourceElementId: 1 @@ -967,6 +1001,7 @@ upsert descriptor #109 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + jobId: "1" @@ -997,6 +1032,7 @@ upsert descriptor #109 + - 16 + - 17 + - 18 + + - 19 + targets: + - elementProto: + namespace: @@ -1167,15 +1203,20 @@ upsert descriptor #109 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + tableId: 109 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + tableId: 109 + metadata: + sourceElementId: 1 @@ -1258,6 +1299,7 @@ upsert descriptor #109 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - jobId: "1" @@ -1288,6 +1330,7 @@ upsert descriptor #109 - - 16 - - 17 - - 18 + - - 19 - targets: - - elementProto: - namespace: @@ -1458,15 +1501,20 @@ upsert descriptor #109 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - tableId: 109 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - tableId: 109 - metadata: - sourceElementId: 1 diff --git a/pkg/kv/kvserver/reports/constraint_stats_report_test.go b/pkg/kv/kvserver/reports/constraint_stats_report_test.go index 490491694621..17718a55a752 100644 --- a/pkg/kv/kvserver/reports/constraint_stats_report_test.go +++ b/pkg/kv/kvserver/reports/constraint_stats_report_test.go @@ -403,7 +403,7 @@ func (idx index) toIndexDescriptor(id int) descpb.IndexDescriptor { for i := 0; i < neededCols; i++ { idxDesc.KeyColumnIDs = append(idxDesc.KeyColumnIDs, descpb.ColumnID(i)) idxDesc.KeyColumnNames = append(idxDesc.KeyColumnNames, fmt.Sprintf("col%d", i)) - idxDesc.KeyColumnDirections = append(idxDesc.KeyColumnDirections, descpb.IndexDescriptor_ASC) + idxDesc.KeyColumnDirections = append(idxDesc.KeyColumnDirections, catpb.IndexColumn_ASC) } idxDesc.Partitioning.NumColumns = uint32(len(idx.partitions[0].start)) for _, p := range idx.partitions { diff --git a/pkg/sql/alter_primary_key.go b/pkg/sql/alter_primary_key.go index c178db83cb3f..e7e700f19a4e 100644 --- a/pkg/sql/alter_primary_key.go +++ b/pkg/sql/alter_primary_key.go @@ -615,9 +615,9 @@ func (p *planner) shouldCreateIndexes( return true, nil } if (elem.Direction == tree.Ascending && - oldPK.GetKeyColumnDirection(idx) != descpb.IndexDescriptor_ASC) || + oldPK.GetKeyColumnDirection(idx) != catpb.IndexColumn_ASC) || (elem.Direction == tree.Descending && - oldPK.GetKeyColumnDirection(idx) != descpb.IndexDescriptor_DESC) { + oldPK.GetKeyColumnDirection(idx) != catpb.IndexColumn_DESC) { return true, nil } } @@ -655,7 +655,7 @@ func shouldCopyPrimaryKey( columnIDsAndDirsWithoutSharded := func(idx *descpb.IndexDescriptor) ( columnIDs descpb.ColumnIDs, - columnDirs []descpb.IndexDescriptor_Direction, + columnDirs []catpb.IndexColumn_Direction, ) { for i, colName := range idx.KeyColumnNames { if colName != idx.Sharded.Name { diff --git a/pkg/sql/alter_table_locality.go b/pkg/sql/alter_table_locality.go index 60b2c7eb9775..ac609f773164 100644 --- a/pkg/sql/alter_table_locality.go +++ b/pkg/sql/alter_table_locality.go @@ -404,7 +404,7 @@ func (n *alterTableSetLocalityNode) alterTableLocalityFromOrToRegionalByRow( newColumnID *descpb.ColumnID, newColumnDefaultExpr *string, pkColumnNames []string, - pkColumnDirections []descpb.IndexDescriptor_Direction, + pkColumnDirections []catpb.IndexColumn_Direction, ) error { // Preserve the same PK columns - implicit partitioning will be added in // AlterPrimaryKey. @@ -414,9 +414,9 @@ func (n *alterTableSetLocalityNode) alterTableLocalityFromOrToRegionalByRow( Column: tree.Name(col), } switch dir := pkColumnDirections[i]; dir { - case descpb.IndexDescriptor_ASC: + case catpb.IndexColumn_ASC: cols[i].Direction = tree.Ascending - case descpb.IndexDescriptor_DESC: + case catpb.IndexColumn_DESC: cols[i].Direction = tree.Descending default: return errors.AssertionFailedf("unknown direction: %v", dir) diff --git a/pkg/sql/backfill_test.go b/pkg/sql/backfill_test.go index 0fc270683fb5..fd43f88974ad 100644 --- a/pkg/sql/backfill_test.go +++ b/pkg/sql/backfill_test.go @@ -57,7 +57,7 @@ func TestShouldSkipConstraintValidation(t *testing.T) { PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "pri", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, @@ -67,9 +67,9 @@ func TestShouldSkipConstraintValidation(t *testing.T) { Index: &descpb.IndexDescriptor{ ID: 2, Name: "new_hash_index", KeyColumnIDs: []descpb.ColumnID{2, 3}, KeyColumnNames: []string{"c2", "c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, diff --git a/pkg/sql/catalog/catalogkeys/BUILD.bazel b/pkg/sql/catalog/catalogkeys/BUILD.bazel index 1e823d03f5bd..d48445d74a8f 100644 --- a/pkg/sql/catalog/catalogkeys/BUILD.bazel +++ b/pkg/sql/catalog/catalogkeys/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "//pkg/keys", "//pkg/roachpb", "//pkg/sql/catalog", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/sem/catconstants", "//pkg/util/encoding", diff --git a/pkg/sql/catalog/catalogkeys/keys.go b/pkg/sql/catalog/catalogkeys/keys.go index 6cc075ced251..4cf863859671 100644 --- a/pkg/sql/catalog/catalogkeys/keys.go +++ b/pkg/sql/catalog/catalogkeys/keys.go @@ -16,6 +16,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants" "github.com/cockroachdb/cockroach/pkg/util/encoding" @@ -36,6 +37,19 @@ var DefaultUserDBs = []string{ DefaultDatabaseName, PgDatabaseName, } +// IndexColumnEncodingDirection converts a direction from the proto to an +// encoding.Direction. +func IndexColumnEncodingDirection(dir catpb.IndexColumn_Direction) (encoding.Direction, error) { + switch dir { + case catpb.IndexColumn_ASC: + return encoding.Ascending, nil + case catpb.IndexColumn_DESC: + return encoding.Descending, nil + default: + return 0, errors.Errorf("invalid direction: %s", dir) + } +} + // IndexKeyValDirs returns the corresponding encoding.Directions for all the // encoded values in index's "fullest" possible index key, including directions // for table/index IDs and the index column values. @@ -50,7 +64,7 @@ func IndexKeyValDirs(index catalog.Index) []encoding.Direction { dirs = append(dirs, encoding.Ascending, encoding.Ascending) for colIdx := 0; colIdx < index.NumKeyColumns(); colIdx++ { - d, err := index.GetKeyColumnDirection(colIdx).ToEncodingDirection() + d, err := IndexColumnEncodingDirection(index.GetKeyColumnDirection(colIdx)) if err != nil { panic(err) } diff --git a/pkg/sql/catalog/catformat/index_test.go b/pkg/sql/catalog/catformat/index_test.go index ed4e30f971b4..67a371b42ad7 100644 --- a/pkg/sql/catalog/catformat/index_test.go +++ b/pkg/sql/catalog/catformat/index_test.go @@ -74,7 +74,7 @@ func TestIndexForDisplay(t *testing.T) { ID: 0x0, KeyColumnNames: []string{"a", "b"}, KeyColumnIDs: descpb.ColumnIDs{1, 2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_DESC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_DESC}, } // UNIQUE INDEX baz (a ASC, b DESC) @@ -99,8 +99,8 @@ func TestIndexForDisplay(t *testing.T) { expressionIndex := baseIndex expressionIndex.KeyColumnNames = []string{"a", "d", "b"} expressionIndex.KeyColumnIDs = descpb.ColumnIDs{1, 4, 2} - expressionIndex.KeyColumnDirections = []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_DESC, descpb.IndexDescriptor_ASC, + expressionIndex.KeyColumnDirections = []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, catpb.IndexColumn_DESC, catpb.IndexColumn_ASC, } // Hash Sharded INDEX baz (a) diff --git a/pkg/sql/catalog/catpb/BUILD.bazel b/pkg/sql/catalog/catpb/BUILD.bazel index a5951f2101f3..dd457a654ec1 100644 --- a/pkg/sql/catalog/catpb/BUILD.bazel +++ b/pkg/sql/catalog/catpb/BUILD.bazel @@ -8,6 +8,7 @@ proto_library( name = "catpb_proto", srcs = [ "catalog.proto", + "index.proto", "privilege.proto", ], strip_import_prefix = "/pkg", diff --git a/pkg/sql/catalog/catpb/index.proto b/pkg/sql/catalog/catpb/index.proto new file mode 100644 index 000000000000..9aeb64a7850a --- /dev/null +++ b/pkg/sql/catalog/catpb/index.proto @@ -0,0 +1,27 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +syntax = "proto3"; + +package cockroach.sql.catalog.catpb; +option go_package = "catpb"; + +import "gogoproto/gogo.proto"; + +// IndexColumn contains an enum used to represent the direction of a column +// in an index key. +message IndexColumn { + + // IndexColumn_Direction refers to the direction of a column in an index. + enum Direction { + ASC = 0; + DESC = 1; + } +} diff --git a/pkg/sql/catalog/descpb/index.go b/pkg/sql/catalog/descpb/index.go index 8d909c84f20e..e2c54453675a 100644 --- a/pkg/sql/catalog/descpb/index.go +++ b/pkg/sql/catalog/descpb/index.go @@ -13,6 +13,7 @@ package descpb import ( "fmt" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" types "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/errors" @@ -43,7 +44,7 @@ func (desc *IndexDescriptor) ExplicitColumnStartIdx() int { // FillColumns sets the column names and directions in desc. func (desc *IndexDescriptor) FillColumns(elems tree.IndexElemList) error { desc.KeyColumnNames = make([]string, 0, len(elems)) - desc.KeyColumnDirections = make([]IndexDescriptor_Direction, 0, len(elems)) + desc.KeyColumnDirections = make([]catpb.IndexColumn_Direction, 0, len(elems)) for _, c := range elems { if c.Expr != nil { return errors.AssertionFailedf("index elem expression should have been replaced with a column") @@ -51,9 +52,9 @@ func (desc *IndexDescriptor) FillColumns(elems tree.IndexElemList) error { desc.KeyColumnNames = append(desc.KeyColumnNames, string(c.Column)) switch c.Direction { case tree.Ascending, tree.DefaultDirection: - desc.KeyColumnDirections = append(desc.KeyColumnDirections, IndexDescriptor_ASC) + desc.KeyColumnDirections = append(desc.KeyColumnDirections, catpb.IndexColumn_ASC) case tree.Descending: - desc.KeyColumnDirections = append(desc.KeyColumnDirections, IndexDescriptor_DESC) + desc.KeyColumnDirections = append(desc.KeyColumnDirections, catpb.IndexColumn_DESC) default: return fmt.Errorf("invalid direction %s for column %s", c.Direction, c.Column) } diff --git a/pkg/sql/catalog/descpb/index_fetch.go b/pkg/sql/catalog/descpb/index_fetch.go index 27dfc369556a..962475c777c8 100644 --- a/pkg/sql/catalog/descpb/index_fetch.go +++ b/pkg/sql/catalog/descpb/index_fetch.go @@ -11,6 +11,7 @@ package descpb import ( + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util/encoding" ) @@ -53,7 +54,7 @@ func (s *IndexFetchSpec) FetchedColumnTypes() []*types.T { // DatumEncoding returns the datum encoding that corresponds to the key column // direction. func (c *IndexFetchSpec_KeyColumn) DatumEncoding() DatumEncoding { - if c.Direction == IndexDescriptor_DESC { + if c.Direction == catpb.IndexColumn_DESC { return DatumEncoding_DESCENDING_KEY } return DatumEncoding_ASCENDING_KEY @@ -61,7 +62,7 @@ func (c *IndexFetchSpec_KeyColumn) DatumEncoding() DatumEncoding { // EncodingDirection returns the encoding direction for the key column. func (c *IndexFetchSpec_KeyColumn) EncodingDirection() encoding.Direction { - if c.Direction == IndexDescriptor_DESC { + if c.Direction == catpb.IndexColumn_DESC { return encoding.Descending } return encoding.Ascending diff --git a/pkg/sql/catalog/descpb/index_fetch.proto b/pkg/sql/catalog/descpb/index_fetch.proto index 6fbc6f0dfb62..79200bab7f95 100644 --- a/pkg/sql/catalog/descpb/index_fetch.proto +++ b/pkg/sql/catalog/descpb/index_fetch.proto @@ -15,7 +15,7 @@ option go_package = "descpb"; import "gogoproto/gogo.proto"; import "sql/types/types.proto"; -import "sql/catalog/descpb/structured.proto"; +import "sql/catalog/catpb/index.proto"; import "geo/geoindex/config.proto"; // IndexFetchSpec contains the subset of information (from TableDescriptor and @@ -44,7 +44,7 @@ message IndexFetchSpec { // KeyColumn describes a column that is encoded using the key encoding. message KeyColumn { optional Column column = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; - optional IndexDescriptor.Direction direction = 2 [(gogoproto.nullable) = false]; + optional catalog.catpb.IndexColumn.Direction direction = 2 [(gogoproto.nullable) = false]; // IsComposite is true if this column can have a composite encoding (i.e. it // can appear in the value in addition to the key). diff --git a/pkg/sql/catalog/descpb/structured.go b/pkg/sql/catalog/descpb/structured.go index 7b4aa0e62f57..e319e8b5b14c 100644 --- a/pkg/sql/catalog/descpb/structured.go +++ b/pkg/sql/catalog/descpb/structured.go @@ -17,22 +17,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/util" - "github.com/cockroachdb/cockroach/pkg/util/encoding" - "github.com/cockroachdb/errors" ) -// ToEncodingDirection converts a direction from the proto to an encoding.Direction. -func (dir IndexDescriptor_Direction) ToEncodingDirection() (encoding.Direction, error) { - switch dir { - case IndexDescriptor_ASC: - return encoding.Ascending, nil - case IndexDescriptor_DESC: - return encoding.Descending, nil - default: - return encoding.Ascending, errors.Errorf("invalid direction: %s", dir) - } -} - // ID, ColumnID, FamilyID, and IndexID are all uint32, but are each given a // type alias to prevent accidental use of one of the types where // another is expected. diff --git a/pkg/sql/catalog/descpb/structured.proto b/pkg/sql/catalog/descpb/structured.proto index e3e3f2235fe5..d7165f47d0bf 100644 --- a/pkg/sql/catalog/descpb/structured.proto +++ b/pkg/sql/catalog/descpb/structured.proto @@ -17,6 +17,7 @@ import "config/zonepb/zone.proto"; import "util/hlc/timestamp.proto"; import "sql/catalog/catpb/catalog.proto"; import "sql/catalog/catpb/privilege.proto"; +import "sql/catalog/catpb/index.proto"; import "sql/schemachanger/scpb/scpb.proto"; import "sql/types/types.proto"; import "geo/geoindex/config.proto"; @@ -324,11 +325,6 @@ message InterleaveDescriptor { // store_column_ids: 5 // w message IndexDescriptor { option (gogoproto.equal) = true; - // The direction of a column in the index. - enum Direction { - ASC = 0; - DESC = 1; - } // The type of the index. enum Type { @@ -356,7 +352,7 @@ message IndexDescriptor { repeated string key_column_names = 4; // The sort direction of each column in key_column_names. - repeated Direction key_column_directions = 8; + repeated cockroach.sql.catalog.catpb.IndexColumn.Direction key_column_directions = 8; // An ordered list of column names which the index stores in addition to the // columns which are explicitly part of the index (STORING clause). diff --git a/pkg/sql/catalog/descriptor.go b/pkg/sql/catalog/descriptor.go index 326cf7850b70..d4f3814e892a 100644 --- a/pkg/sql/catalog/descriptor.go +++ b/pkg/sql/catalog/descriptor.go @@ -502,7 +502,7 @@ type TableDescriptor interface { IndexKeyColumns(idx Index) []Column // IndexKeyColumnDirections returns a slice of column directions for all // key columns in the specified Index. - IndexKeyColumnDirections(idx Index) []descpb.IndexDescriptor_Direction + IndexKeyColumnDirections(idx Index) []catpb.IndexColumn_Direction // IndexKeySuffixColumns returns a slice of Column interfaces containing all // key suffix columns in the specified Index. IndexKeySuffixColumns(idx Index) []Column @@ -513,7 +513,7 @@ type TableDescriptor interface { // IndexFullColumnDirections returns a slice of column directions for all // key columns in the specified Index, plus all key suffix columns if that // index is not a unique index. - IndexFullColumnDirections(idx Index) []descpb.IndexDescriptor_Direction + IndexFullColumnDirections(idx Index) []catpb.IndexColumn_Direction // IndexStoredColumns returns a slice of Column interfaces containing all // stored columns in the specified Index. IndexStoredColumns(idx Index) []Column diff --git a/pkg/sql/catalog/descs/collection_test.go b/pkg/sql/catalog/descs/collection_test.go index b6dcddc261a7..f87538cc1688 100644 --- a/pkg/sql/catalog/descs/collection_test.go +++ b/pkg/sql/catalog/descs/collection_test.go @@ -100,7 +100,7 @@ func TestCollectionWriteDescToBatch(t *testing.T) { Name: "pk", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"a"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, ConstraintID: 1, diff --git a/pkg/sql/catalog/systemschema/system.go b/pkg/sql/catalog/systemschema/system.go index 8b2a4ad68a07..c27deb2fa96c 100644 --- a/pkg/sql/catalog/systemschema/system.go +++ b/pkg/sql/catalog/systemschema/system.go @@ -678,7 +678,7 @@ func pk(name string) descpb.IndexDescriptor { // Helpers used to make some of the descpb.TableDescriptor literals below more concise. var ( - singleASC = []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC} + singleASC = []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC} singleID1 = []descpb.ColumnID{1} // The hash computation expression below is generated by running the CREATE @@ -843,7 +843,7 @@ var ( ID: catconstants.NamespaceTablePrimaryIndexID, Unique: true, KeyColumnNames: []string{"parentID", "parentSchemaID", "name"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2, 3}, }, )) @@ -964,7 +964,7 @@ var ( Name: tabledesc.LegacyPrimaryKeyIndexName, KeyColumnIDs: []descpb.ColumnID{tabledesc.SequenceColumnID}, KeyColumnNames: []string{tabledesc.SequenceColumnName}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, ), func(tbl *descpb.TableDescriptor) { @@ -1038,7 +1038,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"descID", "version", "expiration", "nodeID"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2, 4, 3}, }, )) @@ -1074,7 +1074,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"timestamp", "uniqueID"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 6}, }, )) @@ -1109,7 +1109,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"timestamp", "uniqueID"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 7}, }, )) @@ -1184,7 +1184,7 @@ var ( ID: 2, Unique: false, KeyColumnNames: []string{"status", "created"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{2, 3}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1194,7 +1194,7 @@ var ( ID: 3, Unique: false, KeyColumnNames: []string{"created_by_type", "created_by_id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{6, 7}, StoreColumnIDs: []descpb.ColumnID{2}, StoreColumnNames: []string{"status"}, @@ -1206,7 +1206,7 @@ var ( ID: 4, Unique: false, KeyColumnNames: []string{"claim_session_id", "status", "created"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{8, 2, 3}, StoreColumnNames: []string{"last_run", "num_runs", "claim_instance_id"}, StoreColumnIDs: []descpb.ColumnID{11, 10, 9}, @@ -1255,7 +1255,7 @@ var ( ID: 2, Unique: false, KeyColumnNames: []string{"expiresAt"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{5}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1265,7 +1265,7 @@ var ( ID: 3, Unique: false, KeyColumnNames: []string{"createdAt"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{4}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1275,7 +1275,7 @@ var ( ID: 4, Unique: false, KeyColumnNames: []string{"revokedAt"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{6}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1285,7 +1285,7 @@ var ( ID: 5, Unique: false, KeyColumnNames: []string{"lastUsedAt"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{7}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1334,7 +1334,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"tableID", "statisticID"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, )) @@ -1366,7 +1366,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"localityKey", "localityValue"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, )) @@ -1402,7 +1402,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"role", "member"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, descpb.IndexDescriptor{ @@ -1410,7 +1410,7 @@ var ( ID: 2, Unique: false, KeyColumnNames: []string{"role"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1}, KeySuffixColumnIDs: []descpb.ColumnID{2}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1420,7 +1420,7 @@ var ( ID: 3, Unique: false, KeyColumnNames: []string{"member"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{2}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1448,7 +1448,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"type", "object_id", "sub_id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2, 3}, }, ), @@ -1487,8 +1487,8 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1}, }, @@ -1533,8 +1533,8 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"zone_id", "subzone_id", "type", "config"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2, 3, 4}, }, @@ -1574,8 +1574,8 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"zone_id", "subzone_id", "locality"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2, 3}, }, @@ -1620,7 +1620,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"zone_id", "subzone_id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, )) @@ -1655,8 +1655,8 @@ var ( Unique: true, KeyColumnNames: []string{"singleton"}, KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, }, ), @@ -1700,8 +1700,8 @@ var ( Unique: true, KeyColumnNames: []string{"id"}, KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, }, )) @@ -1730,7 +1730,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"username", "option"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, )) @@ -1788,7 +1788,7 @@ var ( KeyColumnNames: []string{"completed", "id"}, StoreColumnNames: []string{"statement_fingerprint", "min_execution_latency", "expires_at", "sampling_probability"}, KeyColumnIDs: []descpb.ColumnID{2, 1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, StoreColumnIDs: []descpb.ColumnID{3, 6, 7, 8}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, @@ -1871,7 +1871,7 @@ var ( ID: 2, Unique: false, KeyColumnNames: []string{"next_run"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{5}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -1929,11 +1929,11 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"major", "minor", "patch", "internal"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2, 3, 4}, }, @@ -1964,8 +1964,8 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1}, }, @@ -2024,14 +2024,14 @@ var ( "app_name", "node_id", }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{11, 1, 2, 3, 4, 5, 6}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -2057,9 +2057,9 @@ var ( "fingerprint_id", "transaction_fingerprint_id", }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{2, 3}, KeySuffixColumnIDs: []descpb.ColumnID{11, 1, 4, 5, 6}, @@ -2126,12 +2126,12 @@ var ( "app_name", "node_id", }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{8, 1, 2, 3, 4}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -2154,8 +2154,8 @@ var ( KeyColumnNames: []string{ "fingerprint_id", }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{2}, KeySuffixColumnIDs: []descpb.ColumnID{8, 1, 3, 4}, @@ -2204,8 +2204,8 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"database_id", "role_name"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, @@ -2254,9 +2254,9 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"tenant_id", "instance_id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -2354,9 +2354,9 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"tenant_id", "name"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1, 2}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, @@ -2417,7 +2417,7 @@ var ( ID: 1, Unique: true, KeyColumnNames: []string{"username", "path"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, ), diff --git a/pkg/sql/catalog/table_elements.go b/pkg/sql/catalog/table_elements.go index ea5973ce1f67..90df88bf144b 100644 --- a/pkg/sql/catalog/table_elements.go +++ b/pkg/sql/catalog/table_elements.go @@ -159,7 +159,7 @@ type Index interface { NumKeyColumns() int GetKeyColumnID(columnOrdinal int) descpb.ColumnID GetKeyColumnName(columnOrdinal int) string - GetKeyColumnDirection(columnOrdinal int) descpb.IndexDescriptor_Direction + GetKeyColumnDirection(columnOrdinal int) catpb.IndexColumn_Direction CollectKeyColumnIDs() TableColSet CollectKeySuffixColumnIDs() TableColSet diff --git a/pkg/sql/catalog/tabledesc/column.go b/pkg/sql/catalog/tabledesc/column.go index 0d0bc0d83a1d..df8a8dad0464 100644 --- a/pkg/sql/catalog/tabledesc/column.go +++ b/pkg/sql/catalog/tabledesc/column.go @@ -267,13 +267,13 @@ type columnCache struct { type indexColumnCache struct { all []catalog.Column - allDirs []descpb.IndexDescriptor_Direction + allDirs []catpb.IndexColumn_Direction key []catalog.Column - keyDirs []descpb.IndexDescriptor_Direction + keyDirs []catpb.IndexColumn_Direction stored []catalog.Column keySuffix []catalog.Column full []catalog.Column - fullDirs []descpb.IndexDescriptor_Direction + fullDirs []catpb.IndexColumn_Direction keyAndSuffix []descpb.IndexFetchSpec_KeyColumn } @@ -371,7 +371,7 @@ func makeIndexColumnCache(idx *descpb.IndexDescriptor, all []catalog.Column) (ic nKeySuffix := len(idx.KeySuffixColumnIDs) nStored := len(idx.StoreColumnIDs) nAll := nKey + nKeySuffix + nStored - ic.allDirs = make([]descpb.IndexDescriptor_Direction, nAll) + ic.allDirs = make([]catpb.IndexColumn_Direction, nAll) // Only copy key column directions, others will remain at ASC (default value). copy(ic.allDirs, idx.KeyColumnDirections) ic.all = make([]catalog.Column, 0, nAll) diff --git a/pkg/sql/catalog/tabledesc/index.go b/pkg/sql/catalog/tabledesc/index.go index f8287f8e9f37..541012d054de 100644 --- a/pkg/sql/catalog/tabledesc/index.go +++ b/pkg/sql/catalog/tabledesc/index.go @@ -281,7 +281,7 @@ func (w index) GetKeyColumnName(columnOrdinal int) string { // GetKeyColumnDirection returns the direction of the columnOrdinal-th column in // the index key. -func (w index) GetKeyColumnDirection(columnOrdinal int) descpb.IndexDescriptor_Direction { +func (w index) GetKeyColumnDirection(columnOrdinal int) catpb.IndexColumn_Direction { return w.desc.KeyColumnDirections[columnOrdinal] } diff --git a/pkg/sql/catalog/tabledesc/index_test.go b/pkg/sql/catalog/tabledesc/index_test.go index b38e87fc9cbc..c2bf8d6038c4 100644 --- a/pkg/sql/catalog/tabledesc/index_test.go +++ b/pkg/sql/catalog/tabledesc/index_test.go @@ -297,7 +297,7 @@ func TestIndexInterface(t *testing.T) { colIDs.UnionWith(idx.CollectKeySuffixColumnIDs()) for j := range actualColNames { actualColNames[j] = idx.GetKeyColumnName(j) - require.Equalf(t, idx == s1, idx.GetKeyColumnDirection(j) == descpb.IndexDescriptor_DESC, + require.Equalf(t, idx == s1, idx.GetKeyColumnDirection(j) == catpb.IndexColumn_DESC, "mismatched column directions for index '%s'", idx.GetName()) require.True(t, colIDs.Contains(idx.GetKeyColumnID(j)), "column ID resolution failure for column '%s' in index '%s'", idx.GetKeyColumnName(j), idx.GetName()) @@ -591,13 +591,13 @@ func TestSecKeyLatestIndexDescriptorVersion(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "foo_pkey", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnNames: []string{"c2"}, StoreColumnIDs: []descpb.ColumnID{2}, Version: descpb.EmptyArraysInInvertedIndexesVersion, @@ -613,7 +613,7 @@ func TestSecKeyLatestIndexDescriptorVersion(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{3}, KeyColumnNames: []string{"c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.EmptyArraysInInvertedIndexesVersion, EncodingType: descpb.SecondaryIndexEncoding, ConstraintID: 1, diff --git a/pkg/sql/catalog/tabledesc/safe_format_test.go b/pkg/sql/catalog/tabledesc/safe_format_test.go index 9256654a35d4..7e037cc56667 100644 --- a/pkg/sql/catalog/tabledesc/safe_format_test.go +++ b/pkg/sql/catalog/tabledesc/safe_format_test.go @@ -208,9 +208,9 @@ func TestSafeMessage(t *testing.T) { KeySuffixColumnIDs: []descpb.ColumnID{1}, StoreColumnIDs: []descpb.ColumnID{5}, KeyColumnNames: []string{"j_str", "j"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_DESC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, + catpb.IndexColumn_DESC, }, StoreColumnNames: []string{"c"}, }, diff --git a/pkg/sql/catalog/tabledesc/structured.go b/pkg/sql/catalog/tabledesc/structured.go index 7e633c9fec8f..a70ac7b6c380 100644 --- a/pkg/sql/catalog/tabledesc/structured.go +++ b/pkg/sql/catalog/tabledesc/structured.go @@ -679,7 +679,7 @@ func (desc *Mutable) ensurePrimaryKey() error { idx := descpb.IndexDescriptor{ Unique: true, KeyColumnNames: []string{col.Name}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, } if err := desc.AddPrimaryIndex(idx); err != nil { return err diff --git a/pkg/sql/catalog/tabledesc/structured_test.go b/pkg/sql/catalog/tabledesc/structured_test.go index 7ae1e49e69ab..16e17bca82b7 100644 --- a/pkg/sql/catalog/tabledesc/structured_test.go +++ b/pkg/sql/catalog/tabledesc/structured_test.go @@ -39,9 +39,9 @@ import ( // Makes an descpb.IndexDescriptor with all columns being ascending. func makeIndexDescriptor(name string, columnNames []string) descpb.IndexDescriptor { - dirs := make([]descpb.IndexDescriptor_Direction, 0, len(columnNames)) + dirs := make([]catpb.IndexColumn_Direction, 0, len(columnNames)) for range columnNames { - dirs = append(dirs, descpb.IndexDescriptor_ASC) + dirs = append(dirs, catpb.IndexColumn_ASC) } idx := descpb.IndexDescriptor{ ID: descpb.IndexID(0), @@ -113,8 +113,8 @@ func TestAllocateIDs(t *testing.T) { PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "c", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"a", "b"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, - descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, + catpb.IndexColumn_ASC}, StoreColumnIDs: descpb.ColumnIDs{3}, StoreColumnNames: []string{"c"}, EncodingType: descpb.PrimaryIndexEncoding, @@ -127,7 +127,7 @@ func TestAllocateIDs(t *testing.T) { Name: "d", KeyColumnIDs: []descpb.ColumnID{2, 1}, KeyColumnNames: []string{"b", "a"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, { @@ -135,7 +135,7 @@ func TestAllocateIDs(t *testing.T) { Name: "e", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"b"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, @@ -144,7 +144,7 @@ func TestAllocateIDs(t *testing.T) { Name: "f", KeyColumnIDs: []descpb.ColumnID{3}, KeyColumnNames: []string{"c"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, @@ -364,7 +364,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, }, Privileges: catpb.NewBasePrivilegeDescriptor(username.RootUserName()), }, @@ -394,7 +394,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, ConstraintID: 1, @@ -430,7 +430,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, ConstraintID: 1, @@ -441,7 +441,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "other", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"foo"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1}, // This corruption is benign but prevents bumping Version. Version: descpb.SecondaryIndexFamilyFormatVersion, }, @@ -470,7 +470,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, ConstraintID: 1, }, @@ -480,7 +480,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "other", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"foo"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, @@ -512,7 +512,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, ConstraintID: 1, }, Indexes: []descpb.IndexDescriptor{ @@ -521,7 +521,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "other", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"foo"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.EmptyArraysInInvertedIndexesVersion, }, { @@ -529,7 +529,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "another", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.EmptyArraysInInvertedIndexesVersion, }, }, @@ -561,7 +561,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1, 2}, KeyColumnNames: []string{"foo", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, ConstraintID: 1, @@ -572,7 +572,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "other", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"foo"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.SecondaryIndexEncoding, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, @@ -581,7 +581,7 @@ func TestMaybeUpgradeIndexFormatVersion(t *testing.T) { Name: "another", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.SecondaryIndexEncoding, Version: descpb.StrictIndexColumnIDGuaranteesVersion, }, diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index 6a9e5b9b3b98..968e6b66d8a0 100644 --- a/pkg/sql/catalog/tabledesc/table.go +++ b/pkg/sql/catalog/tabledesc/table.go @@ -207,7 +207,7 @@ func MakeColumnDefDescs( ret.PrimaryKeyOrUniqueIndexDescriptor = &descpb.IndexDescriptor{ Unique: true, KeyColumnNames: []string{string(d.Name)}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, } } else { buckets, err := EvalShardBucketCount(ctx, semaCtx, evalCtx, d.PrimaryKey.ShardBuckets, d.PrimaryKey.StorageParams) @@ -218,7 +218,7 @@ func MakeColumnDefDescs( ret.PrimaryKeyOrUniqueIndexDescriptor = &descpb.IndexDescriptor{ Unique: true, KeyColumnNames: []string{shardColName, string(d.Name)}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Sharded: catpb.ShardedDescriptor{ IsSharded: true, Name: shardColName, diff --git a/pkg/sql/catalog/tabledesc/table_desc.go b/pkg/sql/catalog/tabledesc/table_desc.go index d5a6b1c9555d..ca783ec0235e 100644 --- a/pkg/sql/catalog/tabledesc/table_desc.go +++ b/pkg/sql/catalog/tabledesc/table_desc.go @@ -198,11 +198,11 @@ func UpdateIndexPartitioning( newCap := numCols + len(newImplicitCols) - oldNumImplicitCols newColumnIDs := make([]descpb.ColumnID, len(newImplicitCols), newCap) newColumnNames := make([]string, len(newImplicitCols), newCap) - newColumnDirections := make([]descpb.IndexDescriptor_Direction, len(newImplicitCols), newCap) + newColumnDirections := make([]catpb.IndexColumn_Direction, len(newImplicitCols), newCap) for i, col := range newImplicitCols { newColumnIDs[i] = col.GetID() newColumnNames[i] = col.GetName() - newColumnDirections[i] = descpb.IndexDescriptor_ASC + newColumnDirections[i] = catpb.IndexColumn_ASC if isNoOp && (idx.KeyColumnIDs[i] != newColumnIDs[i] || idx.KeyColumnNames[i] != newColumnNames[i] || @@ -482,9 +482,7 @@ func (desc *wrapper) IndexKeyColumns(idx catalog.Index) []catalog.Column { } // IndexKeyColumnDirections implements the TableDescriptor interface. -func (desc *wrapper) IndexKeyColumnDirections( - idx catalog.Index, -) []descpb.IndexDescriptor_Direction { +func (desc *wrapper) IndexKeyColumnDirections(idx catalog.Index) []catpb.IndexColumn_Direction { if ic := desc.getExistingOrNewIndexColumnCache(idx); ic != nil { return ic.keyDirs } @@ -508,9 +506,7 @@ func (desc *wrapper) IndexFullColumns(idx catalog.Index) []catalog.Column { } // IndexFullColumnDirections implements the TableDescriptor interface. -func (desc *wrapper) IndexFullColumnDirections( - idx catalog.Index, -) []descpb.IndexDescriptor_Direction { +func (desc *wrapper) IndexFullColumnDirections(idx catalog.Index) []catpb.IndexColumn_Direction { if ic := desc.getExistingOrNewIndexColumnCache(idx); ic != nil { return ic.fullDirs } diff --git a/pkg/sql/catalog/tabledesc/validate.go b/pkg/sql/catalog/tabledesc/validate.go index 4a856e53bd70..158cd49286d0 100644 --- a/pkg/sql/catalog/tabledesc/validate.go +++ b/pkg/sql/catalog/tabledesc/validate.go @@ -216,7 +216,7 @@ func (desc *wrapper) ValidateCrossReferences( for i := 0; i < pk.NumKeyColumns(); i++ { dir := pk.GetKeyColumnDirection(i) - if dir != descpb.IndexDescriptor_ASC { + if dir != catpb.IndexColumn_ASC { vea.Report(unimplemented.NewWithIssuef( 76912, `non-ascending ordering on PRIMARY KEYs are not supported`, diff --git a/pkg/sql/catalog/tabledesc/validate_test.go b/pkg/sql/catalog/tabledesc/validate_test.go index d17f85e9927a..3e64ca360076 100644 --- a/pkg/sql/catalog/tabledesc/validate_test.go +++ b/pkg/sql/catalog/tabledesc/validate_test.go @@ -648,7 +648,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 0, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, NextColumnID: 2, NextFamilyID: 1, }}, @@ -666,7 +666,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 0, Name: "bar", KeyColumnIDs: []descpb.ColumnID{0}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, NextColumnID: 2, NextFamilyID: 1, }}, @@ -684,7 +684,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, @@ -727,7 +727,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "bar", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar", "blah"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, NextColumnID: 3, NextFamilyID: 1, @@ -747,14 +747,14 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "bar", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "bar", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, }, NextColumnID: 2, @@ -775,14 +775,14 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "bar", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, Indexes: []descpb.IndexDescriptor{ {ID: 1, Name: "blah", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, }, NextColumnID: 2, @@ -803,7 +803,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "bar", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, NextColumnID: 2, NextFamilyID: 1, @@ -823,7 +823,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "bar", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"blah"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, }, NextColumnID: 2, NextFamilyID: 1, @@ -870,7 +870,7 @@ func TestValidateTableDesc(t *testing.T) { ID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnIDs: []descpb.ColumnID{2}, }, NextColumnID: 3, @@ -895,7 +895,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, @@ -904,7 +904,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "secondary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnIDs: []descpb.ColumnID{123}, StoreColumnNames: []string{"quux"}, }}, @@ -934,7 +934,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, @@ -943,7 +943,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "secondary", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"baz"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1}, StoreColumnIDs: []descpb.ColumnID{2}, StoreColumnNames: []string{"quux"}, @@ -970,7 +970,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, @@ -979,7 +979,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "secondary", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"baz"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{123}, }}, NextColumnID: 3, @@ -1000,7 +1000,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, ForeignKey: descpb.ForeignKeyReference{Table: 123, Index: 456}, @@ -1027,7 +1027,7 @@ func TestValidateTableDesc(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, }, @@ -1059,7 +1059,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnNames: []string{"crdb_internal_bar_shard_5"}, StoreColumnIDs: []descpb.ColumnID{2}, EncodingType: descpb.PrimaryIndexEncoding, @@ -1069,7 +1069,7 @@ func TestValidateTableDesc(t *testing.T) { {ID: 2, Name: "foo_crdb_internal_bar_shard_5_bar_idx", KeyColumnIDs: []descpb.ColumnID{2, 1}, KeyColumnNames: []string{"crdb_internal_bar_shard_5", "bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Sharded: catpb.ShardedDescriptor{ IsSharded: true, Name: "does not exist", @@ -1175,7 +1175,7 @@ func TestValidateTableDesc(t *testing.T) { NextFamilyID: 1, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, ConstraintID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, UniqueWithoutIndexConstraints: []descpb.UniqueWithoutIndexConstraint{ { TableID: 2, @@ -1200,7 +1200,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, ConstraintID: 1, @@ -1208,7 +1208,7 @@ func TestValidateTableDesc(t *testing.T) { Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{3}, }, }, @@ -1240,7 +1240,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, ConstraintID: 1, @@ -1248,7 +1248,7 @@ func TestValidateTableDesc(t *testing.T) { Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{}, }, }, @@ -1267,7 +1267,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{3}, KeyColumnNames: []string{"c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, ConstraintID: 1, @@ -1281,7 +1281,7 @@ func TestValidateTableDesc(t *testing.T) { Index: &descpb.IndexDescriptor{ ID: 4, Name: "new_sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{3}, }, }, @@ -1324,14 +1324,14 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{3}, }, }, @@ -1350,7 +1350,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{3}, KeyColumnNames: []string{"c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, @@ -1363,7 +1363,7 @@ func TestValidateTableDesc(t *testing.T) { Index: &descpb.IndexDescriptor{ ID: 4, Name: "new_sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{3}, }, }, @@ -1405,14 +1405,14 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1, 3}, KeyColumnNames: []string{"c1", "c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1, 3}, }, }, @@ -1431,7 +1431,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, @@ -1444,7 +1444,7 @@ func TestValidateTableDesc(t *testing.T) { Index: &descpb.IndexDescriptor{ ID: 4, Name: "new_sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1, 3}, }, }, @@ -1486,14 +1486,14 @@ func TestValidateTableDesc(t *testing.T) { PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "pri", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnNames: []string{"v"}, StoreColumnIDs: []descpb.ColumnID{3}, }, @@ -1518,14 +1518,14 @@ func TestValidateTableDesc(t *testing.T) { PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "pri", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.LatestIndexDescriptorVersion, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnNames: []string{"c2"}, StoreColumnIDs: []descpb.ColumnID{2}, Version: descpb.LatestIndexDescriptorVersion, @@ -1796,7 +1796,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, @@ -1806,7 +1806,7 @@ func TestValidateTableDesc(t *testing.T) { Name: "ruroh", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, UseDeletePreservingEncoding: true, }, @@ -1834,7 +1834,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, UseDeletePreservingEncoding: true, @@ -1930,7 +1930,7 @@ func TestValidateTableDesc(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"a"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.PrimaryIndexWithStoredColumnsVersion, EncodingType: descpb.PrimaryIndexEncoding, ConstraintID: 1, @@ -2015,14 +2015,14 @@ func TestPrimaryKeyCannotBeVirtualBefore22_1(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1, 3}, KeyColumnNames: []string{"c1", "c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1, 3}, }, }, @@ -2057,14 +2057,14 @@ func TestPrimaryKeyCannotBeVirtualBefore22_1(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"c1"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, Indexes: []descpb.IndexDescriptor{ {ID: 2, Name: "sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1, 3}, }, }, @@ -2083,7 +2083,7 @@ func TestPrimaryKeyCannotBeVirtualBefore22_1(t *testing.T) { Unique: true, KeyColumnIDs: []descpb.ColumnID{1, 3}, KeyColumnNames: []string{"c1", "c3"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, }, @@ -2096,7 +2096,7 @@ func TestPrimaryKeyCannotBeVirtualBefore22_1(t *testing.T) { Index: &descpb.IndexDescriptor{ ID: 4, Name: "new_sec", KeyColumnIDs: []descpb.ColumnID{2}, KeyColumnNames: []string{"c2"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeySuffixColumnIDs: []descpb.ColumnID{1, 3}, }, }, @@ -2589,7 +2589,7 @@ func TestValidatePartitioning(t *testing.T) { descpb.TableDescriptor{ PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{{}}, @@ -2603,7 +2603,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{{}}, @@ -2616,7 +2616,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{{Name: "p1"}}, @@ -2629,7 +2629,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{{ @@ -2644,7 +2644,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{ @@ -2659,7 +2659,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{ @@ -2674,7 +2674,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1, 1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, Range: []catpb.PartitioningDescriptor_Range{ @@ -2690,7 +2690,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{ @@ -2706,7 +2706,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{{ @@ -2726,7 +2726,7 @@ func TestValidatePartitioning(t *testing.T) { Columns: []descpb.ColumnDescriptor{{ID: 1, Type: types.Int}}, PrimaryIndex: descpb.IndexDescriptor{ KeyColumnIDs: []descpb.ColumnID{1, 1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, Partitioning: catpb.PartitioningDescriptor{ NumColumns: 1, List: []catpb.PartitioningDescriptor_List{ @@ -2779,7 +2779,7 @@ func TestValidateConstraintID(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, NextColumnID: 2, NextFamilyID: 1, Privileges: catpb.NewPrivilegeDescriptor( @@ -2802,11 +2802,11 @@ func TestValidateConstraintID(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, ConstraintID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, Indexes: []descpb.IndexDescriptor{ { ID: 2, Name: "secondary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Unique: true, }, }, @@ -2832,7 +2832,7 @@ func TestValidateConstraintID(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, ConstraintID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, UniqueWithoutIndexConstraints: []descpb.UniqueWithoutIndexConstraint{ {Name: "bad"}, }, @@ -2858,7 +2858,7 @@ func TestValidateConstraintID(t *testing.T) { }, PrimaryIndex: descpb.IndexDescriptor{ ID: 1, ConstraintID: 1, Name: "primary", KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"bar"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}}, Checks: []*descpb.TableDescriptor_CheckConstraint{ {Name: "bad"}, }, diff --git a/pkg/sql/colencoding/BUILD.bazel b/pkg/sql/colencoding/BUILD.bazel index bce27f797eaa..89659cab33b3 100644 --- a/pkg/sql/colencoding/BUILD.bazel +++ b/pkg/sql/colencoding/BUILD.bazel @@ -11,6 +11,7 @@ go_library( deps = [ "//pkg/col/coldata", "//pkg/roachpb", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/rowenc/keyside", "//pkg/sql/rowenc/valueside", diff --git a/pkg/sql/colencoding/key_encoding.go b/pkg/sql/colencoding/key_encoding.go index 2e794231b7e2..6eb1a10418aa 100644 --- a/pkg/sql/colencoding/key_encoding.go +++ b/pkg/sql/colencoding/key_encoding.go @@ -16,6 +16,7 @@ import ( "github.com/cockroachdb/apd/v3" "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/roachpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/rowenc/keyside" "github.com/cockroachdb/cockroach/pkg/sql/rowenc/valueside" @@ -94,10 +95,10 @@ func decodeTableKeyToCol( rowIdx int, valType *types.T, key []byte, - dir descpb.IndexDescriptor_Direction, + dir catpb.IndexColumn_Direction, scratch []byte, ) (_ []byte, _ bool, retScratch []byte, _ error) { - if (dir != descpb.IndexDescriptor_ASC) && (dir != descpb.IndexDescriptor_DESC) { + if (dir != catpb.IndexColumn_ASC) && (dir != catpb.IndexColumn_DESC) { return nil, false, scratch, errors.AssertionFailedf("invalid direction: %d", redact.Safe(dir)) } var isNull bool @@ -115,7 +116,7 @@ func decodeTableKeyToCol( switch valType.Family() { case types.BoolFamily: var i int64 - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, i, err = encoding.DecodeVarintAscending(key) } else { rkey, i, err = encoding.DecodeVarintDescending(key) @@ -123,7 +124,7 @@ func decodeTableKeyToCol( vecs.BoolCols[colIdx][rowIdx] = i != 0 case types.IntFamily, types.DateFamily: var i int64 - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, i, err = encoding.DecodeVarintAscending(key) } else { rkey, i, err = encoding.DecodeVarintDescending(key) @@ -138,7 +139,7 @@ func decodeTableKeyToCol( } case types.FloatFamily: var f float64 - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, f, err = encoding.DecodeFloatAscending(key) } else { rkey, f, err = encoding.DecodeFloatDescending(key) @@ -146,14 +147,14 @@ func decodeTableKeyToCol( vecs.Float64Cols[colIdx][rowIdx] = f case types.DecimalFamily: var d apd.Decimal - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, d, err = encoding.DecodeDecimalAscending(key, scratch[:0]) } else { rkey, d, err = encoding.DecodeDecimalDescending(key, scratch[:0]) } vecs.DecimalCols[colIdx][rowIdx] = d case types.BytesFamily, types.StringFamily, types.UuidFamily: - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { // We ask for the deep copy to be made so that scratch doesn't // reference the memory of key - this allows us to return scratch // to the caller to be reused. The deep copy additionally ensures @@ -169,7 +170,7 @@ func decodeTableKeyToCol( vecs.BytesCols[colIdx].Set(rowIdx, scratch) case types.TimestampFamily, types.TimestampTZFamily: var t time.Time - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, t, err = encoding.DecodeTimeAscending(key) } else { rkey, t, err = encoding.DecodeTimeDescending(key) @@ -177,7 +178,7 @@ func decodeTableKeyToCol( vecs.TimestampCols[colIdx][rowIdx] = t case types.IntervalFamily: var d duration.Duration - if dir == descpb.IndexDescriptor_ASC { + if dir == catpb.IndexColumn_ASC { rkey, d, err = encoding.DecodeDurationAscending(key) } else { rkey, d, err = encoding.DecodeDurationDescending(key) @@ -201,7 +202,7 @@ func decodeTableKeyToCol( default: var d tree.Datum encDir := encoding.Ascending - if dir == descpb.IndexDescriptor_DESC { + if dir == catpb.IndexColumn_DESC { encDir = encoding.Descending } d, rkey, err = keyside.Decode(da, valType, key, encDir) diff --git a/pkg/sql/colexec/colexecspan/BUILD.bazel b/pkg/sql/colexec/colexecspan/BUILD.bazel index b825e70a76d4..b1415cd2e335 100644 --- a/pkg/sql/colexec/colexecspan/BUILD.bazel +++ b/pkg/sql/colexec/colexecspan/BUILD.bazel @@ -17,6 +17,7 @@ go_library( "//pkg/keys", # keep "//pkg/roachpb", # keep "//pkg/sql/catalog", # keep + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", # keep "//pkg/sql/colexecerror", # keep "//pkg/sql/colmem", # keep diff --git a/pkg/sql/colexec/colexecspan/span_assembler.go b/pkg/sql/colexec/colexecspan/span_assembler.go index ff48f00c723c..b6da7ee51e48 100644 --- a/pkg/sql/colexec/colexecspan/span_assembler.go +++ b/pkg/sql/colexec/colexecspan/span_assembler.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/colexecerror" "github.com/cockroachdb/cockroach/pkg/sql/colmem" @@ -58,7 +59,7 @@ func NewColSpanAssembler( // ColSpanAssembler will later append these together to form valid spans. keyColumns := fetchSpec.KeyColumns() for i := range keyColumns { - asc := keyColumns[i].Direction == descpb.IndexDescriptor_ASC + asc := keyColumns[i].Direction == catpb.IndexColumn_ASC sa.spanEncoders = append(sa.spanEncoders, newSpanEncoder(allocator, inputTypes[i], asc, i)) } if cap(sa.spanCols) < len(sa.spanEncoders) { diff --git a/pkg/sql/colexec/colexecspan/span_assembler_test.go b/pkg/sql/colexec/colexecspan/span_assembler_test.go index cc12f364a216..7911ea64ed91 100644 --- a/pkg/sql/colexec/colexecspan/span_assembler_test.go +++ b/pkg/sql/colexec/colexecspan/span_assembler_test.go @@ -241,7 +241,7 @@ func makeTable(useColFamilies bool) (catalog.TableDescriptor, error) { ID: 1, Unique: true, KeyColumnNames: []string{"a", "b", "c"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2, 3}, }, Indexes: []descpb.IndexDescriptor{ @@ -250,7 +250,7 @@ func makeTable(useColFamilies bool) (catalog.TableDescriptor, error) { ID: 2, Unique: true, KeyColumnNames: []string{"c", "a", "b"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{3, 1, 2}, KeySuffixColumnIDs: []descpb.ColumnID{1, 2}, }, diff --git a/pkg/sql/constraint.go b/pkg/sql/constraint.go index 4f9d0a7f5192..386b9f312763 100644 --- a/pkg/sql/constraint.go +++ b/pkg/sql/constraint.go @@ -15,7 +15,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/opt" "github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder" "github.com/cockroachdb/cockroach/pkg/sql/opt/idxconstraint" @@ -111,7 +111,7 @@ func (p *planner) ConstrainPrimaryIndexSpanByExpr( indexCols := make([]opt.OrderingColumn, len(primary.IndexDesc().KeyColumnIDs)) var notNullIndexCols opt.ColSet for i, colID := range primary.IndexDesc().KeyColumnIDs { - if primary.GetKeyColumnDirection(i) == descpb.IndexDescriptor_ASC { + if primary.GetKeyColumnDirection(i) == catpb.IndexColumn_ASC { indexCols[i] = opt.OrderingColumn(colID) } else { indexCols[i] = opt.OrderingColumn(-colID) diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index 596fda95741b..b8dc49773561 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -2847,9 +2847,9 @@ CREATE TABLE crdb_internal.index_columns ( storing := tree.NewDString("storing") extra := tree.NewDString("extra") composite := tree.NewDString("composite") - idxDirMap := map[descpb.IndexDescriptor_Direction]tree.Datum{ - descpb.IndexDescriptor_ASC: tree.NewDString(descpb.IndexDescriptor_ASC.String()), - descpb.IndexDescriptor_DESC: tree.NewDString(descpb.IndexDescriptor_DESC.String()), + idxDirMap := map[catpb.IndexColumn_Direction]tree.Datum{ + catpb.IndexColumn_ASC: tree.NewDString(catpb.IndexColumn_ASC.String()), + catpb.IndexColumn_DESC: tree.NewDString(catpb.IndexColumn_DESC.String()), } return forEachTableDescAll(ctx, p, dbContext, hideVirtual, diff --git a/pkg/sql/create_sequence.go b/pkg/sql/create_sequence.go index 50c4c61274be..8db6f5f27cd6 100644 --- a/pkg/sql/create_sequence.go +++ b/pkg/sql/create_sequence.go @@ -293,7 +293,7 @@ func NewSequenceTableDesc( Name: tabledesc.LegacyPrimaryKeyIndexName, KeyColumnIDs: []descpb.ColumnID{tabledesc.SequenceColumnID}, KeyColumnNames: []string{tabledesc.SequenceColumnName}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, CreatedAtNanos: creationTime.WallTime, diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index 9db298b7b341..c870461c6622 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -2657,7 +2657,7 @@ func replaceLikeTableOpts(n *tree.CreateTable, params runParams) (tree.TableDefs return nil, err } } - if idx.GetKeyColumnDirection(j) == descpb.IndexDescriptor_DESC { + if idx.GetKeyColumnDirection(j) == catpb.IndexColumn_DESC { elem.Direction = tree.Descending } indexDef.Columns = append(indexDef.Columns, elem) diff --git a/pkg/sql/doctor/doctor_test.go b/pkg/sql/doctor/doctor_test.go index d539f1b24d3c..d74190f6b891 100644 --- a/pkg/sql/doctor/doctor_test.go +++ b/pkg/sql/doctor/doctor_test.go @@ -54,7 +54,7 @@ var validTableDesc = &descpb.Descriptor{ ID: 1, Unique: true, KeyColumnNames: []string{"col"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1}, Version: descpb.LatestIndexDescriptorVersion, EncodingType: descpb.PrimaryIndexEncoding, diff --git a/pkg/sql/execinfrapb/BUILD.bazel b/pkg/sql/execinfrapb/BUILD.bazel index 7717c63925e5..6e2f5a63109a 100644 --- a/pkg/sql/execinfrapb/BUILD.bazel +++ b/pkg/sql/execinfrapb/BUILD.bazel @@ -26,6 +26,7 @@ go_library( "//pkg/settings/cluster", "//pkg/sql/catalog", "//pkg/sql/catalog/catalogkeys", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/typedesc", diff --git a/pkg/sql/execinfrapb/flow_diagram.go b/pkg/sql/execinfrapb/flow_diagram.go index 2678e3564f22..ca38554bac2d 100644 --- a/pkg/sql/execinfrapb/flow_diagram.go +++ b/pkg/sql/execinfrapb/flow_diagram.go @@ -22,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/util/encoding" "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb" @@ -164,7 +165,7 @@ func (tr *TableReaderSpec) summary() (string, []string) { keyDirs := make([]encoding.Direction, len(tr.FetchSpec.KeyAndSuffixColumns)) for i := range keyDirs { keyDirs[i] = encoding.Ascending - if tr.FetchSpec.KeyAndSuffixColumns[i].Direction == descpb.IndexDescriptor_DESC { + if tr.FetchSpec.KeyAndSuffixColumns[i].Direction == catpb.IndexColumn_DESC { keyDirs[i] = encoding.Descending } } diff --git a/pkg/sql/indexbackfiller_test.go b/pkg/sql/indexbackfiller_test.go index 3aaab0595104..e5febb3a01d2 100644 --- a/pkg/sql/indexbackfiller_test.go +++ b/pkg/sql/indexbackfiller_test.go @@ -28,6 +28,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/backfill" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/lease" @@ -254,8 +255,8 @@ INSERT INTO foo VALUES (1, 2), (2, 3), (3, 4); KeyColumnNames: []string{ mut.Columns[2].Name, }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{ mut.Columns[2].ID, @@ -334,8 +335,8 @@ INSERT INTO foo VALUES (1), (10), (100); KeyColumnNames: []string{ mut.Columns[0].Name, }, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, StoreColumnNames: []string{ columnWithDefault.Name, diff --git a/pkg/sql/information_schema.go b/pkg/sql/information_schema.go index 891d1d74d0c7..bcc532a71381 100644 --- a/pkg/sql/information_schema.go +++ b/pkg/sql/information_schema.go @@ -1068,15 +1068,15 @@ var informationSchemaSchemataTablePrivileges = virtualSchemaTable{ var ( indexDirectionNA = tree.NewDString("N/A") - indexDirectionAsc = tree.NewDString(descpb.IndexDescriptor_ASC.String()) - indexDirectionDesc = tree.NewDString(descpb.IndexDescriptor_DESC.String()) + indexDirectionAsc = tree.NewDString(catpb.IndexColumn_ASC.String()) + indexDirectionDesc = tree.NewDString(catpb.IndexColumn_DESC.String()) ) -func dStringForIndexDirection(dir descpb.IndexDescriptor_Direction) tree.Datum { +func dStringForIndexDirection(dir catpb.IndexColumn_Direction) tree.Datum { switch dir { - case descpb.IndexDescriptor_ASC: + case catpb.IndexColumn_ASC: return indexDirectionAsc - case descpb.IndexDescriptor_DESC: + case catpb.IndexColumn_DESC: return indexDirectionDesc } panic("unreachable") 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/opt/exec/execbuilder/testdata/show_trace b/pkg/sql/opt/exec/execbuilder/testdata/show_trace index 467e824e2087..4fa93b9abf31 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/show_trace +++ b/pkg/sql/opt/exec/execbuilder/testdata/show_trace @@ -166,7 +166,7 @@ $trace_query batch flow coordinator Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > batch flow coordinator Del /NamespaceTable/30/1/106/107/"kv2"/4/1 sql query rows affected: 0 -commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > +commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 target_ranks:25 target_ranks:26 target_ranks:27 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > statement ok SET tracing = on,kv,results; DELETE FROM t.kv @@ -208,7 +208,7 @@ $trace_query batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > batch flow coordinator Del /NamespaceTable/30/1/106/107/"kv"/4/1 sql query rows affected: 0 -commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > +commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > # Check that session tracing does not inhibit the fast path for inserts & # friends (the path resulting in 1PC transactions). diff --git a/pkg/sql/opt_catalog.go b/pkg/sql/opt_catalog.go index a76e8ce6385d..b310252182d6 100644 --- a/pkg/sql/opt_catalog.go +++ b/pkg/sql/opt_catalog.go @@ -1476,7 +1476,7 @@ func (oi *optIndex) NonInvertedPrefixColumnCount() int { func (oi *optIndex) Column(i int) cat.IndexColumn { ord := oi.columnOrds[i] // Only key columns have a direction. - descending := i < oi.idx.NumKeyColumns() && oi.idx.GetKeyColumnDirection(i) == descpb.IndexDescriptor_DESC + descending := i < oi.idx.NumKeyColumns() && oi.idx.GetKeyColumnDirection(i) == catpb.IndexColumn_DESC return cat.IndexColumn{ Column: oi.tab.Column(ord), Descending: descending, diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 4f7534dff6d6..b54983178f7c 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -1851,7 +1851,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-index.html`, // Currently, nulls always appear first if the order is ascending, // and always appear last if the order is descending. var thisIndOption tree.DInt - if index.GetKeyColumnDirection(i) == descpb.IndexDescriptor_ASC { + if index.GetKeyColumnDirection(i) == catpb.IndexColumn_ASC { thisIndOption = indoptionNullsFirst } else { thisIndOption = indoptionDesc diff --git a/pkg/sql/protoreflect/BUILD.bazel b/pkg/sql/protoreflect/BUILD.bazel index 63fd190901b6..efdfc052b696 100644 --- a/pkg/sql/protoreflect/BUILD.bazel +++ b/pkg/sql/protoreflect/BUILD.bazel @@ -29,6 +29,7 @@ go_test( "//pkg/geo/geoindex", "//pkg/security/securityassets", "//pkg/security/securitytest", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/protoreflect/test", "//pkg/sql/types", diff --git a/pkg/sql/protoreflect/utils_test.go b/pkg/sql/protoreflect/utils_test.go index c5f2456fde55..cf53bdbc3d98 100644 --- a/pkg/sql/protoreflect/utils_test.go +++ b/pkg/sql/protoreflect/utils_test.go @@ -17,6 +17,7 @@ import ( "testing" "github.com/cockroachdb/cockroach/pkg/geo/geoindex" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/protoreflect" protoreflecttest "github.com/cockroachdb/cockroach/pkg/sql/protoreflect/test" @@ -68,7 +69,7 @@ func TestMessageToJSONBRoundTrip(t *testing.T) { ID: 500, Unique: true, KeyColumnNames: []string{"foo", "bar", "buz"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, GeoConfig: geoindex.Config{ S2Geography: &geoindex.S2GeographyConfig{S2Config: &geoindex.S2Config{ MinLevel: 123, diff --git a/pkg/sql/rowenc/BUILD.bazel b/pkg/sql/rowenc/BUILD.bazel index 0e006b40d8ab..07d00c4eeb30 100644 --- a/pkg/sql/rowenc/BUILD.bazel +++ b/pkg/sql/rowenc/BUILD.bazel @@ -17,6 +17,8 @@ go_library( "//pkg/keys", "//pkg/roachpb", "//pkg/sql/catalog", + "//pkg/sql/catalog/catalogkeys", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/descpb", "//pkg/sql/inverted", @@ -63,6 +65,7 @@ go_test( "//pkg/server", "//pkg/settings/cluster", "//pkg/sql/catalog", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/desctestutils", diff --git a/pkg/sql/rowenc/index_encoding.go b/pkg/sql/rowenc/index_encoding.go index 9831bddb62ca..4fefad75c8a7 100644 --- a/pkg/sql/rowenc/index_encoding.go +++ b/pkg/sql/rowenc/index_encoding.go @@ -20,6 +20,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/inverted" "github.com/cockroachdb/cockroach/pkg/sql/rowenc/keyside" @@ -115,7 +117,7 @@ func EncodePartialIndexKey( containsNull = true } - dir, err := keyCol.Direction.ToEncodingDirection() + dir, err := catalogkeys.IndexColumnEncodingDirection(keyCol.Direction) if err != nil { return nil, false, err } @@ -127,11 +129,11 @@ func EncodePartialIndexKey( return key, containsNull, nil } -type directions []descpb.IndexDescriptor_Direction +type directions []catpb.IndexColumn_Direction func (d directions) get(i int) (encoding.Direction, error) { if i < len(d) { - return d[i].ToEncodingDirection() + return catalogkeys.IndexColumnEncodingDirection(d[i]) } return encoding.Ascending, nil } @@ -343,7 +345,7 @@ func MakeKeyFromEncDatums( for i, val := range values { encoding := descpb.DatumEncoding_ASCENDING_KEY - if keyCols[i].Direction == descpb.IndexDescriptor_DESC { + if keyCols[i].Direction == catpb.IndexColumn_DESC { encoding = descpb.DatumEncoding_DESCENDING_KEY } if val.IsNull() { @@ -412,7 +414,7 @@ func DecodeIndexKey( codec keys.SQLCodec, types []*types.T, vals []EncDatum, - colDirs []descpb.IndexDescriptor_Direction, + colDirs []catpb.IndexColumn_Direction, key []byte, ) (remainingKey []byte, foundNull bool, _ error) { key, err := codec.StripTenantPrefix(key) @@ -435,7 +437,7 @@ func DecodeIndexKey( // used will default to encoding.Ascending. // DecodeKeyVals returns whether or not NULL was encountered in the key. func DecodeKeyVals( - types []*types.T, vals []EncDatum, directions []descpb.IndexDescriptor_Direction, key []byte, + types []*types.T, vals []EncDatum, directions []catpb.IndexColumn_Direction, key []byte, ) (remainingKey []byte, foundNull bool, _ error) { if directions != nil && len(directions) != len(vals) { return nil, false, errors.Errorf("encoding directions doesn't parallel vals: %d vs %d.", @@ -443,7 +445,7 @@ func DecodeKeyVals( } for j := range vals { enc := descpb.DatumEncoding_ASCENDING_KEY - if directions != nil && (directions[j] == descpb.IndexDescriptor_DESC) { + if directions != nil && (directions[j] == catpb.IndexColumn_DESC) { enc = descpb.DatumEncoding_DESCENDING_KEY } var err error @@ -464,7 +466,7 @@ func DecodeKeyValsUsingSpec( for j := range vals { c := keyCols[j] enc := descpb.DatumEncoding_ASCENDING_KEY - if c.Direction == descpb.IndexDescriptor_DESC { + if c.Direction == catpb.IndexColumn_DESC { enc = descpb.DatumEncoding_DESCENDING_KEY } var err error diff --git a/pkg/sql/rowenc/index_encoding_test.go b/pkg/sql/rowenc/index_encoding_test.go index fdf6527c9eea..9f1d5cfadeee 100644 --- a/pkg/sql/rowenc/index_encoding_test.go +++ b/pkg/sql/rowenc/index_encoding_test.go @@ -22,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -73,14 +74,14 @@ func makeTableDescForTest(test indexKeyTest) (catalog.TableDescriptor, catalog.T PrimaryIndex: descpb.IndexDescriptor{ ID: 1, KeyColumnIDs: primaryColumnIDs, - KeyColumnDirections: make([]descpb.IndexDescriptor_Direction, len(primaryColumnIDs)), + KeyColumnDirections: make([]catpb.IndexColumn_Direction, len(primaryColumnIDs)), }, Indexes: []descpb.IndexDescriptor{{ ID: 2, KeyColumnIDs: secondaryColumnIDs, KeySuffixColumnIDs: primaryColumnIDs, Unique: true, - KeyColumnDirections: make([]descpb.IndexDescriptor_Direction, len(secondaryColumnIDs)), + KeyColumnDirections: make([]catpb.IndexColumn_Direction, len(secondaryColumnIDs)), Type: secondaryType, }}, } @@ -679,10 +680,10 @@ func ExtractIndexKey( return nil, err } extraValues := make([]EncDatum, index.NumKeySuffixColumns()) - dirs = make([]descpb.IndexDescriptor_Direction, index.NumKeySuffixColumns()) + dirs = make([]catpb.IndexColumn_Direction, index.NumKeySuffixColumns()) for i := 0; i < index.NumKeySuffixColumns(); i++ { // Implicit columns are always encoded Ascending. - dirs[i] = descpb.IndexDescriptor_ASC + dirs[i] = catpb.IndexColumn_ASC } extraKey := key if index.IsUnique() { 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/rel/internal/entitynodetest/tests.go b/pkg/sql/schemachanger/rel/internal/entitynodetest/tests.go index c78ed0bb3268..d9d615c2706b 100644 --- a/pkg/sql/schemachanger/rel/internal/entitynodetest/tests.go +++ b/pkg/sql/schemachanger/rel/internal/entitynodetest/tests.go @@ -537,6 +537,81 @@ var ( }, UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6}, }, + { + Name: "e[i8] != 1", + Query: rel.Clauses{ + v("e").Type((*entity)(nil)), + v("e").AttrNeq(i8, int8(1)), + }, + Entities: []rel.Var{"e"}, + ResVars: []v{"e"}, + Results: [][]interface{}{ + {b}, + {c}, + }, + UnsatisfiableIndexes: []int{1, 2, 3, 5, 6}, + }, + { + Name: "e != a", + Query: rel.Clauses{ + v("e").Type((*entity)(nil)), + v("e").Neq(a), + }, + Entities: []rel.Var{"e"}, + ResVars: []v{"e"}, + Results: [][]interface{}{ + {b}, + {c}, + }, + UnsatisfiableIndexes: []int{1, 2, 3, 5, 6}, + }, + { + Name: "e[i8] = v; v != 1", + Query: rel.Clauses{ + v("e").Type((*entity)(nil)), + v("e").AttrEqVar(i8, "v"), + v("v").Neq(int8(1)), + }, + Entities: []rel.Var{"e"}, + ResVars: []v{"e", "v"}, + Results: [][]interface{}{ + {b, int8(2)}, + {c, int8(2)}, + }, + UnsatisfiableIndexes: []int{1, 2, 3, 5, 6}, + }, + { + Name: "e[i8] = v; v != 2", + Query: rel.Clauses{ + v("e").Type((*entity)(nil)), + v("e").AttrEqVar(i8, "v"), + v("v").Neq(int8(2)), + }, + Entities: []rel.Var{"e"}, + ResVars: []v{"e", "v"}, + Results: [][]interface{}{ + {a, int8(1)}, + }, + UnsatisfiableIndexes: []int{1, 2, 3, 5, 6}, + }, + { + // This case flexes the semantics of Neq to note that Neq forces + // the variable to bind to the same type as the value. In an ideal + // world this would give you a type error. + // + // TODO(ajwerner): Make type checking more strict such that this + // leads to an error. + Name: "e[i8] = v; v != int16(2)", + Query: rel.Clauses{ + v("e").Type((*entity)(nil)), + v("e").AttrEqVar(i8, "v"), + v("v").Neq(int16(2)), + }, + Entities: []rel.Var{"e"}, + ResVars: []v{"e", "v"}, + Results: [][]interface{}{}, + UnsatisfiableIndexes: []int{1, 2, 3, 5, 6}, + }, }, }, } diff --git a/pkg/sql/schemachanger/rel/query_build.go b/pkg/sql/schemachanger/rel/query_build.go index 5d8e80ab3477..c975f5d5542d 100644 --- a/pkg/sql/schemachanger/rel/query_build.go +++ b/pkg/sql/schemachanger/rel/query_build.go @@ -217,6 +217,12 @@ func (p *queryBuilder) processValueExpr(rawValue expr) slotIdx { panic(err) } return p.fillSlot(slot{typedValue: tv}, false) + case notValueExpr: + tv, err := makeComparableValue(v.value) + if err != nil { + panic(err) + } + return p.fillSlot(slot{not: tv}, false) default: panic(errors.AssertionFailedf("unknown expr type %T", rawValue)) } diff --git a/pkg/sql/schemachanger/rel/query_data.go b/pkg/sql/schemachanger/rel/query_data.go index 79072ee9799b..de11fb6b6982 100644 --- a/pkg/sql/schemachanger/rel/query_data.go +++ b/pkg/sql/schemachanger/rel/query_data.go @@ -37,6 +37,11 @@ type slot struct { // equality filters and then variables used in attributes which require // types. any []typedValue + + // not holds a value which this slot must not be equal to. Additionally, + // the value which fills this slot must have the same type as the value + // in the not container. + not typedValue } // typedValue is a value in its comparable form, which is to say, it is a @@ -106,6 +111,19 @@ func maybeSet( slots []slot, idx slotIdx, tv typedValue, set *util.FastIntSet, ) (foundContradiction bool) { s := &slots[idx] + + eqNotNil := func(a, b interface{}) bool { + _, eq := compareNotNil(a, b) + return eq + } + findMatchInAny := func(haystack []typedValue) bool { + for _, v := range s.any { + if tv.typ == v.typ && eqNotNil(v.value, tv.value) { + return true + } + } + return false + } check := func() (shouldSet, foundContradiction bool) { if !s.empty() { if _, eq := compareNotNil(s.value, tv.value); !eq { @@ -113,21 +131,14 @@ func maybeSet( } return false, false } - - if s.any != nil { - var foundMatch bool - for _, v := range s.any { - if tv.typ != v.typ { - continue - } - if _, foundMatch = compareNotNil(v.value, tv.value); foundMatch { - break - } - } - if !foundMatch { - return false, true // contradiction + if s.not.typ != nil { + if tv.typ != s.not.typ || eqNotNil(s.not.value, tv.value) { + return false, true } } + if s.any != nil && !findMatchInAny(s.any) { + return false, true // contradiction + } return true, false } shouldSet, contradiction := check() diff --git a/pkg/sql/schemachanger/rel/query_eval.go b/pkg/sql/schemachanger/rel/query_eval.go index 90f68959df2e..bbf9f02b3394 100644 --- a/pkg/sql/schemachanger/rel/query_eval.go +++ b/pkg/sql/schemachanger/rel/query_eval.go @@ -24,8 +24,13 @@ type evalContext struct { db *Database ri ResultIterator - facts []fact - depth, cur int + facts []fact + + // depth and cur relate to the join depth in the entities list. + depth, cur int + + // numIterateCalls is the number of calls to iterate which have occurred. + slots []slot filterSliceCaches map[int][]reflect.Value } diff --git a/pkg/sql/schemachanger/rel/query_lang.go b/pkg/sql/schemachanger/rel/query_lang.go index e5492e9572c0..a494e795995b 100644 --- a/pkg/sql/schemachanger/rel/query_lang.go +++ b/pkg/sql/schemachanger/rel/query_lang.go @@ -37,6 +37,15 @@ func (v Var) AttrEq(a Attr, value interface{}) Clause { return makeTriple(v, a, valueExpr{value: value}) } +// AttrNeq constrains the entity bound to v to not have the provided value for +// the specified attr. Note that, perhaps surprisingly, if the entity's +// attribute takes on a value of a different type than the passed value, a +// contradiction will be found; the entity's attribute must be bound, and it +// must be bound to a value of the same type as the provided value. +func (v Var) AttrNeq(a Attr, value interface{}) Clause { + return makeTriple(v, a, notValueExpr{value: value}) +} + // AttrIn constrains the entity bound to v to have a value for // the specified attr in the set of provided values. func (v Var) AttrIn(a Attr, values ...interface{}) Clause { @@ -59,6 +68,15 @@ func (v Var) In(disjuncts ...interface{}) Clause { return eqDecl{v, (anyExpr)(disjuncts)} } +// Neq returns a clause enforcing that the var is not equal to the value +// provided. Note that, perhaps surprisingly, if the variable takes on a +// value of a different type than the passed value, it will be deemed a +// contradiction; the variable must be bound, and it must be bound +// to a value of the same type as the provided value. +func (v Var) Neq(value interface{}) Clause { + return eqDecl{v, notValueExpr{value: value}} +} + // Type returns a clause enforcing that the variable has one of the types // passed by constraining its Type to the output of passing the // args to Types. It is syntactic sugar around existing primitives. diff --git a/pkg/sql/schemachanger/rel/query_lang_expr.go b/pkg/sql/schemachanger/rel/query_lang_expr.go index 0bbbff3f1774..4d1cfe1e57a4 100644 --- a/pkg/sql/schemachanger/rel/query_lang_expr.go +++ b/pkg/sql/schemachanger/rel/query_lang_expr.go @@ -44,6 +44,12 @@ type valueExpr struct { func (v valueExpr) expr() {} +type notValueExpr struct { + value interface{} +} + +func (v notValueExpr) expr() {} + type anyExpr []interface{} func (a anyExpr) expr() {} diff --git a/pkg/sql/schemachanger/rel/query_lang_yaml.go b/pkg/sql/schemachanger/rel/query_lang_yaml.go index b161162b070b..7c1f4b547fc8 100644 --- a/pkg/sql/schemachanger/rel/query_lang_yaml.go +++ b/pkg/sql/schemachanger/rel/query_lang_yaml.go @@ -31,6 +31,10 @@ func (v valueExpr) encoded() interface{} { return valueForYAML(v.value) } +func (v notValueExpr) encoded() interface{} { + return valueForYAML(v.value) +} + func (a anyExpr) encoded() interface{} { ret := make([]interface{}, 0, len(a)) for _, v := range a { @@ -95,9 +99,14 @@ func clauseStr(lhs string, rhs expr) (string, error) { if err != nil { return "", err } - op := "=" - if _, isAny := rhs.(anyExpr); isAny { + var op string + switch rhs.(type) { + case valueExpr, Var: + op = "=" + case anyExpr: op = "IN" + case notValueExpr: + op = "!=" } return fmt.Sprintf("%s %s %s", lhs, op, rhsStr), nil } diff --git a/pkg/sql/schemachanger/rel/schema_rules.go b/pkg/sql/schemachanger/rel/schema_rules.go index bd405d3f54b3..6d6076cb7dff 100644 --- a/pkg/sql/schemachanger/rel/schema_rules.go +++ b/pkg/sql/schemachanger/rel/schema_rules.go @@ -34,17 +34,20 @@ func (sc *Schema) ForEachRule(f func(def RuleDef)) { } } -// Rule1 is a rule with one input variable. -type Rule1 = func(a Var) Clause - -// Rule2 is a rule with two input variables. -type Rule2 = func(a, b Var) Clause - -// Rule3 is a rule with three input variables. -type Rule3 = func(a, b, c Var) Clause - -// Rule4 is a rule with four input variables. -type Rule4 = func(a, b, c, d Var) Clause +type ( + // Rule1 is a rule with one variable. + Rule1 = func(a Var) Clause + // Rule2 is a rule with two variables. + Rule2 = func(a, b Var) Clause + // Rule3 is a rule with three variables. + Rule3 = func(a, b, c Var) Clause + // Rule4 is a rule with four variables. + Rule4 = func(a, b, c, d Var) Clause + // Rule5 is a rule with five variables. + Rule5 = func(a, b, c, d, e Var) Clause + // Rule6 is a rule with six variables. + Rule6 = func(a, b, c, d, e, f Var) Clause +) // Def1 defines a Rule1. func (sc *Schema) Def1(name string, a Var, def func(a Var) Clauses) Rule1 { @@ -66,6 +69,18 @@ func (sc *Schema) Def4(name string, a, b, c, d Var, def func(a, b, c, d Var) Cla return sc.rule(name, def, a, b, c, d).(Rule4) } +// Def5 defines a Rule5. +func (sc *Schema) Def5(name string, a, b, c, d, e Var, def func(a, b, c, d, e Var) Clauses) Rule5 { + return sc.rule(name, def, a, b, c, d, e).(Rule5) +} + +// Def6 defines a Rule6. +func (sc *Schema) Def6( + name string, a, b, c, d, e, f Var, def func(a, b, c, d, e, f Var) Clauses, +) Rule6 { + return sc.rule(name, def, a, b, c, d, e, f).(Rule6) +} + var ( varType = reflect.TypeOf(Var("")) clauseType = reflect.TypeOf((*Clause)(nil)).Elem() diff --git a/pkg/sql/schemachanger/rel/schema_value.go b/pkg/sql/schemachanger/rel/schema_value.go index 8657f43c8885..1baea23a6d79 100644 --- a/pkg/sql/schemachanger/rel/schema_value.go +++ b/pkg/sql/schemachanger/rel/schema_value.go @@ -34,7 +34,7 @@ func makeComparableValue(val interface{}) (typedValue, error) { } typ := vv.Type() switch { - case isIntKind(typ.Kind()): + case isIntKind(typ.Kind()), isUintKind(typ.Kind()): // We need to allocate a new pointer. compType := getComparableType(typ) vvNew := reflect.New(vv.Type()) @@ -45,7 +45,7 @@ func makeComparableValue(val interface{}) (typedValue, error) { }, nil case typ.Kind() == reflect.Ptr: switch { - case isIntKind(typ.Elem().Kind()): + case isIntKind(typ.Elem().Kind()), isUintKind(typ.Elem().Kind()): compType := getComparableType(typ.Elem()) return typedValue{ typ: vv.Type().Elem(), diff --git a/pkg/sql/schemachanger/rel/testdata/entitynode b/pkg/sql/schemachanger/rel/testdata/entitynode index cd4bfda4b032..94afd8b0adb1 100755 --- a/pkg/sql/schemachanger/rel/testdata/entitynode +++ b/pkg/sql/schemachanger/rel/testdata/entitynode @@ -338,4 +338,54 @@ queries: results: - [a] unsatisfiableIndexes: [1, 2, 3, 4, 5, 6] + e[i8] != 1: + query: + - $e[Type] = '*entitynodetest.entity' + - $e[i8] != 1 + entities: [$e] + result-vars: [$e] + results: + - [b] + - [c] + unsatisfiableIndexes: [1, 2, 3, 5, 6] + e != a: + query: + - $e[Type] = '*entitynodetest.entity' + - '$e != {i8: 1, pi8: 1, i16: 1}' + entities: [$e] + result-vars: [$e] + results: + - [b] + - [c] + unsatisfiableIndexes: [1, 2, 3, 5, 6] + e[i8] = v; v != 1: + query: + - $e[Type] = '*entitynodetest.entity' + - $e[i8] = $v + - $v != 1 + entities: [$e] + result-vars: [$e, $v] + results: + - [b, 2] + - [c, 2] + unsatisfiableIndexes: [1, 2, 3, 5, 6] + e[i8] = v; v != 2: + query: + - $e[Type] = '*entitynodetest.entity' + - $e[i8] = $v + - $v != 2 + entities: [$e] + result-vars: [$e, $v] + results: + - [a, 1] + unsatisfiableIndexes: [1, 2, 3, 5, 6] + e[i8] = v; v != int16(2): + query: + - $e[Type] = '*entitynodetest.entity' + - $e[i8] = $v + - $v != 2 + entities: [$e] + result-vars: [$e, $v] + results: [] + unsatisfiableIndexes: [1, 2, 3, 5, 6] comparisons: [] diff --git a/pkg/sql/schemachanger/scbuild/builder_state.go b/pkg/sql/schemachanger/scbuild/builder_state.go index ad0d1dcbef80..8c116bab70c8 100644 --- a/pkg/sql/schemachanger/scbuild/builder_state.go +++ b/pkg/sql/schemachanger/scbuild/builder_state.go @@ -11,6 +11,7 @@ package scbuild import ( + "sort" "strings" "github.com/cockroachdb/cockroach/pkg/keys" @@ -256,23 +257,35 @@ func (b *builderState) IndexPartitioningDescriptor( index *scpb.Index, partBy *tree.PartitionBy, ) catpb.PartitioningDescriptor { b.ensureDescriptor(index.TableID) - desc := b.descCache[index.TableID].desc + bd := b.descCache[index.TableID] + desc := bd.desc tbl, ok := desc.(catalog.TableDescriptor) if !ok { panic(errors.AssertionFailedf("Expected table descriptor for ID %d, instead got %s", desc.GetID(), desc.DescriptorType())) } var oldNumImplicitColumns int - scpb.ForEachIndexPartitioning(b, func(_ scpb.Status, _ scpb.TargetStatus, p *scpb.IndexPartitioning) { + + scpb.ForEachIndexPartitioning(bd.ers, func(_ scpb.Status, _ scpb.TargetStatus, p *scpb.IndexPartitioning) { if p.TableID != index.TableID || p.IndexID != index.IndexID { return } oldNumImplicitColumns = int(p.PartitioningDescriptor.NumImplicitColumns) }) - oldKeyColumnNames := make([]string, len(index.KeyColumnIDs)) - for i, colID := range index.KeyColumnIDs { + + var keyColumns []*scpb.IndexColumn + scpb.ForEachIndexColumn(bd.ers, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn) { + if e.IndexID == index.IndexID && e.Kind == scpb.IndexColumn_KEY { + keyColumns = append(keyColumns, e) + } + }) + sort.Slice(keyColumns, func(i, j int) bool { + return keyColumns[i].OrdinalInKind < keyColumns[j].OrdinalInKind + }) + oldKeyColumnNames := make([]string, len(keyColumns)) + for i, ic := range keyColumns { scpb.ForEachColumnName(b, func(_ scpb.Status, _ scpb.TargetStatus, cn *scpb.ColumnName) { - if cn.TableID != index.TableID || cn.ColumnID != colID { + if cn.TableID != index.TableID || cn.ColumnID != ic.ColumnID { return } oldKeyColumnNames[i] = cn.Name diff --git a/pkg/sql/schemachanger/scbuild/builder_test.go b/pkg/sql/schemachanger/scbuild/builder_test.go index a3103e5a3431..d887693a923f 100644 --- a/pkg/sql/schemachanger/scbuild/builder_test.go +++ b/pkg/sql/schemachanger/scbuild/builder_test.go @@ -89,7 +89,9 @@ func TestBuildDataDriven(t *testing.T) { }, } { t.Run(depsType.name, func(t *testing.T) { - s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{}) + s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ + DisableDefaultTestTenant: true, + }) defer s.Stopper().Stop(ctx) tdb := sqlutils.MakeSQLRunner(sqlDB) datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string { 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 3ecff5285e4f..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 @@ -12,11 +12,11 @@ package scbuildstmt import ( "fmt" + "sort" "strings" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -227,15 +227,9 @@ func alterTableAddColumn( if idx := cdd.PrimaryKeyOrUniqueIndexDescriptor; idx != nil { idx.ID = b.NextTableIndexID(tbl) { - tableElts := b.QueryByID(tbl.TableID) - namesToIDs := make(map[string]descpb.ColumnID) - scpb.ForEachColumnName(tableElts, func(current scpb.Status, target scpb.TargetStatus, e *scpb.ColumnName) { - if target == scpb.ToPublic { - namesToIDs[e.Name] = e.ColumnID - } - }) + namesToIDs := columnNamesToIDs(b, tbl) for _, colName := range cdd.PrimaryKeyOrUniqueIndexDescriptor.KeyColumnNames { - cdd.PrimaryKeyOrUniqueIndexDescriptor.KeyColumnIDs = append(cdd.PrimaryKeyOrUniqueIndexDescriptor.KeyColumnIDs, namesToIDs[colName]) + idx.KeyColumnIDs = append(idx.KeyColumnIDs, namesToIDs[colName]) } } addSecondaryIndexTargetsForAddColumn(b, tbl, idx, primaryIdx) @@ -248,6 +242,17 @@ func alterTableAddColumn( } } +func columnNamesToIDs(b BuildCtx, tbl *scpb.Table) map[string]descpb.ColumnID { + tableElts := b.QueryByID(tbl.TableID) + namesToIDs := make(map[string]descpb.ColumnID) + scpb.ForEachColumnName(tableElts, func(current scpb.Status, target scpb.TargetStatus, e *scpb.ColumnName) { + if target == scpb.ToPublic { + namesToIDs[e.Name] = e.ColumnID + } + }) + return namesToIDs +} + type addColumnSpec struct { tbl *scpb.Table col *scpb.Column @@ -284,14 +289,15 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { // Check whether a target to add a new primary index already exists. If so, // simply add the new column to its storing columns. var existing, freshlyAdded *scpb.PrimaryIndex - publicTargets := b.QueryByID(spec.tbl.TableID).Filter( + allTargets := b.QueryByID(spec.tbl.TableID) + publicTargets := allTargets.Filter( func(_ scpb.Status, target scpb.TargetStatus, _ scpb.Element) bool { return target == scpb.ToPublic }, ) scpb.ForEachPrimaryIndex(publicTargets, func(status scpb.Status, _ scpb.TargetStatus, idx *scpb.PrimaryIndex) { existing = idx - if status == scpb.Status_ABSENT { + if status == scpb.Status_ABSENT || status == scpb.Status_BACKFILL_ONLY { // TODO(postamar): does it matter that there could be more than one? freshlyAdded = idx } @@ -323,12 +329,19 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { // Exceptionally, we can edit the element directly here, by virtue of it // currently being in the ABSENT state we know that it was introduced as a // PUBLIC target by the current statement. - freshlyAdded.StoringColumnIDs = append(freshlyAdded.StoringColumnIDs, spec.col.ColumnID) - tempIndex.StoringColumnIDs = append(tempIndex.StoringColumnIDs, spec.col.ColumnID) - if colinfo.CanHaveCompositeKeyEncoding(spec.colType.Type) { - freshlyAdded.CompositeColumnIDs = append(freshlyAdded.CompositeColumnIDs, spec.col.ColumnID) - tempIndex.CompositeColumnIDs = append(tempIndex.CompositeColumnIDs, spec.col.ColumnID) + + // We want to just add a new index column to the index and to its temp index. + ic := &scpb.IndexColumn{ + TableID: spec.tbl.TableID, + IndexID: freshlyAdded.IndexID, + ColumnID: spec.col.ColumnID, + OrdinalInKind: getNextStoredIndexColumnOrdinal(allTargets, freshlyAdded), + Kind: scpb.IndexColumn_STORED, } + b.Add(ic) + tempIC := protoutil.Clone(ic).(*scpb.IndexColumn) + tempIC.IndexID = tempIndex.IndexID + b.Add(tempIC) return freshlyAdded } // Otherwise, create a new primary index target and swap it with the existing @@ -337,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 @@ -351,6 +400,13 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { existingPartitioning = part } }) + var existingColumns []*scpb.IndexColumn + scpb.ForEachIndexColumn(publicTargets, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn) { + if e.IndexID == existing.IndexID { + existingColumns = append(existingColumns, e) + b.Drop(e) + } + }) if existingPartitioning != nil { b.Drop(existingPartitioning) } @@ -361,11 +417,20 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { replacement := protoutil.Clone(existing).(*scpb.PrimaryIndex) replacement.IndexID = b.NextTableIndexID(spec.tbl) replacement.SourceIndexID = existing.IndexID - replacement.StoringColumnIDs = append(replacement.StoringColumnIDs, spec.col.ColumnID) + for _, ec := range existingColumns { + cloned := protoutil.Clone(ec).(*scpb.IndexColumn) + cloned.IndexID = replacement.IndexID + b.Add(cloned) + } + ic := &scpb.IndexColumn{ + TableID: spec.tbl.TableID, + IndexID: replacement.IndexID, + ColumnID: spec.col.ColumnID, + OrdinalInKind: getNextStoredIndexColumnOrdinal(allTargets, replacement), + Kind: scpb.IndexColumn_STORED, + } + b.Add(ic) replacement.TemporaryIndexID = replacement.IndexID + 1 - if colinfo.CanHaveCompositeKeyEncoding(spec.colType.Type) { - replacement.CompositeColumnIDs = append(replacement.CompositeColumnIDs, spec.col.ColumnID) - } b.Add(replacement) if existingName != nil { updatedName := protoutil.Clone(existingName).(*scpb.IndexName) @@ -390,10 +455,27 @@ func addColumn(b BuildCtx, spec addColumnSpec) (backing *scpb.PrimaryIndex) { updatedPartitioning.IndexID = temp.IndexID b.Add(updatedPartitioning) } - + for _, ec := range append(existingColumns, ic) { + cloned := protoutil.Clone(ec).(*scpb.IndexColumn) + cloned.IndexID = temp.IndexID + b.Add(cloned) + } return replacement } +func getNextStoredIndexColumnOrdinal(allTargets ElementResultSet, idx *scpb.PrimaryIndex) uint32 { + max := -1 + scpb.ForEachIndexColumn(allTargets, func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.IndexID == idx.IndexID && e.Kind == scpb.IndexColumn_STORED && + int(e.OrdinalInKind) > max { + max = int(e.OrdinalInKind) + } + }) + return uint32(max + 1) +} + // getImplicitSecondaryIndexName determines the implicit name for a secondary // index, this logic matches tabledesc.BuildIndexName. func getImplicitSecondaryIndexName( @@ -409,9 +491,10 @@ func getImplicitSecondaryIndexName( if idx == nil { panic(errors.AssertionFailedf("unable to find secondary index.")) } + keyColumns := getIndexColumns(elts, id, scpb.IndexColumn_KEY) // An index name has a segment for the table name, each key column, and a // final word (either "idx" or "key"). - segments := make([]string, 0, len(idx.KeyColumnIDs)+2) + segments := make([]string, 0, len(keyColumns)+2) // Add the table name segment. var tblName *scpb.Namespace scpb.ForEachNamespace(b, func(current scpb.Status, target scpb.TargetStatus, e *scpb.Namespace) { @@ -439,9 +522,9 @@ func getImplicitSecondaryIndexName( // segment. If there are multiple inaccessible columns, add an incrementing // integer suffix. exprCount := 0 - for i, n := numImplicitColumns, len(idx.KeyColumnIDs); i < n; i++ { + for i, n := numImplicitColumns, len(keyColumns); i < n; i++ { var segmentName string - colElts := findColumnNameByID(idx.KeyColumnIDs[i]) + colElts := findColumnNameByID(keyColumns[i].ColumnID) _, _, col := scpb.FindColumnType(colElts) if col.ComputeExpr != nil { if exprCount == 0 { @@ -481,29 +564,34 @@ func getImplicitSecondaryIndexName( return name } +func getIndexColumns( + elts ElementResultSet, id descpb.IndexID, kind scpb.IndexColumn_Kind, +) []*scpb.IndexColumn { + var keyColumns []*scpb.IndexColumn + scpb.ForEachIndexColumn(elts, func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn) { + if e.IndexID == id && e.Kind == kind { + keyColumns = append(keyColumns, e) + } + }) + sort.Slice(keyColumns, func(i, j int) bool { + return keyColumns[i].OrdinalInKind < keyColumns[j].OrdinalInKind + }) + return keyColumns +} + func addSecondaryIndexTargetsForAddColumn( b BuildCtx, tbl *scpb.Table, desc *descpb.IndexDescriptor, newPrimaryIdx *scpb.PrimaryIndex, ) { var partitioning *catpb.PartitioningDescriptor index := scpb.Index{ - TableID: tbl.TableID, - IndexID: desc.ID, - KeyColumnIDs: desc.KeyColumnIDs, - KeyColumnDirections: make([]scpb.Index_Direction, len(desc.KeyColumnIDs)), - KeySuffixColumnIDs: desc.KeySuffixColumnIDs, - StoringColumnIDs: desc.StoreColumnIDs, - CompositeColumnIDs: desc.CompositeColumnIDs, - IsUnique: desc.Unique, - IsInverted: desc.Type == descpb.IndexDescriptor_INVERTED, - SourceIndexID: newPrimaryIdx.IndexID, + TableID: tbl.TableID, + IndexID: desc.ID, + IsUnique: desc.Unique, + IsInverted: desc.Type == descpb.IndexDescriptor_INVERTED, + SourceIndexID: newPrimaryIdx.IndexID, } tempIndexID := index.IndexID + 1 // this is enforced below index.TemporaryIndexID = tempIndexID - for i, dir := range desc.KeyColumnDirections { - if dir == descpb.IndexDescriptor_DESC { - index.KeyColumnDirections[i] = scpb.Index_DESC - } - } if desc.Sharded.IsSharded { index.Sharding = &desc.Sharded } @@ -511,11 +599,6 @@ func addSecondaryIndexTargetsForAddColumn( // allocateIndexIDs, but we are going to do it explicitly for the declarative // schema changer. { - publicTargets := b.QueryByID(tbl.TableID).Filter( - func(_ scpb.Status, target scpb.TargetStatus, _ scpb.Element) bool { - return target == scpb.ToPublic - }, - ) // Apply any implicit partitioning columns first, if they are missing. scpb.ForEachIndexPartitioning(b, func(current scpb.Status, target scpb.TargetStatus, e *scpb.IndexPartitioning) { if e.IndexID == newPrimaryIdx.IndexID && @@ -525,53 +608,76 @@ func addSecondaryIndexTargetsForAddColumn( }) keyColSet := catalog.TableColSet{} extraSuffixColumns := catalog.TableColSet{} - for _, colID := range index.KeyColumnIDs { + for _, colID := range desc.KeyColumnIDs { keyColSet.Add(colID) } - if partitioning != nil && - len(desc.Partitioning.Range) == 0 && len(desc.Partitioning.List) == 0 && + newPrimaryIdxKeyColumns := getIndexColumns( + b.QueryByID(tbl.TableID), newPrimaryIdx.IndexID, scpb.IndexColumn_KEY, + ) + if partitioning != nil && len(desc.Partitioning.Range) == 0 && + len(desc.Partitioning.List) == 0 && partitioning.NumImplicitColumns > 0 { - keyColumns := make([]descpb.ColumnID, 0, len(index.KeyColumnIDs)+int(partitioning.NumImplicitColumns)) - for _, colID := range newPrimaryIdx.KeyColumnIDs[0:partitioning.NumImplicitColumns] { - if !keyColSet.Contains(colID) { - keyColumns = append(keyColumns, colID) - keyColSet.Add(colID) + + keyColumnIDs := make( + []descpb.ColumnID, 0, + len(desc.KeyColumnIDs)+int(partitioning.NumImplicitColumns), + ) + keyColumnDirs := make( + []catpb.IndexColumn_Direction, 0, + len(desc.KeyColumnIDs)+int(partitioning.NumImplicitColumns), + ) + for _, c := range newPrimaryIdxKeyColumns[0:partitioning.NumImplicitColumns] { + if !keyColSet.Contains(c.ColumnID) { + keyColumnIDs = append(keyColumnIDs, c.ColumnID) + keyColumnDirs = append(keyColumnDirs, c.Direction) + keyColSet.Add(c.ColumnID) } } - index.KeyColumnIDs = append(keyColumns, index.KeyColumnIDs...) + desc.KeyColumnIDs = append(keyColumnIDs, desc.KeyColumnIDs...) + desc.KeyColumnDirections = append(keyColumnDirs, desc.KeyColumnDirections...) } else if len(desc.Partitioning.Range) != 0 || len(desc.Partitioning.List) != 0 { partitioning = &desc.Partitioning } - for _, colID := range newPrimaryIdx.KeyColumnIDs { - if !keyColSet.Contains(colID) { - extraSuffixColumns.Add(colID) + for _, c := range newPrimaryIdxKeyColumns { + if !keyColSet.Contains(c.ColumnID) { + extraSuffixColumns.Add(c.ColumnID) } } if !extraSuffixColumns.Empty() { - index.KeySuffixColumnIDs = append(index.KeySuffixColumnIDs, extraSuffixColumns.Ordered()...) - } - // Add in any composite columns at the same time. - // CompositeColumnIDs is defined as the subset of columns in the index key - // or in the primary key whose type has a composite encoding, like DECIMAL - // for instance. - compositeColIDs := catalog.TableColSet{} - scpb.ForEachColumnType(publicTargets, func(current scpb.Status, target scpb.TargetStatus, e *scpb.ColumnType) { - if colinfo.CanHaveCompositeKeyEncoding(e.Type) { - compositeColIDs.Add(e.ColumnID) - } - }) - for _, colID := range index.KeyColumnIDs { - if compositeColIDs.Contains(colID) { - index.CompositeColumnIDs = append(index.CompositeColumnIDs, colID) - } - } - for _, colID := range index.KeySuffixColumnIDs { - if compositeColIDs.Contains(colID) { - index.CompositeColumnIDs = append(index.CompositeColumnIDs, colID) - } + desc.KeySuffixColumnIDs = append( + desc.KeySuffixColumnIDs, extraSuffixColumns.Ordered()..., + ) } } sec := &scpb.SecondaryIndex{Index: index} + for i, dir := range desc.KeyColumnDirections { + b.Add(&scpb.IndexColumn{ + TableID: tbl.TableID, + IndexID: index.IndexID, + ColumnID: desc.KeyColumnIDs[i], + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY, + Direction: dir, + }) + } + for i, colID := range desc.KeySuffixColumnIDs { + b.Add(&scpb.IndexColumn{ + TableID: tbl.TableID, + IndexID: index.IndexID, + ColumnID: colID, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY_SUFFIX, + }) + } + for i, colID := range desc.StoreColumnIDs { + b.Add(&scpb.IndexColumn{ + TableID: tbl.TableID, + IndexID: index.IndexID, + ColumnID: colID, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_STORED, + }) + } b.Add(sec) indexName := desc.Name numImplicitColumns := 0 @@ -597,6 +703,20 @@ func addSecondaryIndexTargetsForAddColumn( "assumed temporary index ID %d != %d", tempIndexID, temp.IndexID, )) } + var tempIndexColumns []*scpb.IndexColumn + scpb.ForEachIndexColumn(b.QueryByID(tbl.TableID), func( + _ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.IndexID != index.IndexID { + return + } + c := protoutil.Clone(e).(*scpb.IndexColumn) + c.IndexID = tempIndexID + tempIndexColumns = append(tempIndexColumns, c) + }) + for _, c := range tempIndexColumns { + b.Add(c) + } b.AddTransient(temp) // Add in the partitioning descriptor for the final and temporary index. if partitioning != nil { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go index 535486cb11ac..eabf1175064d 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go @@ -11,6 +11,8 @@ package scbuildstmt import ( + "sort" + "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" @@ -84,6 +86,16 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { } case *scpb.PrimaryIndex: + // TODO(ajwerner): This is too simplistic. We should build a better + // vocabulary around the possible primary indexes in play. There are + // at most going to be 3, and at least there is going to be 1. If + // there are no column set changes, or there's just additions of + // nullable columns there'll be just one. If there are only either + // adds or drops, but not both, there will be two, the initial and + // the final. If there are both adds and drops, then there will be + // 3, including an intermediate primary index which is keyed on the + // initial primary key and include the union of all of the added and + // dropped columns. if target == scpb.ToPublic { source = t } @@ -130,6 +142,9 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { } // Set key column IDs and directions. keyColNames := make([]string, len(n.Columns)) + var newIndexColumns []*scpb.IndexColumn + var keyColIDs catalog.TableColSet + indexID := nextRelationIndexID(b, relation) for i, columnNode := range n.Columns { colName := columnNode.Column.String() if columnNode.Expr != nil { @@ -151,22 +166,50 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { panic(colinfo.NewUndefinedColumnError(colName)) } keyColNames[i] = colName - index.KeyColumnIDs = append(index.KeyColumnIDs, columnID) - direction := scpb.Index_ASC + direction := catpb.IndexColumn_ASC if columnNode.Direction == tree.Descending { - direction = scpb.Index_DESC + direction = catpb.IndexColumn_DESC + } + ic := &scpb.IndexColumn{ + TableID: index.TableID, + IndexID: indexID, + ColumnID: columnID, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY, + Direction: direction, } - index.KeyColumnDirections = append(index.KeyColumnDirections, direction) + newIndexColumns = append(newIndexColumns, ic) + keyColIDs.Add(columnID) } // Set the key suffix column IDs. - keyColIDs := catalog.MakeTableColSet(index.KeyColumnIDs...) - for _, id := range source.KeyColumnIDs { - if !keyColIDs.Contains(id) { - index.KeySuffixColumnIDs = append(index.KeySuffixColumnIDs, id) + // We want to find the key column IDs + var keySuffixColumns []*scpb.IndexColumn + scpb.ForEachIndexColumn(relationElements, func( + current scpb.Status, target scpb.TargetStatus, e *scpb.IndexColumn, + ) { + if e.IndexID != source.IndexID || keyColIDs.Contains(e.ColumnID) || + e.Kind != scpb.IndexColumn_KEY { + return + } + keySuffixColumns = append(keySuffixColumns, e) + }) + sort.Slice(keySuffixColumns, func(i, j int) bool { + return keySuffixColumns[i].OrdinalInKind < keySuffixColumns[j].OrdinalInKind + }) + for i, c := range keySuffixColumns { + ic := &scpb.IndexColumn{ + TableID: index.TableID, + IndexID: indexID, + ColumnID: c.ColumnID, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY_SUFFIX, + Direction: c.Direction, } + newIndexColumns = append(newIndexColumns, ic) } + // Set the storing column IDs. - for _, storingNode := range n.Storing { + for i, storingNode := range n.Storing { var columnID catid.ColumnID scpb.ForEachColumnName(relationElements, func(_ scpb.Status, target scpb.TargetStatus, e *scpb.ColumnName) { if target == scpb.ToPublic && tree.Name(e.Name) == storingNode { @@ -176,7 +219,14 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { if columnID == 0 { panic(colinfo.NewUndefinedColumnError(storingNode.String())) } - index.StoringColumnIDs = append(index.StoringColumnIDs, columnID) + c := &scpb.IndexColumn{ + TableID: index.TableID, + IndexID: indexID, + ColumnID: columnID, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_STORED, + } + newIndexColumns = append(newIndexColumns, c) } // Set up sharding. if n.Sharded != nil { @@ -196,6 +246,10 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { // and made a new primary key above. index.SourceIndexID = source.IndexID index.IndexID = nextRelationIndexID(b, relation) + for _, ic := range newIndexColumns { + ic.IndexID = index.IndexID + b.Add(ic) + } tempIndexID := index.IndexID + 1 // this is enforced below index.TemporaryIndexID = tempIndexID sec := &scpb.SecondaryIndex{Index: index} @@ -227,6 +281,11 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { )) } b.AddTransient(temp) + for _, ic := range newIndexColumns { + tic := protoutil.Clone(ic).(*scpb.IndexColumn) + tic.IndexID = tempIndexID + b.Add(tic) + } if n.PartitionByIndex.ContainsPartitions() { b.Add(&scpb.IndexPartitioning{ TableID: temp.TableID, diff --git a/pkg/sql/schemachanger/scbuild/testdata/alter_table b/pkg/sql/schemachanger/scbuild/testdata/alter_table index fc3b05209afa..0c99e43504c1 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/alter_table +++ b/pkg/sql/schemachanger/scbuild/testdata/alter_table @@ -25,56 +25,12 @@ ALTER TABLE defaultdb.foo ADD COLUMN j INT width: 64 isNullable: true tableId: 104 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] details: + columnId: 2 indexId: 1 - name: foo_pkey + kind: STORED tableId: 104 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] - details: - indexId: 2 - name: foo_pkey - tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] - details: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - sourceIndexId: 1 - storingColumnIds: - - 2 - tableId: 104 - temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - sourceIndexId: 1 - storingColumnIds: - - 2 - tableId: 104 build ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123 @@ -105,6 +61,33 @@ ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123 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] + details: + columnId: 2 + indexId: 3 + kind: STORED + tableId: 104 - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] details: indexId: 1 @@ -121,39 +104,23 @@ ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123 constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 2 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 3 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 tableId: 104 build @@ -212,6 +179,47 @@ ALTER TABLE defaultdb.foo ADD COLUMN k INT DEFAULT 456; 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] + details: + columnId: 2 + indexId: 3 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 2 + kind: STORED + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 3 + kind: STORED + ordinalInKind: 1 + tableId: 104 - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] details: indexId: 1 @@ -228,41 +236,23 @@ ALTER TABLE defaultdb.foo ADD COLUMN k INT DEFAULT 456; constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 2 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 - - 3 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 3 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 - - 3 tableId: 104 build @@ -290,6 +280,33 @@ ALTER TABLE defaultdb.foo ADD COLUMN a INT AS (i+1) STORED 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] + details: + columnId: 2 + indexId: 3 + kind: STORED + tableId: 104 - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] details: indexId: 1 @@ -306,39 +323,23 @@ ALTER TABLE defaultdb.foo ADD COLUMN a INT AS (i+1) STORED constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 2 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 3 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 tableId: 104 setup @@ -389,107 +390,16 @@ ALTER TABLE defaultdb.bar ADD COLUMN b INT; width: 64 isNullable: true tableId: 105 -- [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 1}, ABSENT], PUBLIC] +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] details: + columnId: 2 indexId: 1 - name: foo_pkey + kind: STORED 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] +- [[IndexColumn:{DescID: 105, ColumnID: 3, IndexID: 1}, PUBLIC], ABSENT] details: + columnId: 3 indexId: 1 - name: bar_pkey + kind: STORED + ordinalInKind: 1 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 - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - sourceIndexId: 1 - storingColumnIds: - - 2 - tableId: 104 - temporaryIndexId: 3 -- [[PrimaryIndex:{DescID: 105, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] - details: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - storingColumnIds: - - 1 - tableId: 105 -- [[PrimaryIndex:{DescID: 105, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - sourceIndexId: 1 - storingColumnIds: - - 1 - - 3 - tableId: 105 - temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - sourceIndexId: 1 - storingColumnIds: - - 2 - tableId: 104 -- [[TemporaryIndex:{DescID: 105, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] - details: - embeddedIndex: - constraintId: 1 - indexId: 3 - isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - sourceIndexId: 1 - storingColumnIds: - - 1 - - 3 - tableId: 105 diff --git a/pkg/sql/schemachanger/scbuild/testdata/create_index b/pkg/sql/schemachanger/scbuild/testdata/create_index index 5e8003335ef0..2448f2dff0db 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/create_index +++ b/pkg/sql/schemachanger/scbuild/testdata/create_index @@ -5,39 +5,57 @@ CREATE TABLE defaultdb.t1 (id INT8 PRIMARY KEY, name VARCHAR(256), money INT8) build CREATE INDEX id1 ON defaultdb.t1(id, name) STORING (money) ---- +- [[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 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 2 + indexId: 3 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 2 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 3 + kind: STORED + tableId: 104 - [[IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC], ABSENT] details: indexId: 2 name: id1 tableId: 104 -- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: indexId: 2 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: indexId: 3 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 isUsingSecondaryEncoding: true @@ -45,43 +63,61 @@ build CREATE INVERTED INDEX CONCURRENTLY id2 ON defaultdb.t1 (id, name) STORING (money) ---- +- [[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 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 2 + indexId: 3 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 2 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 3 + kind: STORED + tableId: 104 - [[IndexName:{DescID: 104, Name: id2, IndexID: 2}, PUBLIC], ABSENT] details: indexId: 2 name: id2 tableId: 104 -- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: indexId: 2 isConcurrently: true isInverted: true - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: indexId: 3 isConcurrently: true isInverted: true - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 isUsingSecondaryEncoding: true @@ -91,6 +127,40 @@ CREATE INDEX id3 STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1)) ---- +- [[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 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 2 + indexId: 3 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 2 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 3 + kind: STORED + tableId: 104 - [[IndexName:{DescID: 104, Name: id3, IndexID: 2}, PUBLIC], ABSENT] details: indexId: 2 @@ -108,34 +178,18 @@ CREATE INDEX id3 partitioning: numColumns: 1 tableId: 104 -- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: indexId: 2 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 temporaryIndexId: 3 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: indexId: 3 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 isUsingSecondaryEncoding: true @@ -165,6 +219,108 @@ CREATE INDEX id4 oid: 23 width: 32 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: 1, IndexID: 4}, PUBLIC], ABSENT] + details: + columnId: 1 + indexId: 4 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 5}, PUBLIC], ABSENT] + details: + columnId: 1 + indexId: 5 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 2 + indexId: 1 + kind: STORED + 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] + details: + columnId: 2 + indexId: 3 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4}, PUBLIC], ABSENT] + details: + columnId: 2 + indexId: 4 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5}, PUBLIC], ABSENT] + details: + columnId: 2 + indexId: 5 + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 3 + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 2 + kind: STORED + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 3 + kind: STORED + ordinalInKind: 1 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 4}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 4 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 5}, PUBLIC], ABSENT] + details: + columnId: 3 + indexId: 5 + kind: STORED + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 2}, PUBLIC], ABSENT] + details: + columnId: 4 + indexId: 2 + kind: STORED + ordinalInKind: 2 + tableId: 104 +- [[IndexColumn:{DescID: 104, ColumnID: 4, IndexID: 3}, PUBLIC], ABSENT] + details: + columnId: 4 + indexId: 3 + kind: STORED + ordinalInKind: 2 + tableId: 104 - [[IndexName:{DescID: 104, Name: id4, IndexID: 4}, PUBLIC], ABSENT] details: indexId: 4 @@ -186,41 +342,20 @@ CREATE INDEX id4 constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - storingColumnIds: - - 2 - - 3 tableId: 104 -- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] +- [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 2 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 - - 3 - - 4 tableId: 104 temporaryIndexId: 3 -- [[SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 0, TemporaryIndexID: 5}, PUBLIC], ABSENT] +- [[SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 0, TemporaryIndexID: 5, SourceIndexID: 1}, PUBLIC], ABSENT] details: embeddedIndex: indexId: 4 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sharding: columnNames: - id @@ -229,36 +364,20 @@ CREATE INDEX id4 name: crdb_internal_id_name_shard_8 shardBuckets: 8 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 temporaryIndexId: 5 -- [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: constraintId: 1 indexId: 3 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 sourceIndexId: 1 - storingColumnIds: - - 2 - - 3 - - 4 tableId: 104 -- [[TemporaryIndex:{DescID: 104, IndexID: 5}, TRANSIENT_ABSENT], ABSENT] +- [[TemporaryIndex:{DescID: 104, IndexID: 5, SourceIndexID: 1}, TRANSIENT_ABSENT], ABSENT] details: embeddedIndex: indexId: 5 - keyColumnDirections: - - ASC - - ASC - keyColumnIds: - - 1 - - 2 sharding: columnNames: - id @@ -267,7 +386,5 @@ CREATE INDEX id4 name: crdb_internal_id_name_shard_8 shardBuckets: 8 sourceIndexId: 1 - storingColumnIds: - - 3 tableId: 104 isUsingSecondaryEncoding: true diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_database b/pkg/sql/schemachanger/scbuild/testdata/drop_database index 078e9860a476..569f503978a6 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_database +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_database @@ -734,6 +734,42 @@ DROP DATABASE db1 CASCADE details: arrayTypeId: 116 typeId: 115 +- [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 1 + indexId: 1 + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 2 + indexId: 1 + kind: STORED + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 3 + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 109 +- [[IndexColumn:{DescID: 110, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 1 + indexId: 1 + tableId: 110 +- [[IndexColumn:{DescID: 110, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 2 + indexId: 1 + kind: STORED + tableId: 110 +- [[IndexColumn:{DescID: 110, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 3 + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 110 - [[IndexComment:{DescID: 109, IndexID: 1, Comment: t1_pkey is good}, ABSENT], PUBLIC] details: comment: t1_pkey is good @@ -935,13 +971,6 @@ DROP DATABASE db1 CASCADE constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - storingColumnIds: - - 2 - - 3 tableId: 109 - [[PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] details: @@ -949,13 +978,6 @@ DROP DATABASE db1 CASCADE constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - storingColumnIds: - - 2 - - 3 tableId: 110 - [[Schema:{DescID: 105}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_schema b/pkg/sql/schemachanger/scbuild/testdata/drop_schema index 95255b19b591..2c3eff670202 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_schema +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_schema @@ -710,6 +710,24 @@ DROP SCHEMA defaultdb.SC1 CASCADE details: arrayTypeId: 113 typeId: 112 +- [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 1 + indexId: 1 + tableId: 107 +- [[IndexColumn:{DescID: 107, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 2 + indexId: 1 + kind: STORED + tableId: 107 +- [[IndexColumn:{DescID: 107, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 3 + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 107 - [[IndexComment:{DescID: 107, IndexID: 1, Comment: t1_pkey is good}, ABSENT], PUBLIC] details: comment: t1_pkey is good @@ -875,13 +893,6 @@ DROP SCHEMA defaultdb.SC1 CASCADE constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - storingColumnIds: - - 2 - - 3 tableId: 107 - [[Schema:{DescID: 104}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_table b/pkg/sql/schemachanger/scbuild/testdata/drop_table index 5278f25c17bd..400b1b4b081d 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_table +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_table @@ -346,6 +346,45 @@ DROP TABLE defaultdb.shipments CASCADE; - 2 referencedTableId: 105 tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 1 + indexId: 1 + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 2 + indexId: 1 + kind: STORED + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 3 + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 4 + indexId: 1 + kind: STORED + ordinalInKind: 2 + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 5, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 5 + indexId: 1 + kind: STORED + ordinalInKind: 3 + tableId: 109 +- [[IndexColumn:{DescID: 109, ColumnID: 6, IndexID: 1}, ABSENT], PUBLIC] + details: + columnId: 6 + indexId: 1 + kind: STORED + ordinalInKind: 4 + tableId: 109 - [[IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT], PUBLIC] details: comment: pkey is good @@ -404,16 +443,6 @@ DROP TABLE defaultdb.shipments CASCADE; constraintId: 1 indexId: 1 isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - storingColumnIds: - - 2 - - 3 - - 4 - - 5 - - 6 tableId: 109 - [[Sequence:{DescID: 110}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scdecomp/decomp.go b/pkg/sql/schemachanger/scdecomp/decomp.go index 7f3a262e4556..a7bd25d1bcb8 100644 --- a/pkg/sql/schemachanger/scdecomp/decomp.go +++ b/pkg/sql/schemachanger/scdecomp/decomp.go @@ -410,19 +410,37 @@ func (w *walkCtx) walkIndex(tbl catalog.TableDescriptor, idx catalog.Index) { TableID: tbl.GetID(), IndexID: idx.GetID(), IsUnique: idx.IsUnique(), - KeyColumnIDs: cpy.KeyColumnIDs, - KeySuffixColumnIDs: cpy.KeySuffixColumnIDs, - StoringColumnIDs: cpy.StoreColumnIDs, - CompositeColumnIDs: cpy.CompositeColumnIDs, IsInverted: idx.GetType() == descpb.IndexDescriptor_INVERTED, IsCreatedExplicitly: idx.IsCreatedExplicitly(), ConstraintID: idx.GetConstraintID(), } - index.KeyColumnDirections = make([]scpb.Index_Direction, len(index.KeyColumnIDs)) - for i := 0; i < idx.NumKeyColumns(); i++ { - if idx.GetKeyColumnDirection(i) == descpb.IndexDescriptor_DESC { - index.KeyColumnDirections[i] = scpb.Index_DESC - } + for i, c := range cpy.KeyColumnIDs { + w.ev(scpb.Status_PUBLIC, &scpb.IndexColumn{ + TableID: tbl.GetID(), + IndexID: idx.GetID(), + ColumnID: c, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY, + Direction: cpy.KeyColumnDirections[i], + }) + } + for i, c := range cpy.KeySuffixColumnIDs { + w.ev(scpb.Status_PUBLIC, &scpb.IndexColumn{ + TableID: tbl.GetID(), + IndexID: idx.GetID(), + ColumnID: c, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_KEY_SUFFIX, + }) + } + for i, c := range cpy.StoreColumnIDs { + w.ev(scpb.Status_PUBLIC, &scpb.IndexColumn{ + TableID: tbl.GetID(), + IndexID: idx.GetID(), + ColumnID: c, + OrdinalInKind: uint32(i), + Kind: scpb.IndexColumn_STORED, + }) } if idx.IsSharded() { index.Sharding = &cpy.Sharded diff --git a/pkg/sql/schemachanger/scdecomp/decomp_test.go b/pkg/sql/schemachanger/scdecomp/decomp_test.go index 0cae22c59aba..cf03c26805e3 100644 --- a/pkg/sql/schemachanger/scdecomp/decomp_test.go +++ b/pkg/sql/schemachanger/scdecomp/decomp_test.go @@ -30,7 +30,11 @@ func TestDecomposeToElements(t *testing.T) { ctx := context.Background() newCluster := func(t *testing.T, knobs *scexec.TestingKnobs) (_ *gosql.DB, cleanup func()) { - tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{}) + tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ + ServerArgs: base.TestServerArgs{ + DisableDefaultTestTenant: true, + }, + }) return tc.ServerConn(0), func() { tc.Stopper().Stop(ctx) } } diff --git a/pkg/sql/schemachanger/scdecomp/testdata/sequence b/pkg/sql/schemachanger/scdecomp/testdata/sequence index c909240ad132..1345d8ed4094 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/sequence +++ b/pkg/sql/schemachanger/scdecomp/testdata/sequence @@ -139,22 +139,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 tableId: 105 temporaryIndexId: 0 Status: PUBLIC @@ -328,6 +320,22 @@ ElementState: indexId: 1 tableId: 105 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 105 @@ -415,22 +423,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 tableId: 105 temporaryIndexId: 0 Status: PUBLIC @@ -582,6 +582,22 @@ ElementState: indexId: 1 tableId: 105 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 105 diff --git a/pkg/sql/schemachanger/scdecomp/testdata/table b/pkg/sql/schemachanger/scdecomp/testdata/table index fe03f9a0f4f5..e2b92805ca77 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/table +++ b/pkg/sql/schemachanger/scdecomp/testdata/table @@ -60,21 +60,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: [] tableId: 104 temporaryIndexId: 0 Status: PUBLIC @@ -179,6 +172,14 @@ ElementState: name: parent_pkey tableId: 104 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 104 @@ -270,45 +271,27 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 - - 3 tableId: 105 temporaryIndexId: 0 Status: PUBLIC - SecondaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 0 indexId: 2 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: false - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: - - 1 sharding: null sourceIndexId: 0 - storingColumnIds: - - 3 tableId: 105 temporaryIndexId: 0 Status: PUBLIC @@ -515,6 +498,54 @@ ElementState: indexId: 1 tableId: 105 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 2 + kind: KEY_SUFFIX + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 2 + kind: KEY + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 3 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 105 + Status: PUBLIC +- IndexColumn: + columnId: 3 + direction: ASC + indexId: 2 + kind: STORED + ordinalInKind: 0 + tableId: 105 + Status: PUBLIC - ConstraintName: constraintId: 2 name: myfk @@ -616,22 +647,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] - constraintId: 2 - indexId: 2 + constraintId: 1 + indexId: 1 isConcurrently: false - isCreatedExplicitly: true + isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 tableId: 104 temporaryIndexId: 0 Status: PUBLIC @@ -764,10 +787,26 @@ ElementState: tableId: 104 Status: PUBLIC - IndexName: - indexId: 2 + indexId: 1 name: parent_pkey tableId: 104 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 104 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 104 @@ -854,22 +893,14 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 1 tableId: 108 temporaryIndexId: 0 Status: PUBLIC @@ -1019,6 +1050,22 @@ ElementState: name: greeter_pkey tableId: 108 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC - Namespace: databaseId: 100 descriptorId: 108 diff --git a/pkg/sql/schemachanger/scdecomp/testdata/type b/pkg/sql/schemachanger/scdecomp/testdata/type index 69a05232b60b..7bf4701487e4 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/type +++ b/pkg/sql/schemachanger/scdecomp/testdata/type @@ -139,45 +139,27 @@ ElementState: Status: PUBLIC - PrimaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 1 indexId: 1 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: true - keyColumnDirections: - - ASC - keyColumnIds: - - 1 - keySuffixColumnIds: [] sharding: null sourceIndexId: 0 - storingColumnIds: - - 2 - - 4 - - 5 tableId: 108 temporaryIndexId: 0 Status: PUBLIC - SecondaryIndex: embeddedIndex: - compositeColumnIds: [] constraintId: 0 indexId: 2 isConcurrently: false isCreatedExplicitly: false isInverted: false isUnique: false - keyColumnDirections: - - ASC - keyColumnIds: - - 2 - keySuffixColumnIds: - - 1 sharding: null sourceIndexId: 0 - storingColumnIds: [] tableId: 108 temporaryIndexId: 0 Status: PUBLIC @@ -469,6 +451,54 @@ ElementState: isRelationBeingDropped: false tableId: 108 Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 1 + kind: KEY + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 1 + direction: ASC + indexId: 2 + kind: KEY_SUFFIX + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 2 + direction: ASC + indexId: 2 + kind: KEY + ordinalInKind: 0 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 4 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 1 + tableId: 108 + Status: PUBLIC +- IndexColumn: + columnId: 5 + direction: ASC + indexId: 1 + kind: STORED + ordinalInKind: 2 + tableId: 108 + Status: PUBLIC - ConstraintName: constraintId: 2 name: mycheck diff --git a/pkg/sql/schemachanger/scexec/BUILD.bazel b/pkg/sql/schemachanger/scexec/BUILD.bazel index 362d530f42e4..752150ea7e72 100644 --- a/pkg/sql/schemachanger/scexec/BUILD.bazel +++ b/pkg/sql/schemachanger/scexec/BUILD.bazel @@ -67,6 +67,7 @@ go_test( "//pkg/settings/cluster", "//pkg/sql", "//pkg/sql/catalog", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/descs", "//pkg/sql/catalog/lease", diff --git a/pkg/sql/schemachanger/scexec/exec_backfill_test.go b/pkg/sql/schemachanger/scexec/exec_backfill_test.go index 66205ce16996..b25a46c0696c 100644 --- a/pkg/sql/schemachanger/scexec/exec_backfill_test.go +++ b/pkg/sql/schemachanger/scexec/exec_backfill_test.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -63,13 +64,13 @@ func TestExecBackfiller(t *testing.T) { addIndexMutation := func( t *testing.T, mut *tabledesc.Mutable, name string, id descpb.IndexID, isTempIndex bool, columns ...string, ) catalog.Index { - var dirs []descpb.IndexDescriptor_Direction + var dirs []catpb.IndexColumn_Direction var columnIDs, keySuffixColumnIDs []descpb.ColumnID var columnIDSet catalog.TableColSet for _, c := range columns { col, err := mut.FindColumnWithName(tree.Name(c)) require.NoError(t, err) - dirs = append(dirs, descpb.IndexDescriptor_ASC) + dirs = append(dirs, catpb.IndexColumn_ASC) columnIDs = append(columnIDs, col.GetID()) columnIDSet.Add(col.GetID()) } diff --git a/pkg/sql/schemachanger/scexec/exec_mutation.go b/pkg/sql/schemachanger/scexec/exec_mutation.go index ff6075820f9e..28bd277f83a4 100644 --- a/pkg/sql/schemachanger/scexec/exec_mutation.go +++ b/pkg/sql/schemachanger/scexec/exec_mutation.go @@ -40,7 +40,7 @@ func executeDescriptorMutationOps(ctx context.Context, deps Dependencies, ops [] v := scmutationexec.NewMutationVisitor(mvs, deps.Catalog(), deps.Clock()) for _, op := range ops { if err := op.(scop.MutationOp).Visit(ctx, v); err != nil { - return err + return errors.Wrapf(err, "%T: %v", op, op) } } diff --git a/pkg/sql/schemachanger/scexec/executor_external_test.go b/pkg/sql/schemachanger/scexec/executor_external_test.go index f6534b1de98a..68aa896bc220 100644 --- a/pkg/sql/schemachanger/scexec/executor_external_test.go +++ b/pkg/sql/schemachanger/scexec/executor_external_test.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/lease" @@ -34,7 +35,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scexec" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" - "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" "github.com/cockroachdb/cockroach/pkg/sql/sqlutil" @@ -183,8 +183,8 @@ CREATE TABLE db.t ( KeyColumnIDs: []descpb.ColumnID{1}, KeyColumnNames: []string{"i"}, StoreColumnNames: []string{}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, ConstraintID: 3, UseDeletePreservingEncoding: true, @@ -211,13 +211,19 @@ CREATE TABLE db.t ( return []scop.Op{ &scop.MakeAddedTempIndexDeleteOnly{ Index: scpb.Index{ - TableID: table.ID, - IndexID: indexToAdd.ID, - KeyColumnIDs: []catid.ColumnID{1}, - KeyColumnDirections: []scpb.Index_Direction{scpb.Index_ASC}, + TableID: table.ID, + IndexID: indexToAdd.ID, }, IsSecondaryIndex: true, }, + &scop.AddColumnToIndex{ + TableID: table.ID, + ColumnID: 1, + IndexID: indexToAdd.ID, + Kind: scpb.IndexColumn_KEY, + Direction: catpb.IndexColumn_ASC, + Ordinal: 0, + }, } }, }, @@ -276,25 +282,12 @@ func TestSchemaChanger(t *testing.T) { targets := []scpb.Target{ scpb.MakeTarget( scpb.ToPublic, - &scpb.PrimaryIndex{ - Index: scpb.Index{ - TableID: fooTable.GetID(), - IndexID: 2, - KeyColumnIDs: []catid.ColumnID{1}, - KeyColumnDirections: []scpb.Index_Direction{scpb.Index_ASC}, - StoringColumnIDs: []catid.ColumnID{2}, - IsUnique: true, - SourceIndexID: 1, - }, - }, - metadata, - ), - scpb.MakeTarget( - scpb.ToPublic, - &scpb.IndexName{ - TableID: fooTable.GetID(), - IndexID: 2, - Name: "new_primary_key", + &scpb.IndexColumn{ + TableID: fooTable.GetID(), + IndexID: 1, + ColumnID: 2, + OrdinalInKind: 0, + Kind: scpb.IndexColumn_STORED, }, metadata, ), @@ -326,37 +319,12 @@ func TestSchemaChanger(t *testing.T) { }, metadata, ), - scpb.MakeTarget( - scpb.ToAbsent, - &scpb.PrimaryIndex{ - Index: scpb.Index{ - TableID: fooTable.GetID(), - IndexID: 1, - KeyColumnIDs: []catid.ColumnID{1}, - KeyColumnDirections: []scpb.Index_Direction{scpb.Index_ASC}, - IsUnique: true, - }, - }, - 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}, @@ -389,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/scexec/scmutationexec/BUILD.bazel b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel index 6ab4547ef1ca..737da7bbf3a1 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel +++ b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel @@ -21,6 +21,8 @@ go_library( "//pkg/jobs/jobspb", "//pkg/keys", "//pkg/sql/catalog", + "//pkg/sql/catalog/catpb", + "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/dbdesc", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/schemadesc", @@ -35,6 +37,7 @@ go_library( "//pkg/sql/sem/tree", "//pkg/sql/types", "//pkg/util/iterutil", + "//pkg/util/log", "//pkg/util/log/eventpb", "//pkg/util/protoutil", "//pkg/util/timeutil", diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/column.go b/pkg/sql/schemachanger/scexec/scmutationexec/column.go index aac3ccf1b287..7ccb2d072a5e 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/column.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/column.go @@ -94,6 +94,7 @@ func (m *visitor) MakeAddedColumnDeleteAndWriteOnly( MakeColumnIDMutationSelector(op.ColumnID), descpb.DescriptorMutation_DELETE_ONLY, descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, + descpb.DescriptorMutation_ADD, ) } @@ -150,6 +151,7 @@ func (m *visitor) MakeDroppedColumnDeleteOnly( MakeColumnIDMutationSelector(op.ColumnID), descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, descpb.DescriptorMutation_DELETE_ONLY, + descpb.DescriptorMutation_DROP, ) } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go b/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go index 0989004f37d1..9640b3206da6 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go @@ -78,7 +78,10 @@ func (m *visitor) checkOutType(ctx context.Context, id descpb.ID) (*typedesc.Mut } func mutationStateChange( - tbl *tabledesc.Mutable, f MutationSelector, exp, next descpb.DescriptorMutation_State, + tbl *tabledesc.Mutable, + f MutationSelector, + exp, next descpb.DescriptorMutation_State, + direction descpb.DescriptorMutation_Direction, ) error { mut, err := FindMutation(tbl, f) if err != nil { @@ -90,6 +93,7 @@ func mutationStateChange( tbl.GetID(), exp, m.State, tbl) } m.State = next + m.Direction = direction return nil } @@ -146,18 +150,6 @@ func (m *visitor) removeMutation( return cpy, nil } -func columnNamesFromIDs(tbl *tabledesc.Mutable, columnIDs descpb.ColumnIDs) ([]string, error) { - storeColNames := make([]string, 0, len(columnIDs)) - for _, colID := range columnIDs { - column, err := tbl.FindColumnWithID(colID) - if err != nil { - return nil, err - } - storeColNames = append(storeColNames, column.GetName()) - } - return storeColNames, nil -} - // MutationSelector defines a predicate on a catalog.Mutation with no // side-effects. type MutationSelector func(mutation catalog.Mutation) (matches bool) diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index d12652f269dc..7cbacee6c9a5 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -12,11 +12,16 @@ package scmutationexec import ( "context" + "sort" + "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" + "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" "github.com/cockroachdb/errors" "github.com/cockroachdb/redact" @@ -58,21 +63,7 @@ func addNewIndexMutation( if opIndex.IndexID >= tbl.NextIndexID { tbl.NextIndexID = opIndex.IndexID + 1 } - // Resolve column names - colNames, err := columnNamesFromIDs(tbl, opIndex.KeyColumnIDs) - if err != nil { - return err - } - storeColNames, err := columnNamesFromIDs(tbl, opIndex.StoringColumnIDs) - if err != nil { - return err - } - colDirs := make([]descpb.IndexDescriptor_Direction, len(opIndex.KeyColumnIDs)) - for i, dir := range opIndex.KeyColumnDirections { - if dir == scpb.Index_DESC { - colDirs[i] = descpb.IndexDescriptor_DESC - } - } + // Set up the index descriptor type. indexType := descpb.IndexDescriptor_FORWARD if opIndex.IsInverted { @@ -90,18 +81,12 @@ func addNewIndexMutation( Name: tabledesc.IndexNamePlaceholder(opIndex.IndexID), Unique: opIndex.IsUnique, Version: indexVersion, - KeyColumnNames: colNames, - KeyColumnIDs: opIndex.KeyColumnIDs, - StoreColumnIDs: opIndex.StoringColumnIDs, - StoreColumnNames: storeColNames, - KeyColumnDirections: colDirs, Type: indexType, - KeySuffixColumnIDs: opIndex.KeySuffixColumnIDs, - CompositeColumnIDs: opIndex.CompositeColumnIDs, CreatedExplicitly: true, EncodingType: encodingType, ConstraintID: tbl.GetNextConstraintID(), UseDeletePreservingEncoding: isDeletePreserving, + StoreColumnNames: []string{}, } if opIndex.Sharding != nil { idx.Sharded = *opIndex.Sharding @@ -138,6 +123,7 @@ func (m *visitor) MakeBackfillingIndexDeleteOnly( MakeIndexIDMutationSelector(op.IndexID), descpb.DescriptorMutation_BACKFILLING, descpb.DescriptorMutation_DELETE_ONLY, + descpb.DescriptorMutation_ADD, ) } @@ -153,6 +139,7 @@ func (m *visitor) MakeAddedIndexDeleteAndWriteOnly( MakeIndexIDMutationSelector(op.IndexID), descpb.DescriptorMutation_DELETE_ONLY, descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, + descpb.DescriptorMutation_ADD, ) } @@ -217,6 +204,7 @@ func (m *visitor) MakeDroppedPrimaryIndexDeleteAndWriteOnly( return errors.AssertionFailedf("index being dropped (%d) does not match existing primary index (%d).", op.IndexID, tbl.PrimaryIndex.ID) } desc := tbl.GetPrimaryIndex().IndexDescDeepCopy() + tbl.TableDesc().PrimaryIndex = descpb.IndexDescriptor{} // zero-out the current primary index return enqueueDropIndexMutation(tbl, &desc) } @@ -249,6 +237,7 @@ func (m *visitor) MakeDroppedIndexDeleteOnly( MakeIndexIDMutationSelector(op.IndexID), descpb.DescriptorMutation_DELETE_AND_WRITE_ONLY, descpb.DescriptorMutation_DELETE_ONLY, + descpb.DescriptorMutation_DROP, ) } @@ -309,3 +298,144 @@ func (m *visitor) SetIndexName(ctx context.Context, op scop.SetIndexName) error index.IndexDesc().Name = op.Name return nil } + +func (m *visitor) AddColumnToIndex(ctx context.Context, op scop.AddColumnToIndex) error { + tbl, err := m.checkOutTable(ctx, op.TableID) + if err != nil { + return err + } + index, err := tbl.FindIndexWithID(op.IndexID) + if err != nil { + return err + } + column, err := tbl.FindColumnWithID(op.ColumnID) + if err != nil { + return err + } + // Deal with the fact that we allow the columns to be unordered in how + // we add them. We could add a rule to make sure we add the columns in + // order, but we'd need a way to express successor or something in rel + // rules to add those dependencies efficiently. Instead, we just don't + // and sort here. + indexDesc := index.IndexDesc() + n := int(op.Ordinal + 1) + insertIntoNames := func(s *[]string) { + for delta := n - len(*s); delta > 0; delta-- { + *s = append(*s, "") + } + (*s)[n-1] = column.GetName() + } + insertIntoDirections := func(s *[]catpb.IndexColumn_Direction) { + for delta := n - len(*s); delta > 0; delta-- { + *s = append(*s, 0) + } + (*s)[n-1] = op.Direction + } + insertIntoIDs := func(s *[]descpb.ColumnID) { + for delta := n - len(*s); delta > 0; delta-- { + *s = append(*s, 0) + } + (*s)[n-1] = column.GetID() + } + switch op.Kind { + case scpb.IndexColumn_KEY: + insertIntoIDs(&indexDesc.KeyColumnIDs) + insertIntoNames(&indexDesc.KeyColumnNames) + insertIntoDirections(&indexDesc.KeyColumnDirections) + case scpb.IndexColumn_KEY_SUFFIX: + insertIntoIDs(&indexDesc.KeySuffixColumnIDs) + case scpb.IndexColumn_STORED: + insertIntoIDs(&indexDesc.StoreColumnIDs) + insertIntoNames(&indexDesc.StoreColumnNames) + } + // If this is a composite column, note that. + if colinfo.CanHaveCompositeKeyEncoding(column.GetType()) && + // We don't need to track the composite column IDs for stored columns. + op.Kind != scpb.IndexColumn_STORED { + + index.NumKeyColumns() + var colOrdMap catalog.TableColMap + for i := 0; i < index.NumKeyColumns(); i++ { + colOrdMap.Set(index.GetKeyColumnID(i), i) + } + for i := 0; i < index.NumKeySuffixColumns(); i++ { + colOrdMap.Set(index.GetKeyColumnID(i), i+index.NumKeyColumns()) + } + indexDesc.CompositeColumnIDs = append(indexDesc.CompositeColumnIDs, column.GetID()) + cids := indexDesc.CompositeColumnIDs + sort.Slice(cids, func(i, j int) bool { + return colOrdMap.GetDefault(cids[i]) < colOrdMap.GetDefault(cids[j]) + }) + } + return nil +} + +func (m *visitor) RemoveColumnFromIndex(ctx context.Context, op scop.RemoveColumnFromIndex) error { + tbl, err := m.checkOutTable(ctx, op.TableID) + if err != nil { + return err + } + index, err := tbl.FindIndexWithID(op.IndexID) + if err != nil { + return err + } + // As a special case, avoid removing any columns from dropped indexes. + // The index is going to be removed, so it doesn't matter if it references + // dropped columns. + log.Infof(ctx, "yo sup, %d %d %v %v %v", op.IndexID, op.ColumnID, index.Dropped(), index.DeleteOnly(), index.Public()) + if index.Dropped() { + return nil + } + column, err := tbl.FindColumnWithID(op.ColumnID) + if err != nil { + return err + } + // Deal with the fact that we allow the columns to be unordered in how + // we add them. We could add a rule to make sure we add the columns in + // order, but we'd need a way to express successor or something in rel + // rules to add those dependencies efficiently. Instead, we just don't + // and sort here. + idx := index.IndexDesc() + n := int(op.Ordinal + 1) + removeFromNames := func(s *[]string) { + (*s)[n-1] = "" + } + removeFromColumnIDs := func(s *[]descpb.ColumnID) { + (*s)[n-1] = 0 + } + switch op.Kind { + case scpb.IndexColumn_KEY: + removeFromNames(&idx.KeyColumnNames) + removeFromColumnIDs(&idx.KeyColumnIDs) + for i := len(idx.KeyColumnIDs) - 1; i >= 0 && idx.KeyColumnIDs[i] == 0; i-- { + idx.KeyColumnNames = idx.KeyColumnNames[:i] + idx.KeyColumnIDs = idx.KeyColumnIDs[:i] + idx.KeyColumnDirections = idx.KeyColumnDirections[:i] + } + case scpb.IndexColumn_KEY_SUFFIX: + removeFromColumnIDs(&idx.KeySuffixColumnIDs) + for i := len(idx.KeySuffixColumnIDs) - 1; i >= 0 && idx.KeySuffixColumnIDs[i] == 0; i-- { + idx.KeySuffixColumnIDs = idx.KeySuffixColumnIDs[:i] + } + case scpb.IndexColumn_STORED: + removeFromNames(&idx.StoreColumnNames) + removeFromColumnIDs(&idx.StoreColumnIDs) + for i := len(idx.StoreColumnIDs) - 1; i >= 0 && idx.StoreColumnIDs[i] == 0; i-- { + idx.StoreColumnNames = idx.StoreColumnNames[:i] + idx.StoreColumnIDs = idx.StoreColumnIDs[:i] + } + } + // If this is a composite column, remove it from the list. + if colinfo.CanHaveCompositeKeyEncoding(column.GetType()) && + // We don't need to track the composite column IDs for stored columns. + op.Kind != scpb.IndexColumn_STORED { + for i, colID := range idx.CompositeColumnIDs { + if colID == column.GetID() { + idx.CompositeColumnIDs = append( + idx.CompositeColumnIDs[:i], idx.CompositeColumnIDs[i+1:]..., + ) + } + } + } + return nil +} diff --git a/pkg/sql/schemachanger/scop/mutation.go b/pkg/sql/schemachanger/scop/mutation.go index fb416aa30beb..e3888f7b8aa3 100644 --- a/pkg/sql/schemachanger/scop/mutation.go +++ b/pkg/sql/schemachanger/scop/mutation.go @@ -541,3 +541,27 @@ type RefreshStats struct { mutationOp TableID descpb.ID } + +// AddColumnToIndex mutates an index to add a column to it. +// The column should already exist on the table and so should +// the index. +type AddColumnToIndex struct { + mutationOp + TableID descpb.ID + ColumnID descpb.ColumnID + IndexID descpb.IndexID + Kind scpb.IndexColumn_Kind + Direction catpb.IndexColumn_Direction + Ordinal uint32 +} + +// RemoveColumnFromIndex mutates an index to removed a column from it. +// The column should already exist on the table and so should the index. +type RemoveColumnFromIndex struct { + mutationOp + TableID descpb.ID + ColumnID descpb.ColumnID + IndexID descpb.IndexID + Kind scpb.IndexColumn_Kind + Ordinal uint32 +} diff --git a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go index 15b5f0a40f98..1807a0715561 100644 --- a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go @@ -88,6 +88,8 @@ type MutationVisitor interface { RemoveDatabaseRoleSettings(context.Context, RemoveDatabaseRoleSettings) error DeleteSchedule(context.Context, DeleteSchedule) error RefreshStats(context.Context, RefreshStats) error + AddColumnToIndex(context.Context, AddColumnToIndex) error + RemoveColumnFromIndex(context.Context, RemoveColumnFromIndex) error } // Visit is part of the MutationOp interface. @@ -419,3 +421,13 @@ func (op DeleteSchedule) Visit(ctx context.Context, v MutationVisitor) error { func (op RefreshStats) Visit(ctx context.Context, v MutationVisitor) error { return v.RefreshStats(ctx, op) } + +// Visit is part of the MutationOp interface. +func (op AddColumnToIndex) Visit(ctx context.Context, v MutationVisitor) error { + return v.AddColumnToIndex(ctx, op) +} + +// Visit is part of the MutationOp interface. +func (op RemoveColumnFromIndex) Visit(ctx context.Context, v MutationVisitor) error { + return v.RemoveColumnFromIndex(ctx, op) +} diff --git a/pkg/sql/schemachanger/scpb/elements.proto b/pkg/sql/schemachanger/scpb/elements.proto index a8940d396ec8..b44c9b894919 100644 --- a/pkg/sql/schemachanger/scpb/elements.proto +++ b/pkg/sql/schemachanger/scpb/elements.proto @@ -13,6 +13,7 @@ package cockroach.sql.schemachanger.scpb; option go_package = "scpb"; import "sql/catalog/catpb/catalog.proto"; +import "sql/catalog/catpb/index.proto"; import "sql/types/types.proto"; import "gogoproto/gogo.proto"; @@ -89,6 +90,7 @@ message ElementProto { IndexPartitioning index_partitioning = 41 [(gogoproto.moretags) = "parent:\"PrimaryIndex, SecondaryIndex\""]; SecondaryIndexPartial secondary_index_partial = 42 [(gogoproto.moretags) = "parent:\"SecondaryIndex\""]; IndexComment index_comment = 43 [(gogoproto.moretags) = "parent:\"PrimaryIndex, SecondaryIndex\""]; + IndexColumn index_column = 44 [(gogoproto.moretags) = "parent:\"PrimaryIndex, SecondaryIndex, TemporaryIndex, Column\""]; // Constraint elements. ConstraintName constraint_name = 51 [(gogoproto.moretags) = "parent:\"UniqueWithoutIndexConstraint, CheckConstraint, ForeignKeyConstraint\""]; @@ -184,15 +186,6 @@ message ColumnFamily { message Index { uint32 table_id = 1 [(gogoproto.customname) = "TableID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.DescID"]; uint32 index_id = 2 [(gogoproto.customname) = "IndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; - repeated uint32 key_column_ids = 3 [(gogoproto.customname) = "KeyColumnIDs", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"]; - enum Direction { - ASC = 0; - DESC = 1; - } - repeated Direction key_column_directions = 4; - repeated uint32 key_suffix_column_ids = 5 [(gogoproto.customname) = "KeySuffixColumnIDs", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"]; - repeated uint32 storing_column_ids = 6 [(gogoproto.customname) = "StoringColumnIDs", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"]; - repeated uint32 composite_column_ids = 7 [(gogoproto.customname) = "CompositeColumnIDs", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"]; bool is_unique = 10; bool is_inverted = 11; @@ -214,6 +207,8 @@ message Index { bool is_concurrently = 20; uint32 source_index_id = 21 [(gogoproto.customname) = "SourceIndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; uint32 temporary_index_id = 22 [(gogoproto.customname) = "TemporaryIndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; + + reserved 3, 4, 5, 6, 7; } message PrimaryIndex { @@ -452,3 +447,23 @@ message DatabaseRoleSetting { uint32 database_id = 1 [(gogoproto.customname) = "DatabaseID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.DescID"]; string role_name = 2; } + +// IndexColumn models column membership in an index. +message IndexColumn { + uint32 table_id = 1 [(gogoproto.customname) = "TableID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.DescID"]; + uint32 index_id = 2 [(gogoproto.customname) = "IndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; + uint32 column_id = 3 [(gogoproto.customname) = "ColumnID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"]; + + // OrdinalInKind is the slice index of this column in the relevant slice + // as indicated by the IndexColumn's Kind. + uint32 ordinal_in_kind = 4; + enum Kind { + KEY = 0; + KEY_SUFFIX = 1; + STORED = 2; + } + Kind kind = 5; + + // Direction is only populated for KEY columns. + sql.catalog.catpb.IndexColumn.Direction direction = 6; +} diff --git a/pkg/sql/schemachanger/scpb/elements_generated.go b/pkg/sql/schemachanger/scpb/elements_generated.go index e82f9626686c..b39fa496912d 100644 --- a/pkg/sql/schemachanger/scpb/elements_generated.go +++ b/pkg/sql/schemachanger/scpb/elements_generated.go @@ -544,6 +544,37 @@ func FindForeignKeyConstraint(b ElementStatusIterator) (current Status, target T return current, target, element } +func (e IndexColumn) element() {} + +// ForEachIndexColumn iterates over elements of type IndexColumn. +func ForEachIndexColumn( + b ElementStatusIterator, fn func(current Status, target TargetStatus, e *IndexColumn), +) { + if b == nil { + return + } + b.ForEachElementStatus(func(current Status, target TargetStatus, e Element) { + if elt, ok := e.(*IndexColumn); ok { + fn(current, target, elt) + } + }) +} + +// FindIndexColumn finds the first element of type IndexColumn. +func FindIndexColumn(b ElementStatusIterator) (current Status, target TargetStatus, element *IndexColumn) { + if b == nil { + return current, target, element + } + b.ForEachElementStatus(func(c Status, t TargetStatus, e Element) { + if elt, ok := e.(*IndexColumn); ok { + element = elt + current = c + target = t + } + }) + return current, target, element +} + func (e IndexComment) element() {} // ForEachIndexComment iterates over elements of type IndexComment. diff --git a/pkg/sql/schemachanger/scpb/uml/table.puml b/pkg/sql/schemachanger/scpb/uml/table.puml index 56f312b3bef9..1077bc19580a 100644 --- a/pkg/sql/schemachanger/scpb/uml/table.puml +++ b/pkg/sql/schemachanger/scpb/uml/table.puml @@ -186,6 +186,15 @@ IndexComment : TableID IndexComment : IndexID IndexComment : Comment +object IndexColumn + +IndexColumn : TableID +IndexColumn : IndexID +IndexColumn : ColumnID +IndexColumn : OrdinalInKind +IndexColumn : Kind +IndexColumn : Direction + object ConstraintName ConstraintName : TableID @@ -279,6 +288,10 @@ SecondaryIndex <|-- IndexPartitioning SecondaryIndex <|-- SecondaryIndexPartial PrimaryIndex <|-- IndexComment SecondaryIndex <|-- IndexComment +PrimaryIndex <|-- IndexColumn +SecondaryIndex <|-- IndexColumn +TemporaryIndex <|-- IndexColumn +Column <|-- IndexColumn UniqueWithoutIndexConstraint <|-- ConstraintName CheckConstraint <|-- ConstraintName ForeignKeyConstraint <|-- ConstraintName diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel b/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel index 9bc3f319149b..56d5cd25225e 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel +++ b/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel @@ -22,6 +22,7 @@ go_library( "opgen_database_role_setting.go", "opgen_enum_type.go", "opgen_foreign_key_constraint.go", + "opgen_index_column.go", "opgen_index_comment.go", "opgen_index_name.go", "opgen_index_partitioning.go", diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_column.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_column.go new file mode 100644 index 000000000000..9a9a4e309650 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_column.go @@ -0,0 +1,48 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.IndexColumn)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, emit(func(column *scpb.IndexColumn) scop.Op { + return scop.AddColumnToIndex{ + TableID: column.TableID, + ColumnID: column.ColumnID, + IndexID: column.IndexID, + Kind: column.Kind, + Direction: column.Direction, + Ordinal: column.OrdinalInKind, + } + })), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + revertible(false), + emit(func(column *scpb.IndexColumn) scop.Op { + return scop.RemoveColumnFromIndex{ + TableID: column.TableID, + ColumnID: column.ColumnID, + IndexID: column.IndexID, + Kind: column.Kind, + Ordinal: column.OrdinalInKind, + } + })), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/rules/BUILD.bazel b/pkg/sql/schemachanger/scplan/internal/rules/BUILD.bazel index 3686ca509b40..818d9b10d15c 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/BUILD.bazel +++ b/pkg/sql/schemachanger/scplan/internal/rules/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "//pkg/sql/schemachanger/scplan/internal/opgen", "//pkg/sql/schemachanger/scplan/internal/scgraph", "//pkg/sql/schemachanger/screl", + "//pkg/sql/sem/catid", "//pkg/sql/types", "//pkg/util/iterutil", "//pkg/util/log", diff --git a/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go b/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go index 078aac18ad99..9fca7f4898fd 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/dep_index_and_column.go @@ -11,11 +11,11 @@ package rules import ( - "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/rel" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scplan/internal/scgraph" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/screl" + "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" ) // This registeredDepRule ensures that a new primary index becomes public right after the @@ -72,7 +72,7 @@ func init() { // Vice-versa for index removal. func init() { registerDepRule( - "index existence precedes index dependents", + "index existence precedes index name and comment", scgraph.Precedence, "index", "index-dependent", func(from, to nodeVars) rel.Clauses { @@ -83,7 +83,6 @@ func init() { ), to.el.Type( (*scpb.IndexName)(nil), - (*scpb.IndexPartitioning)(nil), (*scpb.IndexComment)(nil), ), joinOnIndexID(from.el, to.el, "table-id", "index-id"), @@ -93,45 +92,58 @@ func init() { } }) + // It's very important that columns are added to the descriptor's + // IndexDescriptor in the same mutation stage which adds that index + // to the TableDescriptor. registerDepRule( - "partitioning set right after temp index existence", + "index exists right before columns, partitioning, and partial", scgraph.SameStagePrecedence, - "temp-index", "index-partitioning", + "index", "index-column", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ - from.el.Type((*scpb.TemporaryIndex)(nil)), - to.el.Type((*scpb.IndexPartitioning)(nil)), + from.el.Type( + (*scpb.PrimaryIndex)(nil), + (*scpb.SecondaryIndex)(nil), + ), + to.el.Type( + (*scpb.IndexColumn)(nil), + (*scpb.IndexPartitioning)(nil), + (*scpb.SecondaryIndexPartial)(nil), + ), joinOnIndexID(from.el, to.el, "table-id", "index-id"), - targetStatus(from.target, scpb.Transient), - targetStatus(to.target, scpb.ToPublic), - currentStatus(from.node, scpb.Status_DELETE_ONLY), + targetStatusEq(from.target, to.target, scpb.ToPublic), + currentStatus(from.node, scpb.Status_BACKFILL_ONLY), currentStatus(to.node, scpb.Status_PUBLIC), } }) - registerDepRule( - "partial predicate set right after secondary index existence", + "temp index exists right before columns, partitioning, and partial", scgraph.SameStagePrecedence, - "index", "index-predicate", + "temp-index", "index-partitioning", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ - from.el.Type((*scpb.SecondaryIndex)(nil)), - to.el.Type((*scpb.SecondaryIndexPartial)(nil)), + from.el.Type((*scpb.TemporaryIndex)(nil)), + to.el.Type( + (*scpb.IndexColumn)(nil), + (*scpb.IndexPartitioning)(nil), + (*scpb.SecondaryIndexPartial)(nil), + ), joinOnIndexID(from.el, to.el, "table-id", "index-id"), - targetStatusEq(from.target, to.target, scpb.ToPublic), - currentStatus(from.node, scpb.Status_BACKFILL_ONLY), - currentStatus(to.el, scpb.Status_PUBLIC), + targetStatus(from.target, scpb.Transient), + targetStatus(to.target, scpb.ToPublic), + currentStatus(from.node, scpb.Status_DELETE_ONLY), + currentStatus(to.node, scpb.Status_PUBLIC), } }) + // Once the index is public, its comment should be visible. registerDepRule( - "dependents existence precedes writes to index", + "comment existence precedes index becoming public", scgraph.Precedence, "child", "index", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ from.el.Type( - (*scpb.IndexPartitioning)(nil), (*scpb.IndexComment)(nil), ), to.el.Type( @@ -141,7 +153,7 @@ func init() { joinOnIndexID(from.el, to.el, "table-id", "index-id"), targetStatusEq(from.target, to.target, scpb.ToPublic), currentStatus(from.node, scpb.Status_PUBLIC), - currentStatus(to.node, scpb.Status_WRITE_ONLY), + currentStatus(to.node, scpb.Status_PUBLIC), } }, ) @@ -163,47 +175,79 @@ func init() { }, ) + // If we're going to be removing columns from an index, we know that + // it'll be because we're dropping the index. If we're dropping the + // index and not the descriptor, we need to make sure that we only + // do it once the index is definitely being dropped. The reason for + // this is roundabout: dropping a column from an index which is itself + // being dropped is treated as a no-op by the execution layer. registerDepRule( - "dependents removed after index no longer public", + "temp and secondary index columns removed just before removing the index", scgraph.SameStagePrecedence, - "child", "index", + "index", "index-column", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ - from.el.Type( - (*scpb.IndexName)(nil), - (*scpb.IndexPartitioning)(nil), - (*scpb.SecondaryIndexPartial)(nil), - (*scpb.IndexComment)(nil), - ), + from.el.Type((*scpb.IndexColumn)(nil)), to.el.Type( - (*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil), + (*scpb.TemporaryIndex)(nil), ), joinOnIndexID(from.el, to.el, "table-id", "index-id"), toAbsent(from.target, to.target), currentStatus(from.node, scpb.Status_ABSENT), - currentStatus(to.node, scpb.Status_VALIDATED), + currentStatus(to.node, scpb.Status_ABSENT), } }, ) - registerDepRule( - "dependents removed before index", - scgraph.Precedence, - "dependent", "index", - func(from, to nodeVars) rel.Clauses { + indexDependents := screl.Schema.Def4("index-dependents", + "index", "dep", + "table-id", "index-id", func( + index, dep, tableID, indexID rel.Var, + ) rel.Clauses { return rel.Clauses{ - from.el.Type( + dep.Type( (*scpb.IndexName)(nil), (*scpb.IndexPartitioning)(nil), (*scpb.SecondaryIndexPartial)(nil), (*scpb.IndexComment)(nil), + (*scpb.IndexColumn)(nil), ), - to.el.Type( + index.Type( (*scpb.PrimaryIndex)(nil), + (*scpb.TemporaryIndex)(nil), (*scpb.SecondaryIndex)(nil), ), - joinOnIndexID(from.el, to.el, "table-id", "index-id"), + + joinOnIndexID(dep, index, "table-id", "index-id"), + } + }) + + // This rule is suspect. We absolutely cannot remove the partial predicate + // until the index is not longer being written to. I think the same goes + // for the columns. The partitioning is less clear. I think the name could + // go earlier. + registerDepRule( + "index no longer public before dependents removed", + scgraph.Precedence, + "index", "child", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + indexDependents(from.el, to.el, "table-id", "index-id"), + toAbsent(from.target, to.target), + currentStatus(from.node, scpb.Status_VALIDATED), + currentStatus(to.node, scpb.Status_ABSENT), + } + }, + ) + + registerDepRule( + "dependents removed before index", + scgraph.Precedence, + "dependent", "index", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + indexDependents(to.el, from.el, "table-id", "index-id"), targetStatusEq(from.target, to.target, scpb.ToAbsent), currentStatusEq(from.node, to.node, scpb.Status_ABSENT), } @@ -264,6 +308,7 @@ func init() { (*scpb.ColumnDefaultExpression)(nil), (*scpb.ColumnOnUpdateExpression)(nil), (*scpb.ColumnComment)(nil), + (*scpb.IndexColumn)(nil), ), joinOnColumnID(from.el, to.el, "table-id", "col-id"), targetStatusEq(from.target, to.target, scpb.ToPublic), @@ -449,35 +494,38 @@ func init() { // These rules ensure that columns and indexes containing these columns // appear into existence in the correct order. func init() { - columnInList := func(targetColumn descpb.ColumnID, columnList descpb.ColumnIDs) bool { - for _, column := range columnList { - if targetColumn == column { - return true + indexContainsColumn := screl.Schema.Def6( + "indexContainsColumn", + "index", "column", "index-column", "table-id", "column-id", "index-id", func( + index, column, indexColumn, tableID, columnID, indexID rel.Var, + ) rel.Clauses { + return rel.Clauses{ + index.AttrEqVar(screl.IndexID, indexID), + indexColumn.Type((*scpb.IndexColumn)(nil)), + indexColumn.AttrEqVar(screl.DescID, rel.Blank), + joinOnColumnID(column, indexColumn, tableID, columnID), + joinOnIndexID(index, indexColumn, tableID, indexID), } + }) + sourceIndexNotSet := screl.Schema.Def1("sourceIndexNotSet", "index", func( + index rel.Var, + ) rel.Clauses { + return rel.Clauses{ + index.AttrNeq(screl.SourceIndexID, catid.IndexID(0)), } - return false - } - columnInIndex := func(from *scpb.Column, to scpb.Element) bool { - var idx *scpb.Index - switch to := to.(type) { - case *scpb.PrimaryIndex: - idx = &to.Index - case *scpb.SecondaryIndex: - idx = &to.Index - case *scpb.TemporaryIndex: - idx = &to.Index - } - if idx == nil { - return false - } - return columnInList(from.ColumnID, idx.KeyColumnIDs) || - columnInList(from.ColumnID, idx.StoringColumnIDs) || - columnInList(from.ColumnID, idx.KeySuffixColumnIDs) - } - columnInPrimaryIndexSwap := func(from *scpb.Column, to *scpb.PrimaryIndex) bool { - return columnInIndex(from, to) && to.SourceIndexID != 0 - } - + }) + columnInPrimaryIndexSwap := screl.Schema.Def6( + "columnInPrimaryIndexSwap", + "index", "column", "index-column", "table-id", "column-id", "index-id", func( + index, column, indexColumn, tableID, columnID, indexID rel.Var, + ) rel.Clauses { + return rel.Clauses{ + indexContainsColumn( + index, column, indexColumn, tableID, columnID, indexID, + ), + sourceIndexNotSet(index), + } + }) registerDepRule( "column depends on primary index", scgraph.Precedence, @@ -487,14 +535,16 @@ func init() { return rel.Clauses{ from.el.Type((*scpb.PrimaryIndex)(nil)), to.el.Type((*scpb.Column)(nil)), + columnInPrimaryIndexSwap( + from.el, to.el, "index-column", "table-id", "column-id", "index-id", + ), targetStatusEq(from.target, to.target, scpb.ToPublic), - join(from.el, to.el, screl.DescID, "table-id"), - rel.Filter("columnFeaturedInIndex", to.el, from.el)(columnInIndex), status.In(scpb.Status_WRITE_ONLY, scpb.Status_PUBLIC), status.Entities(screl.CurrentStatus, from.node, to.node), } }, ) + registerDepRule( "primary index should be cleaned up before newly added column when reverting", scgraph.Precedence, @@ -505,8 +555,9 @@ func init() { from.el.Type((*scpb.PrimaryIndex)(nil)), to.el.Type((*scpb.Column)(nil)), toAbsent(from.target, to.target), - joinOnDescID(from.el, to.el, "table-id"), - rel.Filter("columnFeaturedInIndex", to.el, from.el)(columnInPrimaryIndexSwap), + columnInPrimaryIndexSwap( + from.el, to.el, "indexColumn", "table-id", "column-id", "index-id", + ), status.Eq(scpb.Status_WRITE_ONLY), status.Entities(screl.CurrentStatus, from.node, to.node), } @@ -519,15 +570,18 @@ func init() { return rel.Clauses{ from.el.Type((*scpb.Column)(nil)), to.el.Type((*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil)), + indexContainsColumn( + to.el, from.el, "index-column", "table-id", "column-id", "index-id", + ), targetStatusEq(from.target, to.target, scpb.ToPublic), currentStatus(from.node, scpb.Status_DELETE_ONLY), currentStatus(to.node, scpb.Status_BACKFILL_ONLY), - join(from.el, to.el, screl.DescID, "table-id"), - rel.Filter("columnFeaturedInIndex", from.el, to.el)(columnInIndex), } }, ) + // We need to make sure that we don't add a temporary index to a table + // until the column has been added to the table. registerDepRule( "column existence precedes temporary index existence", scgraph.Precedence, @@ -536,98 +590,98 @@ func init() { return rel.Clauses{ from.el.Type((*scpb.Column)(nil)), to.el.Type((*scpb.TemporaryIndex)(nil)), - join(from.el, to.el, screl.DescID, "table-id"), + indexContainsColumn( + to.el, from.el, "index-column", "table-id", "column-id", "index-id", + ), targetStatus(from.target, scpb.ToPublic), targetStatus(to.target, scpb.Transient), currentStatusEq(from.node, to.node, scpb.Status_DELETE_ONLY), - rel.Filter("columnFeaturedInIndex", from.el, to.el)(columnInIndex), } }, ) - primaryIndexHasSecondaryColumns := func(from *scpb.PrimaryIndex, to scpb.Element) bool { - switch to := to.(type) { - case *scpb.SecondaryIndex: - for _, colID := range from.StoringColumnIDs { - if columnInList(colID, to.KeyColumnIDs) || - columnInList(colID, to.StoringColumnIDs) || - columnInList(colID, to.KeySuffixColumnIDs) { - return true - } - } - case *scpb.TemporaryIndex: - if !to.IsUsingSecondaryEncoding { - return false - } - for _, colID := range from.StoringColumnIDs { - if columnInList(colID, to.KeyColumnIDs) || - columnInList(colID, to.StoringColumnIDs) || - columnInList(colID, to.KeySuffixColumnIDs) { - return true - } - } - } - return false - } - secondaryIndexHasPrimarySwapColumns := func(to scpb.Element, from *scpb.PrimaryIndex) bool { - if from.SourceIndexID == 0 { - return false - } - switch to := to.(type) { - case *scpb.SecondaryIndex: - for _, colID := range from.StoringColumnIDs { - if columnInList(colID, to.KeyColumnIDs) || - columnInList(colID, to.StoringColumnIDs) || - columnInList(colID, to.KeySuffixColumnIDs) { - return true - } - } - case *scpb.TemporaryIndex: - if !to.IsUsingSecondaryEncoding { - return false - } - for _, colID := range from.StoringColumnIDs { - if columnInList(colID, to.KeyColumnIDs) || - columnInList(colID, to.StoringColumnIDs) || - columnInList(colID, to.KeySuffixColumnIDs) { - return true - } - } - } - return false - } + // We want to say that all columns which are part of a secondary index need + // to be in a primary index which is validated + // To do that, we want to find a secondary index which has a source which + // is a primary index which is itself new. Then we want to find registerDepRule( - "primary index with new columns should exist before secondary/temp indexes", + "primary index with new columns should exist before secondary indexes", scgraph.Precedence, "primary-index", "second-index", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ from.el.Type((*scpb.PrimaryIndex)(nil)), - to.el.Type((*scpb.SecondaryIndex)(nil), (*scpb.TemporaryIndex)(nil)), + to.el.Type((*scpb.SecondaryIndex)(nil)), joinOnDescID(from.el, to.el, "table-id"), + joinOn( + from.el, screl.IndexID, + to.el, screl.SourceIndexID, + "primary-index-id", + ), targetStatus(from.target, scpb.ToPublic), targetStatus(to.target, scpb.ToPublic), - currentStatus(from.node, scpb.Status_VALIDATED), + currentStatus(from.node, scpb.Status_PUBLIC), currentStatus(to.node, scpb.Status_BACKFILL_ONLY), - rel.Filter("newColumnFeaturedInIndex", from.el, to.el)( - primaryIndexHasSecondaryColumns, - ), } }) registerDepRule( - "secondary indexes should be cleaned up before any primary index with columns when reverting", + "primary index with new columns should exist before temp indexes", scgraph.Precedence, - "second-index", "primary-index", + "primary-index", "second-index", func(from, to nodeVars) rel.Clauses { return rel.Clauses{ - from.el.Type((*scpb.SecondaryIndex)(nil), (*scpb.TemporaryIndex)(nil)), - to.el.Type((*scpb.PrimaryIndex)(nil)), + from.el.Type((*scpb.PrimaryIndex)(nil)), + to.el.Type((*scpb.TemporaryIndex)(nil)), joinOnDescID(from.el, to.el, "table-id"), - toAbsent(from.target, to.target), - currentStatus(from.node, scpb.Status_ABSENT), - currentStatus(to.node, scpb.Status_VALIDATED), - rel.Filter("newColumnFeaturedInIndex", from.el, to.el)( - secondaryIndexHasPrimarySwapColumns, - ), + joinOn(from.el, screl.IndexID, to.el, screl.SourceIndexID, "primary-index-id"), + targetStatus(from.target, scpb.ToPublic), + targetStatus(to.target, scpb.Transient), + currentStatus(from.node, scpb.Status_PUBLIC), + currentStatus(to.node, scpb.Status_DELETE_ONLY), + } + }) + + // We want to ensure that column names are not dropped until the column is + // no longer in use in any dropping indexes. + registerDepRule( + "column name and type to public after all index column to public", + scgraph.Precedence, + "index-column", "column-name", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + from.el.Type((*scpb.ColumnName)(nil), (*scpb.ColumnType)(nil)), + to.el.Type((*scpb.IndexColumn)(nil)), + joinOnColumnID(from.el, to.el, "table-id", "column-id"), + targetStatusEq(from.target, to.target, scpb.ToPublic), + currentStatusEq(from.node, to.node, scpb.Status_PUBLIC), + } + }, + ) + + registerDepRule("index-column added to index after index exists", + scgraph.SameStagePrecedence, + "index", "index-column", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + from.el.Type((*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil)), + to.el.Type((*scpb.IndexColumn)(nil)), + joinOnIndexID(from.el, to.el, "table-id", "index-id"), + targetStatusEq(from.target, to.target, scpb.ToPublic), + currentStatus(from.node, scpb.Status_BACKFILL_ONLY), + currentStatus(to.node, scpb.Status_PUBLIC), + } + }) + registerDepRule("index-column added to index after temp index exists", + scgraph.SameStagePrecedence, + "index", "index-column", + func(from, to nodeVars) rel.Clauses { + return rel.Clauses{ + from.el.Type((*scpb.TemporaryIndex)(nil)), + to.el.Type((*scpb.IndexColumn)(nil)), + joinOnIndexID(from.el, to.el, "table-id", "index-id"), + targetStatus(from.target, scpb.Transient), + targetStatus(to.target, scpb.ToPublic), + currentStatus(from.node, scpb.Status_DELETE_ONLY), + currentStatus(to.node, scpb.Status_PUBLIC), } }) } diff --git a/pkg/sql/schemachanger/scplan/internal/rules/helpers.go b/pkg/sql/schemachanger/scplan/internal/rules/helpers.go index 252f2c2fffeb..ae3c1f12ab44 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/helpers.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/helpers.go @@ -68,6 +68,7 @@ var ( targetStatusEq(target1, target2, scpb.ToAbsent), } }) + toAbsentIn = func(status scpb.Status) rel.Rule4 { ss := status.String() return screl.Schema.Def4( diff --git a/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go b/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go index 6aca180ee992..7170de35d785 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go @@ -124,10 +124,12 @@ func init() { index.el.Type( (*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil), + (*scpb.TemporaryIndex)(nil), ), dep.el.Type( (*scpb.IndexName)(nil), (*scpb.IndexPartitioning)(nil), + (*scpb.IndexColumn)(nil), ), joinOnDescID(relation.el, index.el, relationID), diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules index 69f03aec9c37..d116ce8875a5 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules @@ -33,6 +33,21 @@ joinOnConstraintID(a, b, desc-id, constraint-id): - joinOnDescID($a, $b, $desc-id) - $a[ConstraintID] = $constraint-id - $b[ConstraintID] = $constraint-id +index-dependents(index, dep, table-id, index-id): + - $dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn'] + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.TemporaryIndex', '*scpb.SecondaryIndex'] + - joinOnIndexID($dep, $index, $table-id, $index-id) +indexContainsColumn(index, column, index-column, table-id, column-id, index-id): + - $index[IndexID] = $index-id + - $index-column[Type] = '*scpb.IndexColumn' + - $index-column[DescID] = $_ + - joinOnColumnID($column, $index-column, $table-id, $column-id) + - joinOnIndexID($index, $index-column, $table-id, $index-id) +sourceIndexNotSet(index): + - $index[SourceIndexID] != 0 +columnInPrimaryIndexSwap(index, column, index-column, table-id, column-id, index-id): + - indexContainsColumn($index, $column, $index-column, $table-id, $column-id, $index-id) + - sourceIndexNotSet($index) deprules ---- @@ -42,7 +57,7 @@ deprules to: dependent-node query: - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType'] - - $dependent[Type] IN ['*scpb.ColumnFamily', '*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.ConstraintName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent'] + - $dependent[Type] IN ['*scpb.ColumnFamily', '*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent'] - toAbsent($descriptor-target, $dependent-target) - $descriptor-node[CurrentStatus] = DROPPED - $dependent-node[CurrentStatus] = ABSENT @@ -66,7 +81,7 @@ deprules to: referencing-via-attr-node query: - $referenced-descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType'] - - $referencing-via-attr[Type] IN ['*scpb.ColumnFamily', '*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.ConstraintName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent'] + - $referencing-via-attr[Type] IN ['*scpb.ColumnFamily', '*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent'] - toAbsent($referenced-descriptor-target, $referencing-via-attr-target) - $referenced-descriptor-node[CurrentStatus] = DROPPED - $referencing-via-attr-node[CurrentStatus] = ABSENT @@ -129,13 +144,13 @@ deprules - new-primary-index-depends-on-old(*scpb.PrimaryIndex, *scpb.PrimaryIndex)($new-index, $old-index) - joinTargetNode($new-index, $new-index-target, $new-index-node) - joinTargetNode($old-index, $old-index-target, $old-index-node) -- name: index existence precedes index dependents +- name: index existence precedes index name and comment from: index-node kind: Precedence to: index-dependent-node query: - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] - - $index-dependent[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.IndexComment'] + - $index-dependent[Type] IN ['*scpb.IndexName', '*scpb.IndexComment'] - joinOnIndexID($index, $index-dependent, $table-id, $index-id) - $index-target[TargetStatus] = PUBLIC - $index-dependent-target[TargetStatus] = PUBLIC @@ -143,13 +158,27 @@ deprules - $index-dependent-node[CurrentStatus] = PUBLIC - joinTargetNode($index, $index-target, $index-node) - joinTargetNode($index-dependent, $index-dependent-target, $index-dependent-node) -- name: partitioning set right after temp index existence +- name: index exists right before columns, partitioning, and partial + from: index-node + kind: SameStagePrecedence + to: index-column-node + query: + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] + - $index-column[Type] IN ['*scpb.IndexColumn', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial'] + - joinOnIndexID($index, $index-column, $table-id, $index-id) + - $index-target[TargetStatus] = PUBLIC + - $index-column-target[TargetStatus] = PUBLIC + - $index-node[CurrentStatus] = BACKFILL_ONLY + - $index-column-node[CurrentStatus] = PUBLIC + - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($index-column, $index-column-target, $index-column-node) +- name: temp index exists right before columns, partitioning, and partial from: temp-index-node kind: SameStagePrecedence to: index-partitioning-node query: - $temp-index[Type] = '*scpb.TemporaryIndex' - - $index-partitioning[Type] = '*scpb.IndexPartitioning' + - $index-partitioning[Type] IN ['*scpb.IndexColumn', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial'] - joinOnIndexID($temp-index, $index-partitioning, $table-id, $index-id) - $temp-index-target[TargetStatus] = TRANSIENT_ABSENT - $index-partitioning-target[TargetStatus] = PUBLIC @@ -157,32 +186,18 @@ deprules - $index-partitioning-node[CurrentStatus] = PUBLIC - joinTargetNode($temp-index, $temp-index-target, $temp-index-node) - joinTargetNode($index-partitioning, $index-partitioning-target, $index-partitioning-node) -- name: partial predicate set right after secondary index existence - from: index-node - kind: SameStagePrecedence - to: index-predicate-node - query: - - $index[Type] = '*scpb.SecondaryIndex' - - $index-predicate[Type] = '*scpb.SecondaryIndexPartial' - - joinOnIndexID($index, $index-predicate, $table-id, $index-id) - - $index-target[TargetStatus] = PUBLIC - - $index-predicate-target[TargetStatus] = PUBLIC - - $index-node[CurrentStatus] = BACKFILL_ONLY - - $index-predicate[CurrentStatus] = PUBLIC - - joinTargetNode($index, $index-target, $index-node) - - joinTargetNode($index-predicate, $index-predicate-target, $index-predicate-node) -- name: dependents existence precedes writes to index +- name: comment existence precedes index becoming public from: child-node kind: Precedence to: index-node query: - - $child[Type] IN ['*scpb.IndexPartitioning', '*scpb.IndexComment'] + - $child[Type] = '*scpb.IndexComment' - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] - joinOnIndexID($child, $index, $table-id, $index-id) - $child-target[TargetStatus] = PUBLIC - $index-target[TargetStatus] = PUBLIC - $child-node[CurrentStatus] = PUBLIC - - $index-node[CurrentStatus] = WRITE_ONLY + - $index-node[CurrentStatus] = PUBLIC - joinTargetNode($child, $child-target, $child-node) - joinTargetNode($index, $index-target, $index-node) - name: index named right before index becomes public @@ -199,27 +214,36 @@ deprules - joinOnIndexID($index-name, $index, $table-id, $index-id) - joinTargetNode($index-name, $index-name-target, $index-name-node) - joinTargetNode($index, $index-target, $index-node) -- name: dependents removed after index no longer public - from: child-node +- name: temp and secondary index columns removed just before removing the index + from: index-node kind: SameStagePrecedence - to: index-node + to: index-column-node query: - - $child[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment'] - - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] - - joinOnIndexID($child, $index, $table-id, $index-id) - - toAbsent($child-target, $index-target) - - $child-node[CurrentStatus] = ABSENT + - $index[Type] = '*scpb.IndexColumn' + - $index-column[Type] IN ['*scpb.SecondaryIndex', '*scpb.TemporaryIndex'] + - joinOnIndexID($index, $index-column, $table-id, $index-id) + - toAbsent($index-target, $index-column-target) + - $index-node[CurrentStatus] = ABSENT + - $index-column-node[CurrentStatus] = ABSENT + - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($index-column, $index-column-target, $index-column-node) +- name: index no longer public before dependents removed + from: index-node + kind: Precedence + to: child-node + query: + - index-dependents($index, $child, $table-id, $index-id) + - toAbsent($index-target, $child-target) - $index-node[CurrentStatus] = VALIDATED - - joinTargetNode($child, $child-target, $child-node) + - $child-node[CurrentStatus] = ABSENT - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($child, $child-target, $child-node) - name: dependents removed before index from: dependent-node kind: Precedence to: index-node query: - - $dependent[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment'] - - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] - - joinOnIndexID($dependent, $index, $table-id, $index-id) + - index-dependents($index, $dependent, $table-id, $index-id) - $dependent-target[TargetStatus] = ABSENT - $index-target[TargetStatus] = ABSENT - $dependent-node[CurrentStatus] = ABSENT @@ -262,7 +286,7 @@ deprules to: dependent-node query: - $column[Type] = '*scpb.Column' - - $dependent[Type] IN ['*scpb.ColumnName', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.ColumnComment'] + - $dependent[Type] IN ['*scpb.ColumnName', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.ColumnComment', '*scpb.IndexColumn'] - joinOnColumnID($column, $dependent, $table-id, $col-id) - $column-target[TargetStatus] = PUBLIC - $dependent-target[TargetStatus] = PUBLIC @@ -391,11 +415,9 @@ deprules query: - $index[Type] = '*scpb.PrimaryIndex' - $column[Type] = '*scpb.Column' + - columnInPrimaryIndexSwap($index, $column, $index-column, $table-id, $column-id, $index-id) - $index-target[TargetStatus] = PUBLIC - $column-target[TargetStatus] = PUBLIC - - $index[DescID] = $table-id - - $column[DescID] = $table-id - - columnFeaturedInIndex(*scpb.Column, scpb.Element)($column, $index) - $status IN [WRITE_ONLY, PUBLIC] - $index-node[CurrentStatus] = $status - $column-node[CurrentStatus] = $status @@ -409,8 +431,7 @@ deprules - $index[Type] = '*scpb.PrimaryIndex' - $column[Type] = '*scpb.Column' - toAbsent($index-target, $column-target) - - joinOnDescID($index, $column, $table-id) - - columnFeaturedInIndex(*scpb.Column, *scpb.PrimaryIndex)($column, $index) + - columnInPrimaryIndexSwap($index, $column, $indexColumn, $table-id, $column-id, $index-id) - $status = WRITE_ONLY - $index-node[CurrentStatus] = $status - $column-node[CurrentStatus] = $status @@ -423,13 +444,11 @@ deprules query: - $column[Type] = '*scpb.Column' - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] + - indexContainsColumn($index, $column, $index-column, $table-id, $column-id, $index-id) - $column-target[TargetStatus] = PUBLIC - $index-target[TargetStatus] = PUBLIC - $column-node[CurrentStatus] = DELETE_ONLY - $index-node[CurrentStatus] = BACKFILL_ONLY - - $column[DescID] = $table-id - - $index[DescID] = $table-id - - columnFeaturedInIndex(*scpb.Column, scpb.Element)($column, $index) - joinTargetNode($column, $column-target, $column-node) - joinTargetNode($index, $index-target, $index-node) - name: column existence precedes temporary index existence @@ -439,44 +458,87 @@ deprules query: - $column[Type] = '*scpb.Column' - $temp-index[Type] = '*scpb.TemporaryIndex' - - $column[DescID] = $table-id - - $temp-index[DescID] = $table-id + - indexContainsColumn($temp-index, $column, $index-column, $table-id, $column-id, $index-id) - $column-target[TargetStatus] = PUBLIC - $temp-index-target[TargetStatus] = TRANSIENT_ABSENT - $column-node[CurrentStatus] = DELETE_ONLY - $temp-index-node[CurrentStatus] = DELETE_ONLY - - columnFeaturedInIndex(*scpb.Column, scpb.Element)($column, $temp-index) - joinTargetNode($column, $column-target, $column-node) - joinTargetNode($temp-index, $temp-index-target, $temp-index-node) -- name: primary index with new columns should exist before secondary/temp indexes +- name: primary index with new columns should exist before secondary indexes from: primary-index-node kind: Precedence to: second-index-node query: - $primary-index[Type] = '*scpb.PrimaryIndex' - - $second-index[Type] IN ['*scpb.SecondaryIndex', '*scpb.TemporaryIndex'] + - $second-index[Type] = '*scpb.SecondaryIndex' - joinOnDescID($primary-index, $second-index, $table-id) + - $primary-index[IndexID] = $primary-index-id + - $second-index[SourceIndexID] = $primary-index-id - $primary-index-target[TargetStatus] = PUBLIC - $second-index-target[TargetStatus] = PUBLIC - - $primary-index-node[CurrentStatus] = VALIDATED + - $primary-index-node[CurrentStatus] = PUBLIC - $second-index-node[CurrentStatus] = BACKFILL_ONLY - - newColumnFeaturedInIndex(*scpb.PrimaryIndex, scpb.Element)($primary-index, $second-index) - joinTargetNode($primary-index, $primary-index-target, $primary-index-node) - joinTargetNode($second-index, $second-index-target, $second-index-node) -- name: secondary indexes should be cleaned up before any primary index with columns when reverting - from: second-index-node +- name: primary index with new columns should exist before temp indexes + from: primary-index-node kind: Precedence - to: primary-index-node + to: second-index-node query: - - $second-index[Type] IN ['*scpb.SecondaryIndex', '*scpb.TemporaryIndex'] - $primary-index[Type] = '*scpb.PrimaryIndex' - - joinOnDescID($second-index, $primary-index, $table-id) - - toAbsent($second-index-target, $primary-index-target) - - $second-index-node[CurrentStatus] = ABSENT - - $primary-index-node[CurrentStatus] = VALIDATED - - newColumnFeaturedInIndex(scpb.Element, *scpb.PrimaryIndex)($second-index, $primary-index) - - joinTargetNode($second-index, $second-index-target, $second-index-node) + - $second-index[Type] = '*scpb.TemporaryIndex' + - joinOnDescID($primary-index, $second-index, $table-id) + - $primary-index[IndexID] = $primary-index-id + - $second-index[SourceIndexID] = $primary-index-id + - $primary-index-target[TargetStatus] = PUBLIC + - $second-index-target[TargetStatus] = TRANSIENT_ABSENT + - $primary-index-node[CurrentStatus] = PUBLIC + - $second-index-node[CurrentStatus] = DELETE_ONLY - joinTargetNode($primary-index, $primary-index-target, $primary-index-node) + - joinTargetNode($second-index, $second-index-target, $second-index-node) +- name: column name and type to public after all index column to public + from: index-column-node + kind: Precedence + to: column-name-node + query: + - $index-column[Type] IN ['*scpb.ColumnName', '*scpb.ColumnType'] + - $column-name[Type] = '*scpb.IndexColumn' + - joinOnColumnID($index-column, $column-name, $table-id, $column-id) + - $index-column-target[TargetStatus] = PUBLIC + - $column-name-target[TargetStatus] = PUBLIC + - $index-column-node[CurrentStatus] = PUBLIC + - $column-name-node[CurrentStatus] = PUBLIC + - joinTargetNode($index-column, $index-column-target, $index-column-node) + - joinTargetNode($column-name, $column-name-target, $column-name-node) +- name: index-column added to index after index exists + from: index-node + kind: SameStagePrecedence + to: index-column-node + query: + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] + - $index-column[Type] = '*scpb.IndexColumn' + - joinOnIndexID($index, $index-column, $table-id, $index-id) + - $index-target[TargetStatus] = PUBLIC + - $index-column-target[TargetStatus] = PUBLIC + - $index-node[CurrentStatus] = BACKFILL_ONLY + - $index-column-node[CurrentStatus] = PUBLIC + - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($index-column, $index-column-target, $index-column-node) +- name: index-column added to index after temp index exists + from: index-node + kind: SameStagePrecedence + to: index-column-node + query: + - $index[Type] = '*scpb.TemporaryIndex' + - $index-column[Type] = '*scpb.IndexColumn' + - joinOnIndexID($index, $index-column, $table-id, $index-id) + - $index-target[TargetStatus] = TRANSIENT_ABSENT + - $index-column-target[TargetStatus] = PUBLIC + - $index-node[CurrentStatus] = DELETE_ONLY + - $index-column-node[CurrentStatus] = PUBLIC + - joinTargetNode($index, $index-target, $index-node) + - joinTargetNode($index-column, $index-column-target, $index-column-node) - name: ensure columns are in increasing order from: later-column-node kind: SameStagePrecedence diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules index b0620b8bce37..617310a1131b 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules @@ -33,6 +33,21 @@ joinOnConstraintID(a, b, desc-id, constraint-id): - joinOnDescID($a, $b, $desc-id) - $a[ConstraintID] = $constraint-id - $b[ConstraintID] = $constraint-id +index-dependents(index, dep, table-id, index-id): + - $dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn'] + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.TemporaryIndex', '*scpb.SecondaryIndex'] + - joinOnIndexID($dep, $index, $table-id, $index-id) +indexContainsColumn(index, column, index-column, table-id, column-id, index-id): + - $index[IndexID] = $index-id + - $index-column[Type] = '*scpb.IndexColumn' + - $index-column[DescID] = $_ + - joinOnColumnID($column, $index-column, $table-id, $column-id) + - joinOnIndexID($index, $index-column, $table-id, $index-id) +sourceIndexNotSet(index): + - $index[SourceIndexID] != 0 +columnInPrimaryIndexSwap(index, column, index-column, table-id, column-id, index-id): + - indexContainsColumn($index, $column, $index-column, $table-id, $column-id, $index-id) + - sourceIndexNotSet($index) oprules ---- @@ -72,8 +87,8 @@ oprules from: index-dep-node query: - $relation[Type] IN ['*scpb.Table', '*scpb.View'] - - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex'] - - $index-dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning'] + - $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex', '*scpb.TemporaryIndex'] + - $index-dep[Type] IN ['*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.IndexColumn'] - joinOnDescID($relation, $index, $relation-id) - joinOnIndexID($index, $index-dep, $relation-id, $index-id) - joinTarget($relation, $relation-target) diff --git a/pkg/sql/schemachanger/scplan/plan_test.go b/pkg/sql/schemachanger/scplan/plan_test.go index e23a756214ee..fc3cfdbc6028 100644 --- a/pkg/sql/schemachanger/scplan/plan_test.go +++ b/pkg/sql/schemachanger/scplan/plan_test.go @@ -51,7 +51,9 @@ func TestPlanDataDriven(t *testing.T) { ctx := context.Background() datadriven.Walk(t, testutils.TestDataPath(t), func(t *testing.T, path string) { - s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{}) + s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ + DisableDefaultTestTenant: true, + }) defer s.Stopper().Stop(ctx) tdb := sqlutils.MakeSQLRunner(sqlDB) diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table b/pkg/sql/schemachanger/scplan/testdata/alter_table index f3196c1467aa..3b5bf1c56346 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table @@ -6,13 +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 7 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 - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 1}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -57,33 +56,11 @@ StatementPhase stage 1 of 1 with 7 MutationType ops TypeIDs: - 105 - 106 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 - SourceIndexID: 1 - StoringColumnIDs: - - 2 - TableID: 104 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 - SourceIndexID: 1 - StoringColumnIDs: - - 2 - TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 1 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 4 MutationType ops transitions: ops: @@ -104,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}, 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}, 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}, PUBLIC], BACKFILLED] -> DELETE_ONLY - ops: - *scop.MakeBackfillingIndexDeleteOnly - IndexID: 2 - TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 *scop.SetJobStateOnDescriptor @@ -151,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 +PostCommitPhase stage 2 of 2 with 6 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], MERGE_ONLY] -> MERGED - ops: - *scop.MergeIndex - BackfilledIndexID: 2 - TableID: 104 - TemporaryIndexID: 3 -PostCommitPhase stage 6 of 7 with 1 ValidationType op - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], VALIDATED] -> PUBLIC - [[IndexName:{DescID: 104, Name: foo_pkey, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *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: 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: @@ -224,62 +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 6 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - ops: - *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}, 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 @@ -296,14 +134,18 @@ PostCommitNonRevertiblePhase stage 2 of 2 with 8 MutationType ops ops ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123 ---- -StatementPhase stage 1 of 1 with 7 MutationType ops +StatementPhase stage 1 of 1 with 11 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 [[ColumnDefaultExpression:{DescID: 104, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[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 ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -350,13 +192,7 @@ StatementPhase stage 1 of 1 with 7 MutationType ops ConstraintID: 1 IndexID: 2 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 TableID: 104 TemporaryIndexID: 3 *scop.MakeAddedTempIndexDeleteOnly @@ -364,14 +200,26 @@ StatementPhase stage 1 of 1 with 7 MutationType ops ConstraintID: 1 IndexID: 3 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 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 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 2 MutationType ops transitions: ops: @@ -393,7 +241,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops PostCommitPhase stage 1 of 7 with 4 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 2 @@ -407,7 +255,7 @@ PostCommitPhase stage 1 of 7 with 4 MutationType ops JobID: 1 PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: *scop.BackfillIndex IndexID: 2 @@ -415,7 +263,7 @@ PostCommitPhase stage 2 of 7 with 1 BackfillType op TableID: 104 PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILLED] -> DELETE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: *scop.MakeBackfillingIndexDeleteOnly IndexID: 2 @@ -426,7 +274,7 @@ PostCommitPhase stage 3 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 2 @@ -437,7 +285,7 @@ PostCommitPhase stage 4 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGE_ONLY] -> MERGED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: *scop.MergeIndex BackfilledIndexID: 2 @@ -445,7 +293,7 @@ PostCommitPhase stage 5 of 7 with 1 BackfillType op TemporaryIndexID: 3 PostCommitPhase stage 6 of 7 with 1 ValidationType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -455,9 +303,12 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops [[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}, PUBLIC], VALIDATED] -> 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 @@ -466,9 +317,6 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops IndexID: 2 Name: foo_pkey TableID: 104 - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 *scop.MakeAddedPrimaryIndexPublic EventBase: Authorization: @@ -498,11 +346,16 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops *scop.UpdateSchemaChangerJob IsNonCancelable: true JobID: 1 -PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops +PostCommitNonRevertiblePhase stage 1 of 2 with 5 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}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_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 @@ -517,7 +370,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops PostCommitNonRevertiblePhase stage 2 of 2 with 6 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT ops: *scop.CreateGcJobForIndex IndexID: 1 @@ -552,18 +405,24 @@ ops ALTER TABLE defaultdb.foo ADD COLUMN j INT DEFAULT 123; ALTER TABLE defaultdb.foo ADD COLUMN k INT DEFAULT 456; ---- -StatementPhase stage 1 of 1 with 12 MutationType ops +StatementPhase stage 1 of 1 with 18 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 [[ColumnDefaultExpression:{DescID: 104, ColumnID: 2}, PUBLIC], ABSENT] -> PUBLIC - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[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 [[Column:{DescID: 104, ColumnID: 3}, PUBLIC], ABSENT] -> DELETE_ONLY [[ColumnName:{DescID: 104, Name: k, ColumnID: 3}, PUBLIC], ABSENT] -> PUBLIC [[ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3}, PUBLIC], ABSENT] -> PUBLIC [[ColumnDefaultExpression:{DescID: 104, ColumnID: 3}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -651,14 +510,7 @@ StatementPhase stage 1 of 1 with 12 MutationType ops ConstraintID: 1 IndexID: 2 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 - - 3 TableID: 104 TemporaryIndexID: 3 *scop.MakeAddedTempIndexDeleteOnly @@ -666,15 +518,38 @@ StatementPhase stage 1 of 1 with 12 MutationType ops ConstraintID: 1 IndexID: 3 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 - - 3 TableID: 104 + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 3 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 3 + Kind: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 2 + Kind: 2 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 3 + Kind: 2 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 2 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 2 MutationType ops transitions: ops: @@ -700,7 +575,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops PostCommitPhase stage 1 of 7 with 5 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY [[Column:{DescID: 104, ColumnID: 3}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedColumnDeleteAndWriteOnly @@ -718,7 +593,7 @@ PostCommitPhase stage 1 of 7 with 5 MutationType ops JobID: 1 PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: *scop.BackfillIndex IndexID: 2 @@ -726,7 +601,7 @@ PostCommitPhase stage 2 of 7 with 1 BackfillType op TableID: 104 PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILLED] -> DELETE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: *scop.MakeBackfillingIndexDeleteOnly IndexID: 2 @@ -737,7 +612,7 @@ PostCommitPhase stage 3 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 2 @@ -748,7 +623,7 @@ PostCommitPhase stage 4 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGE_ONLY] -> MERGED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: *scop.MergeIndex BackfilledIndexID: 2 @@ -756,7 +631,7 @@ PostCommitPhase stage 5 of 7 with 1 BackfillType op TemporaryIndexID: 3 PostCommitPhase stage 6 of 7 with 1 ValidationType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -766,10 +641,13 @@ PostCommitPhase stage 7 of 7 with 10 MutationType ops [[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}, PUBLIC], VALIDATED] -> 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 [[Column:{DescID: 104, ColumnID: 3}, PUBLIC], WRITE_ONLY] -> PUBLIC ops: + *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly + IndexID: 1 + TableID: 104 *scop.SetIndexName IndexID: 1 Name: crdb_internal_index_1_name_placeholder @@ -778,9 +656,6 @@ PostCommitPhase stage 7 of 7 with 10 MutationType ops IndexID: 2 Name: foo_pkey TableID: 104 - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 *scop.MakeAddedPrimaryIndexPublic EventBase: Authorization: @@ -824,11 +699,16 @@ PostCommitPhase stage 7 of 7 with 10 MutationType ops *scop.UpdateSchemaChangerJob IsNonCancelable: true JobID: 1 -PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops +PostCommitNonRevertiblePhase stage 1 of 2 with 5 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}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_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 @@ -843,7 +723,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops PostCommitNonRevertiblePhase stage 2 of 2 with 6 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT ops: *scop.CreateGcJobForIndex IndexID: 1 @@ -877,13 +757,17 @@ PostCommitNonRevertiblePhase stage 2 of 2 with 6 MutationType ops ops ALTER TABLE defaultdb.foo ADD COLUMN a INT AS (i+1) STORED ---- -StatementPhase stage 1 of 1 with 6 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 - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[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 ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -927,13 +811,7 @@ StatementPhase stage 1 of 1 with 6 MutationType ops ConstraintID: 1 IndexID: 2 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 TableID: 104 TemporaryIndexID: 3 *scop.MakeAddedTempIndexDeleteOnly @@ -941,14 +819,26 @@ StatementPhase stage 1 of 1 with 6 MutationType ops ConstraintID: 1 IndexID: 3 IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 SourceIndexID: 1 - StoringColumnIDs: - - 2 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 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 2 MutationType ops transitions: ops: @@ -970,7 +860,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops PostCommitPhase stage 1 of 7 with 4 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 2}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedColumnDeleteAndWriteOnly ColumnID: 2 @@ -984,7 +874,7 @@ PostCommitPhase stage 1 of 7 with 4 MutationType ops JobID: 1 PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: *scop.BackfillIndex IndexID: 2 @@ -992,7 +882,7 @@ PostCommitPhase stage 2 of 7 with 1 BackfillType op TableID: 104 PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILLED] -> DELETE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: *scop.MakeBackfillingIndexDeleteOnly IndexID: 2 @@ -1003,7 +893,7 @@ PostCommitPhase stage 3 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 2 @@ -1014,7 +904,7 @@ PostCommitPhase stage 4 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGE_ONLY] -> MERGED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: *scop.MergeIndex BackfilledIndexID: 2 @@ -1022,7 +912,7 @@ PostCommitPhase stage 5 of 7 with 1 BackfillType op TemporaryIndexID: 3 PostCommitPhase stage 6 of 7 with 1 ValidationType op transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], MERGED] -> VALIDATED + [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 @@ -1032,9 +922,12 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops [[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}, PUBLIC], VALIDATED] -> 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 @@ -1043,9 +936,6 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops IndexID: 2 Name: foo_pkey TableID: 104 - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 *scop.MakeAddedPrimaryIndexPublic EventBase: Authorization: @@ -1077,11 +967,16 @@ PostCommitPhase stage 7 of 7 with 8 MutationType ops *scop.UpdateSchemaChangerJob IsNonCancelable: true JobID: 1 -PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops +PostCommitNonRevertiblePhase stage 1 of 2 with 5 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}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_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 @@ -1096,7 +991,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops PostCommitNonRevertiblePhase stage 2 of 2 with 6 MutationType ops transitions: [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT ops: *scop.CreateGcJobForIndex IndexID: 1 @@ -1137,18 +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 12 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 - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[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 - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[IndexColumn:{DescID: 107, ColumnID: 3, IndexID: 1}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedColumnDeleteOnly Column: @@ -1184,33 +1077,11 @@ StatementPhase stage 1 of 1 with 12 MutationType ops family: IntFamily oid: 20 width: 64 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 - SourceIndexID: 1 - StoringColumnIDs: - - 2 - TableID: 104 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 1 - SourceIndexID: 1 - StoringColumnIDs: - - 2 - TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 1 + Kind: 2 + TableID: 104 *scop.MakeAddedColumnDeleteOnly Column: ColumnID: 3 @@ -1246,35 +1117,12 @@ StatementPhase stage 1 of 1 with 12 MutationType ops family: IntFamily oid: 20 width: 64 - *scop.MakeAddedIndexBackfilling - Index: - ConstraintID: 1 - IndexID: 2 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 2 - SourceIndexID: 1 - StoringColumnIDs: - - 1 - - 3 - TableID: 107 - TemporaryIndexID: 3 - *scop.MakeAddedTempIndexDeleteOnly - Index: - ConstraintID: 1 - IndexID: 3 - IsUnique: true - KeyColumnDirections: - - 0 - KeyColumnIDs: - - 2 - SourceIndexID: 1 - StoringColumnIDs: - - 1 - - 3 - TableID: 107 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 1 + Kind: 2 + Ordinal: 1 + TableID: 107 PreCommitPhase stage 1 of 1 with 3 MutationType ops transitions: ops: @@ -1291,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 @@ -1299,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}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY [[Column:{DescID: 107, ColumnID: 3}, PUBLIC], DELETE_ONLY] -> WRITE_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3}, 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 +PostCommitPhase stage 2 of 2 with 7 MutationType ops transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], BACKFILLED] -> DELETE_ONLY - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], MERGE_ONLY] -> MERGED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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}, PUBLIC], MERGED] -> VALIDATED - [[PrimaryIndex:{DescID: 107, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}, 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 - 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}, 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}, PUBLIC], VALIDATED] -> PUBLIC - [[IndexName:{DescID: 107, Name: bar_pkey, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *scop.SetIndexName - IndexID: 1 - Name: crdb_internal_index_1_name_placeholder - TableID: 104 - *scop.SetIndexName - IndexID: 2 - Name: foo_pkey - TableID: 104 - *scop.SetIndexName - IndexID: 1 - Name: crdb_internal_index_1_name_placeholder - TableID: 107 - *scop.SetIndexName - IndexID: 2 - Name: bar_pkey - TableID: 107 - *scop.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 104 - *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.MakeDroppedPrimaryIndexDeleteAndWriteOnly - IndexID: 1 - TableID: 107 - *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: @@ -1480,92 +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 7 MutationType ops - transitions: - [[PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], VALIDATED] -> DELETE_ONLY - [[TemporaryIndex:{DescID: 107, IndexID: 3}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY - ops: - *scop.MakeDroppedIndexDeleteOnly - IndexID: 3 - TableID: 104 - *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}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT - [[PrimaryIndex:{DescID: 107, IndexID: 1, ConstraintID: 1}, ABSENT], DELETE_ONLY] -> ABSENT - [[TemporaryIndex:{DescID: 107, IndexID: 3}, 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/scplan/testdata/create_index b/pkg/sql/schemachanger/scplan/testdata/create_index index ef4508842dc8..354a1d9e9258 100644 --- a/pkg/sql/schemachanger/scplan/testdata/create_index +++ b/pkg/sql/schemachanger/scplan/testdata/create_index @@ -5,40 +5,58 @@ CREATE TABLE defaultdb.t1 (id INT PRIMARY KEY, name varchar(256), money int) ops CREATE INDEX id1 ON defaultdb.t1 (id, name) STORING (money) ---- -StatementPhase stage 1 of 1 with 2 MutationType ops +StatementPhase stage 1 of 1 with 8 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, 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: 3, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedIndexBackfilling Index: IndexID: 2 - KeyColumnDirections: - - 0 - - 0 - KeyColumnIDs: - - 1 - - 2 SourceIndexID: 1 - StoringColumnIDs: - - 3 TableID: 104 TemporaryIndexID: 3 IsSecondaryIndex: true *scop.MakeAddedTempIndexDeleteOnly Index: IndexID: 3 - KeyColumnDirections: - - 0 - - 0 - KeyColumnIDs: - - 1 - - 2 SourceIndexID: 1 - StoringColumnIDs: - - 3 TableID: 104 IsSecondaryIndex: true + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 3 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 3 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 3 + Kind: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 2 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 2 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 2 MutationType ops transitions: ops: @@ -59,7 +77,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops statementtag: CREATE INDEX PostCommitPhase stage 1 of 7 with 3 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 3 @@ -70,7 +88,7 @@ PostCommitPhase stage 1 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: *scop.BackfillIndex IndexID: 2 @@ -78,7 +96,7 @@ PostCommitPhase stage 2 of 7 with 1 BackfillType op TableID: 104 PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], BACKFILLED] -> DELETE_ONLY + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: *scop.MakeBackfillingIndexDeleteOnly IndexID: 2 @@ -89,7 +107,7 @@ PostCommitPhase stage 3 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 2 @@ -100,7 +118,7 @@ PostCommitPhase stage 4 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], MERGE_ONLY] -> MERGED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: *scop.MergeIndex BackfilledIndexID: 2 @@ -108,14 +126,14 @@ PostCommitPhase stage 5 of 7 with 1 BackfillType op TemporaryIndexID: 3 PostCommitPhase stage 6 of 7 with 1 ValidationType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], MERGED] -> VALIDATED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 TableID: 104 PostCommitPhase stage 7 of 7 with 4 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], VALIDATED] -> PUBLIC + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], VALIDATED] -> PUBLIC [[IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.SetIndexName @@ -132,7 +150,7 @@ PostCommitPhase stage 7 of 7 with 4 MutationType ops JobID: 1 PostCommitNonRevertiblePhase stage 1 of 2 with 3 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY ops: *scop.MakeDroppedIndexDeleteOnly IndexID: 3 @@ -144,7 +162,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 3 MutationType ops JobID: 1 PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT ops: *scop.CreateGcJobForIndex IndexID: 3 @@ -163,40 +181,62 @@ deps CREATE INDEX id1 ON defaultdb.t1 (id, name) STORING (money) ---- - from: [IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC] - to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC] + to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC] kind: SameStagePrecedence rule: index named right before index becomes public -- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, BACKFILL_ONLY] +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] to: [IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC] kind: Precedence - rule: index existence precedes index dependents -- from: [TemporaryIndex:{DescID: 104, IndexID: 3}, WRITE_ONLY] - to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, BACKFILLED] + rule: index existence precedes index name and comment +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, WRITE_ONLY] + to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILLED] kind: Precedence rule: temp index is WRITE_ONLY before backfill ops CREATE INVERTED INDEX CONCURRENTLY id1 ON defaultdb.t1 (id, name) STORING (money) ---- -StatementPhase stage 1 of 1 with 2 MutationType ops +StatementPhase stage 1 of 1 with 8 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], ABSENT] -> BACKFILL_ONLY - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], ABSENT] -> DELETE_ONLY + [[IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, 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: 3, IndexID: 3}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.MakeAddedIndexBackfilling Index: IndexID: 2 IsConcurrently: true IsInverted: true - KeyColumnDirections: - - 0 - - 0 - KeyColumnIDs: - - 1 - - 2 SourceIndexID: 1 - StoringColumnIDs: - - 3 TableID: 104 TemporaryIndexID: 3 IsSecondaryIndex: true @@ -205,17 +245,37 @@ StatementPhase stage 1 of 1 with 2 MutationType ops IndexID: 3 IsConcurrently: true IsInverted: true - KeyColumnDirections: - - 0 - - 0 - KeyColumnIDs: - - 1 - - 2 SourceIndexID: 1 - StoringColumnIDs: - - 3 TableID: 104 IsSecondaryIndex: true + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 3 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 3 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 3 + Kind: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 1 + IndexID: 2 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 2 + IndexID: 2 + Ordinal: 1 + TableID: 104 + scop.AddColumnToIndex + ColumnID: 3 + IndexID: 2 + Kind: 2 + TableID: 104 PreCommitPhase stage 1 of 1 with 2 MutationType ops transitions: ops: @@ -237,7 +297,7 @@ PreCommitPhase stage 1 of 1 with 2 MutationType ops statementtag: CREATE INDEX PostCommitPhase stage 1 of 7 with 3 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], DELETE_ONLY] -> WRITE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 3 @@ -248,7 +308,7 @@ PostCommitPhase stage 1 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 2 of 7 with 1 BackfillType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILL_ONLY] -> BACKFILLED ops: *scop.BackfillIndex IndexID: 2 @@ -256,7 +316,7 @@ PostCommitPhase stage 2 of 7 with 1 BackfillType op TableID: 104 PostCommitPhase stage 3 of 7 with 3 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], BACKFILLED] -> DELETE_ONLY + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], BACKFILLED] -> DELETE_ONLY ops: *scop.MakeBackfillingIndexDeleteOnly IndexID: 2 @@ -267,7 +327,7 @@ PostCommitPhase stage 3 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 4 of 7 with 3 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], DELETE_ONLY] -> MERGE_ONLY ops: *scop.MakeAddedIndexDeleteAndWriteOnly IndexID: 2 @@ -278,7 +338,7 @@ PostCommitPhase stage 4 of 7 with 3 MutationType ops JobID: 1 PostCommitPhase stage 5 of 7 with 1 BackfillType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], MERGE_ONLY] -> MERGED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGE_ONLY] -> MERGED ops: *scop.MergeIndex BackfilledIndexID: 2 @@ -286,14 +346,14 @@ PostCommitPhase stage 5 of 7 with 1 BackfillType op TemporaryIndexID: 3 PostCommitPhase stage 6 of 7 with 1 ValidationType op transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], MERGED] -> VALIDATED + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], MERGED] -> VALIDATED ops: *scop.ValidateUniqueIndex IndexID: 2 TableID: 104 PostCommitPhase stage 7 of 7 with 4 MutationType ops transitions: - [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC], VALIDATED] -> PUBLIC + [[SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC], VALIDATED] -> PUBLIC [[IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.SetIndexName @@ -310,7 +370,7 @@ PostCommitPhase stage 7 of 7 with 4 MutationType ops JobID: 1 PostCommitNonRevertiblePhase stage 1 of 2 with 3 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], WRITE_ONLY] -> TRANSIENT_DELETE_ONLY ops: *scop.MakeDroppedIndexDeleteOnly IndexID: 3 @@ -322,7 +382,7 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 3 MutationType ops JobID: 1 PostCommitNonRevertiblePhase stage 2 of 2 with 4 MutationType ops transitions: - [[TemporaryIndex:{DescID: 104, IndexID: 3}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT + [[TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, TRANSIENT_ABSENT], TRANSIENT_DELETE_ONLY] -> TRANSIENT_ABSENT ops: *scop.CreateGcJobForIndex IndexID: 3 @@ -341,14 +401,38 @@ deps CREATE INDEX id1 ON defaultdb.t1 (id, name) STORING (money) ---- - from: [IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC] - to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, PUBLIC] + to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, PUBLIC] kind: SameStagePrecedence rule: index named right before index becomes public -- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, BACKFILL_ONLY] +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after index exists +- from: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILL_ONLY] to: [IndexName:{DescID: 104, Name: id1, IndexID: 2}, PUBLIC] kind: Precedence - rule: index existence precedes index dependents -- from: [TemporaryIndex:{DescID: 104, IndexID: 3}, WRITE_ONLY] - to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3}, BACKFILLED] + rule: index existence precedes index name and comment +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, DELETE_ONLY] + to: [IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}, PUBLIC] + kind: SameStagePrecedence + rule: index-column added to index after temp index exists +- from: [TemporaryIndex:{DescID: 104, IndexID: 3, SourceIndexID: 1}, WRITE_ONLY] + to: [SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}, BACKFILLED] kind: Precedence rule: temp index is WRITE_ONLY before backfill diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_database b/pkg/sql/schemachanger/scplan/testdata/drop_database index 294dcf3dd7f1..6f2f54b8bb11 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_database +++ b/pkg/sql/schemachanger/scplan/testdata/drop_database @@ -72,6 +72,9 @@ StatementPhase stage 1 of 1 with 53 MutationType ops [[Column:{DescID: 110, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 110, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT [[ColumnType:{DescID: 110, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 110, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 110, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 110, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 110, Name: t1_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Namespace:{DescID: 108, Name: sq1, ReferencedDescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -104,6 +107,9 @@ StatementPhase stage 1 of 1 with 53 MutationType ops [[Column:{DescID: 109, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 109, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 109, Name: t1_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Namespace:{DescID: 111, Name: v1, ReferencedDescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -1781,22 +1787,70 @@ DROP DATABASE db1 CASCADE to: [UserPrivileges:{DescID: 115, Name: root}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal -- from: [IndexName:{DescID: 109, Name: t1_pkey, IndexID: 1}, ABSENT] +- from: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] kind: Precedence rule: dependents removed before index +- from: [IndexColumn:{DescID: 110, ColumnID: 1, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 110, ColumnID: 2, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 110, ColumnID: 3, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index - from: [IndexName:{DescID: 109, Name: t1_pkey, IndexID: 1}, ABSENT] - to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index - from: [IndexName:{DescID: 110, Name: t1_pkey, IndexID: 1}, ABSENT] to: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, ABSENT] kind: Precedence rule: dependents removed before index -- from: [IndexName:{DescID: 110, Name: t1_pkey, IndexID: 1}, ABSENT] - to: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexName:{DescID: 109, Name: t1_pkey, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 110, ColumnID: 1, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 110, ColumnID: 2, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 110, ColumnID: 3, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 110, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexName:{DescID: 110, Name: t1_pkey, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed - from: [Schema:{DescID: 105}, DROPPED] to: [Namespace:{DescID: 105, Name: public, ReferencedDescID: 104}, ABSENT] kind: SameStagePrecedence @@ -2009,6 +2063,18 @@ DROP DATABASE db1 CASCADE to: [ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal - from: [Table:{DescID: 109}, DROPPED] to: [IndexName:{DescID: 109, Name: t1_pkey, IndexID: 1}, ABSENT] kind: SameStagePrecedence @@ -2109,6 +2175,18 @@ DROP DATABASE db1 CASCADE to: [ColumnType:{DescID: 110, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 110}, DROPPED] + to: [IndexColumn:{DescID: 110, ColumnID: 1, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 110}, DROPPED] + to: [IndexColumn:{DescID: 110, ColumnID: 2, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 110}, DROPPED] + to: [IndexColumn:{DescID: 110, ColumnID: 3, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal - from: [Table:{DescID: 110}, DROPPED] to: [IndexName:{DescID: 110, Name: t1_pkey, IndexID: 1}, ABSENT] kind: SameStagePrecedence diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_schema b/pkg/sql/schemachanger/scplan/testdata/drop_schema index d89933dae0b7..6d20be0f9c30 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_schema +++ b/pkg/sql/schemachanger/scplan/testdata/drop_schema @@ -467,14 +467,38 @@ DROP SCHEMA defaultdb.SC1 CASCADE to: [UserPrivileges:{DescID: 111, Name: root}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal -- from: [IndexName:{DescID: 106, Name: t1_pkey, IndexID: 1}, ABSENT] +- from: [IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1}, ABSENT] to: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, ABSENT] kind: Precedence rule: dependents removed before index - from: [IndexName:{DescID: 106, Name: t1_pkey, IndexID: 1}, ABSENT] - to: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public + to: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexName:{DescID: 106, Name: t1_pkey, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed - from: [Schema:{DescID: 104}, DROPPED] to: [Namespace:{DescID: 104, Name: sc1, ReferencedDescID: 100}, ABSENT] kind: SameStagePrecedence @@ -631,6 +655,18 @@ DROP SCHEMA defaultdb.SC1 CASCADE to: [ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967295}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 106}, DROPPED] + to: [IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 106}, DROPPED] + to: [IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 106}, DROPPED] + to: [IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal - from: [Table:{DescID: 106}, DROPPED] to: [IndexName:{DescID: 106, Name: t1_pkey, IndexID: 1}, ABSENT] kind: SameStagePrecedence @@ -1042,6 +1078,9 @@ StatementPhase stage 1 of 1 with 37 MutationType ops [[Column:{DescID: 106, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 106, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT [[ColumnType:{DescID: 106, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 106, Name: t1_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[Namespace:{DescID: 107, Name: v1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_table b/pkg/sql/schemachanger/scplan/testdata/drop_table index b5f23c9a47a8..a388dde97d69 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_table +++ b/pkg/sql/schemachanger/scplan/testdata/drop_table @@ -64,9 +64,17 @@ StatementPhase stage 1 of 1 with 23 MutationType ops [[Column:{DescID: 109, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 109, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT [[ColumnType:{DescID: 109, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 5, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 109, Name: shipments_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT [[SecondaryIndexPartial:{DescID: 109, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT [[SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 109, Name: partialidx, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT @@ -642,38 +650,102 @@ DROP TABLE defaultdb.shipments CASCADE; to: [Column:{DescID: 111, ColumnID: 4294967295}, ABSENT] kind: Precedence rule: dependents removed before column -- from: [IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT] +- from: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 2}, ABSENT] + to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 2}, ABSENT] + to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 1}, ABSENT] + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 2}, ABSENT] + to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT] + kind: Precedence + rule: dependents removed before index +- from: [IndexColumn:{DescID: 109, ColumnID: 5, IndexID: 1}, ABSENT] to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] kind: Precedence rule: dependents removed before index - from: [IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT] - to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public + to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] + kind: Precedence + rule: dependents removed before index - from: [IndexName:{DescID: 109, Name: partialidx, IndexID: 2}, ABSENT] to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT] kind: Precedence rule: dependents removed before index -- from: [IndexName:{DescID: 109, Name: partialidx, IndexID: 2}, ABSENT] - to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public - from: [IndexName:{DescID: 109, Name: shipments_pkey, IndexID: 1}, ABSENT] to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, ABSENT] kind: Precedence rule: dependents removed before index -- from: [IndexName:{DescID: 109, Name: shipments_pkey, IndexID: 1}, ABSENT] - to: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 5, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [PrimaryIndex:{DescID: 109, IndexID: 1, ConstraintID: 1}, VALIDATED] + to: [IndexName:{DescID: 109, Name: shipments_pkey, IndexID: 1}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 2}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 2}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] + to: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 2}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] + to: [IndexName:{DescID: 109, Name: partialidx, IndexID: 2}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed +- from: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] + to: [SecondaryIndexPartial:{DescID: 109, IndexID: 2}, ABSENT] + kind: Precedence + rule: index no longer public before dependents removed - from: [SecondaryIndexPartial:{DescID: 109, IndexID: 2}, ABSENT] to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, ABSENT] kind: Precedence rule: dependents removed before index -- from: [SecondaryIndexPartial:{DescID: 109, IndexID: 2}, ABSENT] - to: [SecondaryIndex:{DescID: 109, IndexID: 2, ConstraintID: 0}, VALIDATED] - kind: SameStagePrecedence - rule: dependents removed after index no longer public - from: [Sequence:{DescID: 110}, DROPPED] to: [Namespace:{DescID: 110, Name: sq1, ReferencedDescID: 100}, ABSENT] kind: SameStagePrecedence @@ -830,6 +902,38 @@ DROP TABLE defaultdb.shipments CASCADE; to: [ForeignKeyConstraint:{DescID: 109, ConstraintID: 3, ReferencedDescID: 105}, ABSENT] kind: SameStagePrecedence rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 2}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 2, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 3, IndexID: 2}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 4, IndexID: 2}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal +- from: [Table:{DescID: 109}, DROPPED] + to: [IndexColumn:{DescID: 109, ColumnID: 5, IndexID: 1}, ABSENT] + kind: SameStagePrecedence + rule: descriptor drop right before dependent element removal - from: [Table:{DescID: 109}, DROPPED] to: [IndexComment:{DescID: 109, IndexID: 1, Comment: pkey is good}, ABSENT] kind: SameStagePrecedence @@ -982,8 +1086,13 @@ StatementPhase stage 1 of 1 with 12 MutationType ops [[Column:{DescID: 114, ColumnID: 4294967294}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 114, Name: tableoid, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT [[ColumnType:{DescID: 114, ColumnFamilyID: 0, ColumnID: 4294967294}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 114, ColumnID: 3, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 114, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 114, ColumnID: 2, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT [[PrimaryIndex:{DescID: 114, IndexID: 1, ConstraintID: 1}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 114, Name: greeter_pkey, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 114, ColumnID: 2, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT + [[IndexColumn:{DescID: 114, ColumnID: 3, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT [[SecondaryIndexPartial:{DescID: 114, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT [[SecondaryIndex:{DescID: 114, IndexID: 2, ConstraintID: 0}, ABSENT], PUBLIC] -> VALIDATED [[IndexName:{DescID: 114, Name: i, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT diff --git a/pkg/sql/schemachanger/screl/attr.go b/pkg/sql/schemachanger/screl/attr.go index 03409bf72581..d0a1f03164ad 100644 --- a/pkg/sql/schemachanger/screl/attr.go +++ b/pkg/sql/schemachanger/screl/attr.go @@ -65,6 +65,9 @@ const ( // TemporaryIndexID is the index ID of the temporary index being populated // during this index's backfill. TemporaryIndexID + // SourceIndexID is the index ID of the source index for a newly created + // index. + SourceIndexID // TargetStatus is the target status of an element. TargetStatus @@ -132,16 +135,19 @@ var elementSchemaOptions = []rel.SchemaOption{ rel.EntityAttr(IndexID, "IndexID"), rel.EntityAttr(ConstraintID, "ConstraintID"), rel.EntityAttr(TemporaryIndexID, "TemporaryIndexID"), + rel.EntityAttr(SourceIndexID, "SourceIndexID"), ), rel.EntityMapping(t((*scpb.SecondaryIndex)(nil)), rel.EntityAttr(DescID, "TableID"), rel.EntityAttr(IndexID, "IndexID"), rel.EntityAttr(ConstraintID, "ConstraintID"), rel.EntityAttr(TemporaryIndexID, "TemporaryIndexID"), + rel.EntityAttr(SourceIndexID, "SourceIndexID"), ), rel.EntityMapping(t((*scpb.TemporaryIndex)(nil)), rel.EntityAttr(DescID, "TableID"), rel.EntityAttr(IndexID, "IndexID"), + rel.EntityAttr(SourceIndexID, "SourceIndexID"), ), rel.EntityMapping(t((*scpb.UniqueWithoutIndexConstraint)(nil)), rel.EntityAttr(DescID, "TableID"), @@ -276,6 +282,11 @@ var elementSchemaOptions = []rel.SchemaOption{ rel.EntityAttr(ConstraintID, "ConstraintID"), rel.EntityAttr(Comment, "Comment"), ), + rel.EntityMapping(t((*scpb.IndexColumn)(nil)), + rel.EntityAttr(DescID, "TableID"), + rel.EntityAttr(IndexID, "IndexID"), + rel.EntityAttr(ColumnID, "ColumnID"), + ), } // Schema is the schema exported by this package covering the elements of scpb. diff --git a/pkg/sql/schemachanger/screl/attr_string.go b/pkg/sql/schemachanger/screl/attr_string.go index a4211a0db15e..23c2b7569954 100644 --- a/pkg/sql/schemachanger/screl/attr_string.go +++ b/pkg/sql/schemachanger/screl/attr_string.go @@ -17,15 +17,16 @@ func _() { _ = x[ReferencedDescID-7] _ = x[Comment-8] _ = x[TemporaryIndexID-9] - _ = x[TargetStatus-10] - _ = x[CurrentStatus-11] - _ = x[Element-12] - _ = x[Target-13] + _ = x[SourceIndexID-10] + _ = x[TargetStatus-11] + _ = x[CurrentStatus-12] + _ = x[Element-13] + _ = x[Target-14] } -const _Attr_name = "DescIDIndexIDColumnFamilyIDColumnIDConstraintIDNameReferencedDescIDCommentTemporaryIndexIDTargetStatusCurrentStatusElementTarget" +const _Attr_name = "DescIDIndexIDColumnFamilyIDColumnIDConstraintIDNameReferencedDescIDCommentTemporaryIndexIDSourceIndexIDTargetStatusCurrentStatusElementTarget" -var _Attr_index = [...]uint8{0, 6, 13, 27, 35, 47, 51, 67, 74, 90, 102, 115, 122, 128} +var _Attr_index = [...]uint8{0, 6, 13, 27, 35, 47, 51, 67, 74, 90, 103, 115, 128, 135, 141} func (i Attr) String() string { i -= 1 diff --git a/pkg/sql/schemachanger/screl/format.go b/pkg/sql/schemachanger/screl/format.go index 3ba5f3300094..181f0d6f8712 100644 --- a/pkg/sql/schemachanger/screl/format.go +++ b/pkg/sql/schemachanger/screl/format.go @@ -63,8 +63,11 @@ func FormatElement(w redact.SafeWriter, e scpb.Element) (err error) { w.SafeString(":{") var written int if err := Schema.IterateAttributes(e, func(attr rel.Attr, value interface{}) error { - if attr == TemporaryIndexID && value == descpb.IndexID(0) { - return nil + switch attr { + case TemporaryIndexID, SourceIndexID: + if value == descpb.IndexID(0) { + return nil + } } if written > 0 { w.SafeString(", ") diff --git a/pkg/sql/schemachanger/testdata/alter_table_add_column b/pkg/sql/schemachanger/testdata/alter_table_add_column index 632c1fe7e6a0..96bb87893fdd 100644 --- a/pkg/sql/schemachanger/testdata/alter_table_add_column +++ b/pkg/sql/schemachanger/testdata/alter_table_add_column @@ -20,7 +20,7 @@ increment telemetry for sql.schema.qualifcation.default_expr increment telemetry for sql.schema.new_column_type.int8 begin transaction #1 # begin StatementPhase -## StatementPhase stage 1 of 1 with 7 MutationType ops +## StatementPhase stage 1 of 1 with 11 MutationType ops upsert descriptor #106 ... - columnIds: @@ -131,13 +131,18 @@ upsert descriptor #106 + currentStatuses: + - PUBLIC + - PUBLIC + + - PUBLIC + - DELETE_ONLY + - PUBLIC + - PUBLIC + - PUBLIC + + - PUBLIC + + - PUBLIC + - BACKFILL_ONLY + - ABSENT + - DELETE_ONLY + + - PUBLIC + + - PUBLIC + jobId: "1" + relevantStatements: + - statement: @@ -156,17 +161,27 @@ upsert descriptor #106 + - 6 + - 7 + - 8 + + - 9 + + - 10 + + - 11 + + - 12 + + - 13 + targets: + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + tableId: 106 + metadata: + sourceElementId: 1 @@ -223,18 +238,31 @@ upsert descriptor #106 + subWorkId: 1 + targetStatus: PUBLIC + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 2 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 2 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 1 - + storingColumnIds: - + - 2 + tableId: 106 + temporaryIndexId: 3 + metadata: @@ -256,18 +284,31 @@ upsert descriptor #106 + constraintId: 1 + indexId: 3 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 1 - + storingColumnIds: - + - 2 + tableId: 106 + metadata: + sourceElementId: 1 + subWorkId: 1 + targetStatus: TRANSIENT_ABSENT + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 3 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 3 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC families: - columnIds: ... @@ -302,8 +343,8 @@ upsert descriptor #106 - ABSENT - - DELETE_ONLY + - WRITE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -426,8 +467,8 @@ upsert descriptor #106 createAsOfTime: wallTime: "1640995200000000000" ... - userName: root currentStatuses: + - PUBLIC + - VALIDATED + - ABSENT - PUBLIC @@ -435,12 +476,14 @@ upsert descriptor #106 - - WRITE_ONLY - PUBLIC - PUBLIC + ... + - PUBLIC - PUBLIC - - MERGE_ONLY - - ABSENT + - PUBLIC - WRITE_ONLY - jobId: "1" + - PUBLIC ... statement: ALTER TABLE db.public.tbl ADD COLUMN j INT8 NOT NULL DEFAULT 42 statementTag: ALTER TABLE @@ -550,26 +593,29 @@ upsert descriptor #106 - version: "5" + version: "6" adding table for stats refresh: 106 -update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 2 MutationType ops pending" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 3 MutationType ops pending" set schema change job #1 to non-cancellable commit transaction #9 begin transaction #10 -## PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 2 with 5 MutationType ops upsert descriptor #106 ... userName: root currentStatuses: + - - PUBLIC - - VALIDATED - + - DELETE_ONLY - ABSENT + + - DELETE_ONLY + + - ABSENT + - PUBLIC - PUBLIC ... - PUBLIC - PUBLIC - - WRITE_ONLY + - TRANSIENT_DELETE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -577,7 +623,10 @@ upsert descriptor #106 - wallTime: "1640995200000000009" + modificationTime: {} mutations: - - direction: ADD + - - direction: ADD + + - direction: DROP + index: + constraintId: 3 ... version: 4 mutationId: 1 @@ -609,6 +658,7 @@ upsert descriptor #106 - authorization: - userName: root - currentStatuses: + - - ABSENT - - DELETE_ONLY - - ABSENT - - PUBLIC @@ -617,7 +667,11 @@ upsert descriptor #106 - - PUBLIC - - PUBLIC - - PUBLIC + - - PUBLIC + - - PUBLIC - - TRANSIENT_DELETE_ONLY + - - PUBLIC + - - PUBLIC - jobId: "1" - relevantStatements: - - statement: @@ -635,17 +689,27 @@ upsert descriptor #106 - - 6 - - 7 - - 8 + - - 9 + - - 10 + - - 11 + - - 12 + - - 13 - targets: - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - tableId: 106 - metadata: - sourceElementId: 1 @@ -702,18 +766,31 @@ upsert descriptor #106 - subWorkId: 1 - targetStatus: PUBLIC - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 2 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 2 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 1 - - storingColumnIds: - - - 2 - tableId: 106 - temporaryIndexId: 3 - metadata: @@ -735,18 +812,31 @@ upsert descriptor #106 - constraintId: 1 - indexId: 3 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 1 - - storingColumnIds: - - - 2 - tableId: 106 - metadata: - sourceElementId: 1 - subWorkId: 1 - targetStatus: TRANSIENT_ABSENT + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 3 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 3 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC families: - columnIds: ... @@ -755,7 +845,7 @@ upsert descriptor #106 - modificationTime: - wallTime: "1640995200000000010" - mutations: - - - direction: ADD + - - direction: DROP - index: - constraintId: 3 - createdExplicitly: true @@ -831,7 +921,7 @@ increment telemetry for sql.schema.qualifcation.default_expr increment telemetry for sql.schema.new_column_type.int8 begin transaction #1 # begin StatementPhase -## StatementPhase stage 1 of 1 with 7 MutationType ops +## StatementPhase stage 1 of 1 with 13 MutationType ops upsert descriptor #106 ... - 1 @@ -947,13 +1037,21 @@ upsert descriptor #106 + currentStatuses: + - PUBLIC + - PUBLIC + + - PUBLIC + + - PUBLIC + - DELETE_ONLY + - PUBLIC + - PUBLIC + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + - BACKFILL_ONLY + - ABSENT + - DELETE_ONLY + + - PUBLIC + + - PUBLIC + + - PUBLIC + jobId: "1" + relevantStatements: + - statement: @@ -972,20 +1070,41 @@ upsert descriptor #106 + - 6 + - 7 + - 8 + + - 9 + + - 10 + + - 11 + + - 12 + + - 13 + + - 14 + + - 15 + + - 16 + targets: + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 2 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 2 + indexId: 2 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 - + storingColumnIds: - + - 2 + tableId: 106 + metadata: + sourceElementId: 1 @@ -1042,20 +1161,43 @@ upsert descriptor #106 + subWorkId: 1 + targetStatus: PUBLIC + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 4 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 4 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 4 + + kind: STORED + + ordinalInKind: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 2 + indexId: 4 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 2 - + storingColumnIds: - + - 2 - + - 3 + tableId: 106 + temporaryIndexId: 5 + metadata: @@ -1078,19 +1220,42 @@ upsert descriptor #106 + indexId: 5 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 2 - + storingColumnIds: - + - 2 - + - 3 + tableId: 106 + metadata: + sourceElementId: 1 + subWorkId: 1 + targetStatus: TRANSIENT_ABSENT + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 5 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 5 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 5 + + kind: STORED + + ordinalInKind: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC families: - columnIds: ... @@ -1125,8 +1290,8 @@ upsert descriptor #106 - ABSENT - - DELETE_ONLY + - WRITE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -1249,8 +1414,8 @@ upsert descriptor #106 createAsOfTime: wallTime: "1640995200000000000" ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC + - VALIDATED + - ABSENT - PUBLIC @@ -1258,12 +1423,14 @@ upsert descriptor #106 - - WRITE_ONLY - PUBLIC - PUBLIC + ... + - PUBLIC - PUBLIC - - MERGE_ONLY - - ABSENT + - PUBLIC - WRITE_ONLY - jobId: "1" + - PUBLIC ... statement: ALTER TABLE db.public.tbl ADD COLUMN k INT8 NOT NULL DEFAULT 42 statementTag: ALTER TABLE @@ -1373,26 +1540,31 @@ upsert descriptor #106 - version: "12" + version: "13" adding table for stats refresh: 106 -update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 2 MutationType ops pending" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops pending" set schema change job #1 to non-cancellable commit transaction #9 begin transaction #10 -## PostCommitNonRevertiblePhase stage 1 of 2 with 4 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 2 with 6 MutationType ops upsert descriptor #106 ... userName: root currentStatuses: + - - PUBLIC + - - PUBLIC - - VALIDATED - + - DELETE_ONLY - ABSENT + + - ABSENT + + - DELETE_ONLY + + - ABSENT + - PUBLIC - PUBLIC ... - PUBLIC - PUBLIC - - WRITE_ONLY + - TRANSIENT_DELETE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -1400,7 +1572,10 @@ upsert descriptor #106 - wallTime: "1640995200000000009" + modificationTime: {} mutations: - - direction: ADD + - - direction: ADD + + - direction: DROP + index: + constraintId: 5 ... version: 4 mutationId: 1 @@ -1432,6 +1607,8 @@ upsert descriptor #106 - authorization: - userName: root - currentStatuses: + - - ABSENT + - - ABSENT - - DELETE_ONLY - - ABSENT - - PUBLIC @@ -1440,7 +1617,13 @@ upsert descriptor #106 - - PUBLIC - - PUBLIC - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC - - TRANSIENT_DELETE_ONLY + - - PUBLIC + - - PUBLIC + - - PUBLIC - jobId: "1" - relevantStatements: - - statement: @@ -1458,20 +1641,41 @@ upsert descriptor #106 - - 6 - - 7 - - 8 + - - 9 + - - 10 + - - 11 + - - 12 + - - 13 + - - 14 + - - 15 + - - 16 - targets: - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 2 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 2 - indexId: 2 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - - storingColumnIds: - - - 2 - tableId: 106 - metadata: - sourceElementId: 1 @@ -1528,20 +1732,43 @@ upsert descriptor #106 - subWorkId: 1 - targetStatus: PUBLIC - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 4 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 4 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 4 + - kind: STORED + - ordinalInKind: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 2 - indexId: 4 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 2 - - storingColumnIds: - - - 2 - - - 3 - tableId: 106 - temporaryIndexId: 5 - metadata: @@ -1564,19 +1791,42 @@ upsert descriptor #106 - indexId: 5 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 2 - - storingColumnIds: - - - 2 - - - 3 - tableId: 106 - metadata: - sourceElementId: 1 - subWorkId: 1 - targetStatus: TRANSIENT_ABSENT + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 5 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 5 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 5 + - kind: STORED + - ordinalInKind: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC families: - columnIds: ... @@ -1585,7 +1835,7 @@ upsert descriptor #106 - modificationTime: - wallTime: "1640995200000000010" - mutations: - - - direction: ADD + - - direction: DROP - index: - constraintId: 5 - createdExplicitly: true @@ -1668,7 +1918,7 @@ increment telemetry for sql.schema.qualifcation.default_expr increment telemetry for sql.schema.new_column_type.int8 begin transaction #1 # begin StatementPhase -## StatementPhase stage 1 of 1 with 8 MutationType ops +## StatementPhase stage 1 of 1 with 16 MutationType ops upsert descriptor #106 ... - 2 @@ -1815,13 +2065,24 @@ upsert descriptor #106 + currentStatuses: + - PUBLIC + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + - DELETE_ONLY + - PUBLIC + - PUBLIC + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + - BACKFILL_ONLY + - ABSENT + - DELETE_ONLY + + - PUBLIC + + - PUBLIC + + - PUBLIC + + - PUBLIC + jobId: "1" + relevantStatements: + - statement: @@ -1840,21 +2101,55 @@ upsert descriptor #106 + - 6 + - 7 + - 8 + + - 9 + + - 10 + + - 11 + + - 12 + + - 13 + + - 14 + + - 15 + + - 16 + + - 17 + + - 18 + + - 19 + targets: + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 4 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 4 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 4 + + kind: STORED + + ordinalInKind: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 4 + indexId: 4 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 - + storingColumnIds: - + - 2 - + - 3 + tableId: 106 + metadata: + sourceElementId: 1 @@ -1913,21 +2208,54 @@ upsert descriptor #106 + subWorkId: 1 + targetStatus: PUBLIC + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 6 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 6 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 6 + + kind: STORED + + ordinalInKind: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 4 + + indexId: 6 + + kind: STORED + + ordinalInKind: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 4 + indexId: 6 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 4 - + storingColumnIds: - + - 2 - + - 3 - + - 4 + tableId: 106 + temporaryIndexId: 7 + metadata: @@ -1950,20 +2278,53 @@ upsert descriptor #106 + indexId: 7 + isCreatedExplicitly: true + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 + sourceIndexId: 4 - + storingColumnIds: - + - 2 - + - 3 - + - 4 + tableId: 106 + metadata: + sourceElementId: 1 + subWorkId: 1 + targetStatus: TRANSIENT_ABSENT + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 7 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 7 + + kind: STORED + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 7 + + kind: STORED + + ordinalInKind: 1 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 4 + + indexId: 7 + + kind: STORED + + ordinalInKind: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC families: - columnIds: ... @@ -2018,8 +2379,8 @@ upsert descriptor #106 - ABSENT - - DELETE_ONLY + - WRITE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -2186,8 +2547,8 @@ upsert descriptor #106 createAsOfTime: wallTime: "1640995200000000000" ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC + - VALIDATED + - ABSENT - PUBLIC @@ -2195,12 +2556,14 @@ upsert descriptor #106 - - WRITE_ONLY - PUBLIC - PUBLIC + ... + - PUBLIC - PUBLIC - - MERGE_ONLY - - ABSENT + - PUBLIC - WRITE_ONLY - jobId: "1" + - PUBLIC ... statement: ALTER TABLE db.public.tbl ADD COLUMN l INT8 NOT NULL DEFAULT nextval('db.public.sq1') statementTag: ALTER TABLE @@ -2335,26 +2698,33 @@ upsert descriptor #107 - version: "5" + version: "6" adding table for stats refresh: 106 -update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 2 MutationType ops pending" +update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 1 of 2 with 5 MutationType ops pending" set schema change job #1 to non-cancellable commit transaction #9 begin transaction #10 -## PostCommitNonRevertiblePhase stage 1 of 2 with 5 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops upsert descriptor #106 ... userName: root currentStatuses: + - - PUBLIC + - - PUBLIC + - - PUBLIC - - VALIDATED - + - DELETE_ONLY - ABSENT + + - ABSENT + + - ABSENT + + - DELETE_ONLY + + - ABSENT + - PUBLIC - PUBLIC ... - PUBLIC - PUBLIC - - WRITE_ONLY + - TRANSIENT_DELETE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -2362,7 +2732,10 @@ upsert descriptor #106 - wallTime: "1640995200000000009" + modificationTime: {} mutations: - - direction: ADD + - - direction: ADD + + - direction: DROP + index: + constraintId: 7 ... version: 4 mutationId: 1 @@ -2408,6 +2781,9 @@ upsert descriptor #106 - authorization: - userName: root - currentStatuses: + - - ABSENT + - - ABSENT + - - ABSENT - - DELETE_ONLY - - ABSENT - - PUBLIC @@ -2416,7 +2792,15 @@ upsert descriptor #106 - - PUBLIC - - PUBLIC - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC - - TRANSIENT_DELETE_ONLY + - - PUBLIC + - - PUBLIC + - - PUBLIC + - - PUBLIC - jobId: "1" - relevantStatements: - - statement: @@ -2434,21 +2818,55 @@ upsert descriptor #106 - - 6 - - 7 - - 8 + - - 9 + - - 10 + - - 11 + - - 12 + - - 13 + - - 14 + - - 15 + - - 16 + - - 17 + - - 18 + - - 19 - targets: - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 4 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 4 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 4 + - kind: STORED + - ordinalInKind: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 4 - indexId: 4 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - - storingColumnIds: - - - 2 - - - 3 - tableId: 106 - metadata: - sourceElementId: 1 @@ -2507,21 +2925,54 @@ upsert descriptor #106 - subWorkId: 1 - targetStatus: PUBLIC - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 6 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 6 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 6 + - kind: STORED + - ordinalInKind: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 4 + - indexId: 6 + - kind: STORED + - ordinalInKind: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 4 - indexId: 6 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 4 - - storingColumnIds: - - - 2 - - - 3 - - - 4 - tableId: 106 - temporaryIndexId: 7 - metadata: @@ -2544,20 +2995,53 @@ upsert descriptor #106 - indexId: 7 - isCreatedExplicitly: true - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - sourceIndexId: 4 - - storingColumnIds: - - - 2 - - - 3 - - - 4 - tableId: 106 - metadata: - sourceElementId: 1 - subWorkId: 1 - targetStatus: TRANSIENT_ABSENT + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 7 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 7 + - kind: STORED + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 7 + - kind: STORED + - ordinalInKind: 1 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 4 + - indexId: 7 + - kind: STORED + - ordinalInKind: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC families: - columnIds: ... @@ -2566,7 +3050,7 @@ upsert descriptor #106 - modificationTime: - wallTime: "1640995200000000010" - mutations: - - - direction: ADD + - - direction: DROP - index: - constraintId: 7 - createdExplicitly: true 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 diff --git a/pkg/sql/schemachanger/testdata/drop b/pkg/sql/schemachanger/testdata/drop index 85a262dfb19a..7836d702cc73 100644 --- a/pkg/sql/schemachanger/testdata/drop +++ b/pkg/sql/schemachanger/testdata/drop @@ -255,6 +255,9 @@ upsert descriptor #108 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + jobId: "1" @@ -289,6 +292,9 @@ upsert descriptor #108 + - 22 + - 23 + - 24 + + - 25 + + - 26 + + - 27 + targets: + - elementProto: + namespace: @@ -526,18 +532,41 @@ upsert descriptor #108 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 1 + + tableId: 108 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + kind: STORED + + tableId: 108 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + kind: STORED + + ordinalInKind: 1 + + tableId: 108 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 3 - + storingColumnIds: - + - 1 - + - 2 + tableId: 108 + metadata: + sourceElementId: 1 @@ -604,6 +633,9 @@ upsert descriptor #108 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT + - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - jobId: "1" @@ -638,6 +670,9 @@ upsert descriptor #108 - - 22 - - 23 - - 24 + - - 25 + - - 26 + - - 27 - targets: - - elementProto: - namespace: @@ -875,18 +910,41 @@ upsert descriptor #108 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 1 + - tableId: 108 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - kind: STORED + - tableId: 108 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - kind: STORED + - ordinalInKind: 1 + - tableId: 108 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 3 - - storingColumnIds: - - - 1 - - - 2 - tableId: 108 - metadata: - sourceElementId: 1 @@ -2287,12 +2345,12 @@ upsert descriptor #115 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 75 - + - 76 - + - 77 - + - 78 - + - 79 + - 80 + + - 81 + + - 82 + + - 83 + + - 84 + + - 85 + targets: + - elementProto: + namespace: @@ -2387,6 +2445,9 @@ upsert descriptor #116 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + jobId: "1" @@ -2396,11 +2457,6 @@ upsert descriptor #116 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 81 - + - 82 - + - 83 - + - 84 - + - 85 + - 86 + - 87 + - 88 @@ -2421,6 +2477,14 @@ upsert descriptor #116 + - 103 + - 104 + - 105 + + - 106 + + - 107 + + - 108 + + - 109 + + - 110 + + - 111 + + - 112 + + - 113 + targets: + - elementProto: + namespace: @@ -2661,18 +2725,41 @@ upsert descriptor #116 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + tableId: 116 + + metadata: + + sourceElementId: 7 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + kind: STORED + + tableId: 116 + + metadata: + + sourceElementId: 7 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 1 + + kind: STORED + + ordinalInKind: 1 + + tableId: 116 + + metadata: + + sourceElementId: 7 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 - + storingColumnIds: - + - 2 - + - 3 + tableId: 116 + metadata: + sourceElementId: 7 @@ -2729,6 +2816,9 @@ upsert descriptor #117 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + jobId: "1" @@ -2763,6 +2853,9 @@ upsert descriptor #117 + - 48 + - 49 + - 50 + + - 51 + + - 52 + + - 53 + targets: + - elementProto: + namespace: @@ -3003,18 +3096,41 @@ upsert descriptor #117 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + tableId: 117 + + metadata: + + sourceElementId: 3 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + kind: STORED + + tableId: 117 + + metadata: + + sourceElementId: 3 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 3 + + indexId: 1 + + kind: STORED + + ordinalInKind: 1 + + tableId: 117 + + metadata: + + sourceElementId: 3 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 - + storingColumnIds: - + - 2 - + - 3 + tableId: 117 + metadata: + sourceElementId: 3 @@ -3069,6 +3185,8 @@ upsert descriptor #118 + - WRITE_ONLY + - ABSENT + - ABSENT + + - ABSENT + + - ABSENT + - VALIDATED + - ABSENT + - ABSENT @@ -3079,9 +3197,6 @@ upsert descriptor #118 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 51 - + - 52 - + - 53 + - 54 + - 55 + - 56 @@ -3103,6 +3218,11 @@ upsert descriptor #118 + - 72 + - 73 + - 74 + + - 75 + + - 76 + + - 77 + + - 78 + + - 79 + targets: + - elementProto: + namespace: @@ -3316,17 +3436,30 @@ upsert descriptor #118 + subWorkId: 1 + targetStatus: ABSENT + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 1 + + tableId: 118 + + metadata: + + sourceElementId: 3 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 1 + + kind: STORED + + tableId: 118 + + metadata: + + sourceElementId: 3 + + subWorkId: 1 + + targetStatus: ABSENT + + - elementProto: + primaryIndex: + embeddedIndex: + constraintId: 1 + indexId: 1 + isUnique: true - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 1 - + storingColumnIds: - + - 2 + tableId: 118 + metadata: + sourceElementId: 3 @@ -3392,14 +3525,6 @@ upsert descriptor #119 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 106 - + - 107 - + - 108 - + - 109 - + - 110 - + - 111 - + - 112 - + - 113 + - 114 + - 115 + - 116 @@ -3407,6 +3532,14 @@ upsert descriptor #119 + - 118 + - 119 + - 120 + + - 121 + + - 122 + + - 123 + + - 124 + + - 125 + + - 126 + + - 127 + + - 128 + targets: + - elementProto: + namespace: @@ -3607,14 +3740,6 @@ upsert descriptor #120 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 121 - + - 122 - + - 123 - + - 124 - + - 125 - + - 126 - + - 127 - + - 128 + - 129 + - 130 + - 131 @@ -3625,6 +3750,14 @@ upsert descriptor #120 + - 136 + - 137 + - 138 + + - 139 + + - 140 + + - 141 + + - 142 + + - 143 + + - 144 + + - 145 + + - 146 + targets: + - elementProto: + namespace: @@ -3859,14 +3992,6 @@ upsert descriptor #121 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 139 - + - 140 - + - 141 - + - 142 - + - 143 - + - 144 - + - 145 - + - 146 + - 147 + - 148 + - 149 @@ -3877,6 +4002,14 @@ upsert descriptor #121 + - 154 + - 155 + - 156 + + - 157 + + - 158 + + - 159 + + - 160 + + - 161 + + - 162 + + - 163 + + - 164 + targets: + - elementProto: + namespace: @@ -4112,14 +4245,6 @@ upsert descriptor #122 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 157 - + - 158 - + - 159 - + - 160 - + - 161 - + - 162 - + - 163 - + - 164 + - 165 + - 166 + - 167 @@ -4130,6 +4255,14 @@ upsert descriptor #122 + - 172 + - 173 + - 174 + + - 175 + + - 176 + + - 177 + + - 178 + + - 179 + + - 180 + + - 181 + + - 182 + targets: + - elementProto: + namespace: @@ -4352,13 +4485,13 @@ upsert descriptor #123 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 175 - + - 176 - + - 177 - + - 178 - + - 179 - + - 180 - + - 181 + + - 183 + + - 184 + + - 185 + + - 186 + + - 187 + + - 188 + + - 189 + targets: + - elementProto: + namespace: @@ -4453,13 +4586,13 @@ upsert descriptor #124 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 182 - + - 183 - + - 184 - + - 185 - + - 186 - + - 187 - + - 188 + + - 190 + + - 191 + + - 192 + + - 193 + + - 194 + + - 195 + + - 196 + targets: + - elementProto: + namespace: @@ -4578,14 +4711,6 @@ upsert descriptor #125 + statement: DROP DATABASE db1 CASCADE + statementTag: DROP DATABASE + targetRanks: - + - 189 - + - 190 - + - 191 - + - 192 - + - 193 - + - 194 - + - 195 - + - 196 + - 197 + - 198 + - 199 @@ -4599,6 +4724,14 @@ upsert descriptor #125 + - 207 + - 208 + - 209 + + - 210 + + - 211 + + - 212 + + - 213 + + - 214 + + - 215 + + - 216 + + - 217 + targets: + - elementProto: + namespace: @@ -4960,12 +5093,12 @@ upsert descriptor #115 - statement: DROP DATABASE db1 CASCADE - statementTag: DROP DATABASE - targetRanks: - - - 75 - - - 76 - - - 77 - - - 78 - - - 79 - - 80 + - - 81 + - - 82 + - - 83 + - - 84 + - - 85 - targets: - - elementProto: - namespace: @@ -5064,6 +5197,9 @@ upsert descriptor #116 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT + - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - jobId: "1" @@ -5073,11 +5209,6 @@ upsert descriptor #116 - statement: DROP DATABASE db1 CASCADE - statementTag: DROP DATABASE - targetRanks: - - - 81 - - - 82 - - - 83 - - - 84 - - - 85 - - 86 - - 87 - - 88 @@ -5098,6 +5229,14 @@ upsert descriptor #116 - - 103 - - 104 - - 105 + - - 106 + - - 107 + - - 108 + - - 109 + - - 110 + - - 111 + - - 112 + - - 113 - targets: - - elementProto: - namespace: @@ -5338,18 +5477,41 @@ upsert descriptor #116 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - tableId: 116 + - metadata: + - sourceElementId: 7 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - kind: STORED + - tableId: 116 + - metadata: + - sourceElementId: 7 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 1 + - kind: STORED + - ordinalInKind: 1 + - tableId: 116 + - metadata: + - sourceElementId: 7 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - - storingColumnIds: - - - 2 - - - 3 - tableId: 116 - metadata: - sourceElementId: 7 @@ -5410,6 +5572,9 @@ upsert descriptor #117 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT + - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - jobId: "1" @@ -5444,6 +5609,9 @@ upsert descriptor #117 - - 48 - - 49 - - 50 + - - 51 + - - 52 + - - 53 - targets: - - elementProto: - namespace: @@ -5684,18 +5852,41 @@ upsert descriptor #117 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - tableId: 117 + - metadata: + - sourceElementId: 3 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - kind: STORED + - tableId: 117 + - metadata: + - sourceElementId: 3 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 3 + - indexId: 1 + - kind: STORED + - ordinalInKind: 1 + - tableId: 117 + - metadata: + - sourceElementId: 3 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - - storingColumnIds: - - - 2 - - - 3 - tableId: 117 - metadata: - sourceElementId: 3 @@ -5754,6 +5945,8 @@ upsert descriptor #118 - - WRITE_ONLY - - ABSENT - - ABSENT + - - ABSENT + - - ABSENT - - VALIDATED - - ABSENT - - ABSENT @@ -5764,9 +5957,6 @@ upsert descriptor #118 - statement: DROP DATABASE db1 CASCADE - statementTag: DROP DATABASE - targetRanks: - - - 51 - - - 52 - - - 53 - - 54 - - 55 - - 56 @@ -5788,6 +5978,11 @@ upsert descriptor #118 - - 72 - - 73 - - 74 + - - 75 + - - 76 + - - 77 + - - 78 + - - 79 - targets: - - elementProto: - namespace: @@ -6001,17 +6196,30 @@ upsert descriptor #118 - subWorkId: 1 - targetStatus: ABSENT - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 1 + - tableId: 118 + - metadata: + - sourceElementId: 3 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 1 + - kind: STORED + - tableId: 118 + - metadata: + - sourceElementId: 3 + - subWorkId: 1 + - targetStatus: ABSENT + - - elementProto: - primaryIndex: - embeddedIndex: - constraintId: 1 - indexId: 1 - isUnique: true - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 1 - - storingColumnIds: - - - 2 - tableId: 118 - metadata: - sourceElementId: 3 diff --git a/pkg/sql/schemachanger/testdata/index b/pkg/sql/schemachanger/testdata/index index 325eb5390e10..9e62478cd918 100644 --- a/pkg/sql/schemachanger/testdata/index +++ b/pkg/sql/schemachanger/testdata/index @@ -13,7 +13,7 @@ CREATE INDEX idx1 ON t (v) WHERE (v = 'a'); checking for feature: CREATE INDEX begin transaction #1 # begin StatementPhase -## StatementPhase stage 1 of 1 with 2 MutationType ops +## StatementPhase stage 1 of 1 with 6 MutationType ops upsert descriptor #106 ... formatVersion: 3 @@ -94,9 +94,13 @@ upsert descriptor #106 + authorization: + userName: root + currentStatuses: + + - PUBLIC + + - PUBLIC + - BACKFILL_ONLY + - ABSENT + - DELETE_ONLY + + - PUBLIC + + - PUBLIC + jobId: "1" + relevantStatements: + - statement: @@ -109,17 +113,34 @@ upsert descriptor #106 + - 0 + - 1 + - 2 + + - 3 + + - 4 + + - 5 + + - 6 + targets: + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 2 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 2 + + kind: KEY_SUFFIX + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + secondaryIndex: + embeddedIndex: + indexId: 2 - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 2 - + keySuffixColumnIds: - + - 1 + sourceIndexId: 1 + tableId: 106 + temporaryIndexId: 3 @@ -140,12 +161,6 @@ upsert descriptor #106 + temporaryIndex: + embeddedIndex: + indexId: 3 - + keyColumnDirections: - + - ASC - + keyColumnIds: - + - 2 - + keySuffixColumnIds: - + - 1 + sourceIndexId: 1 + tableId: 106 + isUsingSecondaryEncoding: true @@ -153,6 +168,25 @@ upsert descriptor #106 + sourceElementId: 1 + subWorkId: 1 + targetStatus: TRANSIENT_ABSENT + + - elementProto: + + indexColumn: + + columnId: 2 + + indexId: 3 + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC + + - elementProto: + + indexColumn: + + columnId: 1 + + indexId: 3 + + kind: KEY_SUFFIX + + tableId: 106 + + metadata: + + sourceElementId: 1 + + subWorkId: 1 + + targetStatus: PUBLIC families: - columnIds: ... @@ -180,8 +214,8 @@ upsert descriptor #106 - ABSENT - - DELETE_ONLY + - WRITE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... formatVersion: 3 id: 106 @@ -212,8 +246,8 @@ begin transaction #5 ## PostCommitPhase stage 3 of 7 with 3 MutationType ops upsert descriptor #106 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - BACKFILL_ONLY + - DELETE_ONLY - ABSENT @@ -244,8 +278,8 @@ begin transaction #6 ## PostCommitPhase stage 4 of 7 with 3 MutationType ops upsert descriptor #106 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - DELETE_ONLY + - MERGE_ONLY - ABSENT @@ -284,14 +318,14 @@ begin transaction #9 ## PostCommitPhase stage 7 of 7 with 4 MutationType ops upsert descriptor #106 ... - userName: root - currentStatuses: + - PUBLIC + - PUBLIC - - MERGE_ONLY - - ABSENT + - PUBLIC + - PUBLIC - WRITE_ONLY - jobId: "1" + - PUBLIC ... statement: CREATE INDEX idx1 ON t (v) WHERE (v = 'a') statementTag: CREATE INDEX @@ -368,8 +402,8 @@ upsert descriptor #106 - PUBLIC - - WRITE_ONLY + - TRANSIENT_DELETE_ONLY - jobId: "1" - relevantStatements: + - PUBLIC + - PUBLIC ... storeColumnNames: [] version: 4 @@ -377,7 +411,10 @@ upsert descriptor #106 - wallTime: "1640995200000000009" + modificationTime: {} mutations: - - direction: ADD + - - direction: ADD + + - direction: DROP + index: + constraintId: 3 ... version: 4 mutationId: 1 @@ -404,7 +441,11 @@ upsert descriptor #106 - currentStatuses: - - PUBLIC - - PUBLIC + - - PUBLIC + - - PUBLIC - - TRANSIENT_DELETE_ONLY + - - PUBLIC + - - PUBLIC - jobId: "1" - relevantStatements: - - statement: @@ -416,17 +457,34 @@ upsert descriptor #106 - - 0 - - 1 - - 2 + - - 3 + - - 4 + - - 5 + - - 6 - targets: - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 2 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 2 + - kind: KEY_SUFFIX + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: - secondaryIndex: - embeddedIndex: - indexId: 2 - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 2 - - keySuffixColumnIds: - - - 1 - sourceIndexId: 1 - tableId: 106 - temporaryIndexId: 3 @@ -447,12 +505,6 @@ upsert descriptor #106 - temporaryIndex: - embeddedIndex: - indexId: 3 - - keyColumnDirections: - - - ASC - - keyColumnIds: - - - 2 - - keySuffixColumnIds: - - - 1 - sourceIndexId: 1 - tableId: 106 - isUsingSecondaryEncoding: true @@ -460,6 +512,25 @@ upsert descriptor #106 - sourceElementId: 1 - subWorkId: 1 - targetStatus: TRANSIENT_ABSENT + - - elementProto: + - indexColumn: + - columnId: 2 + - indexId: 3 + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC + - - elementProto: + - indexColumn: + - columnId: 1 + - indexId: 3 + - kind: KEY_SUFFIX + - tableId: 106 + - metadata: + - sourceElementId: 1 + - subWorkId: 1 + - targetStatus: PUBLIC families: - columnIds: ... @@ -468,7 +539,7 @@ upsert descriptor #106 - modificationTime: - wallTime: "1640995200000000010" - mutations: - - - direction: ADD + - - direction: DROP - index: - constraintId: 3 - createdExplicitly: true diff --git a/pkg/sql/span/BUILD.bazel b/pkg/sql/span/BUILD.bazel index 31284459f96b..e823f8b71288 100644 --- a/pkg/sql/span/BUILD.bazel +++ b/pkg/sql/span/BUILD.bazel @@ -12,6 +12,8 @@ go_library( "//pkg/keys", "//pkg/roachpb", "//pkg/sql/catalog", + "//pkg/sql/catalog/catalogkeys", + "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/inverted", "//pkg/sql/opt/constraint", diff --git a/pkg/sql/span/span_builder.go b/pkg/sql/span/span_builder.go index 11dfa166fec3..60b93ddbab90 100644 --- a/pkg/sql/span/span_builder.go +++ b/pkg/sql/span/span_builder.go @@ -16,6 +16,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/inverted" "github.com/cockroachdb/cockroach/pkg/sql/opt/constraint" @@ -86,7 +88,7 @@ func (s *Builder) SpanFromEncDatumsWithRange( endInclusive bool, ) (_ roachpb.Span, containsNull bool, err error) { - isDesc := s.keyAndPrefixCols[prefixLen-1].Direction == descpb.IndexDescriptor_DESC + isDesc := s.keyAndPrefixCols[prefixLen-1].Direction == catpb.IndexColumn_DESC if isDesc { startDatum, endDatum = endDatum, startDatum startInclusive, endInclusive = endInclusive, startInclusive @@ -272,7 +274,9 @@ func (s *Builder) encodeConstraintKey( containsNull = true } - dir, err := s.keyAndPrefixCols[i].Direction.ToEncodingDirection() + dir, err := catalogkeys.IndexColumnEncodingDirection( + s.keyAndPrefixCols[i].Direction, + ) if err != nil { return nil, false, err } diff --git a/pkg/sql/stats/stats_cache.go b/pkg/sql/stats/stats_cache.go index 313fc9606456..cd4090b6a9cf 100644 --- a/pkg/sql/stats/stats_cache.go +++ b/pkg/sql/stats/stats_cache.go @@ -22,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/opt/cat" @@ -185,7 +186,7 @@ func decodeTableStatisticsKV( ) (tableDesc descpb.ID, err error) { // The primary key of table_statistics is (tableID INT, statisticID INT). types := []*types.T{types.Int, types.Int} - dirs := []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC} + dirs := []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC} keyVals := make([]rowenc.EncDatum, 2) if _, _, err := rowenc.DecodeIndexKey(codec, types, keyVals, dirs, kv.Key); err != nil { return 0, err diff --git a/pkg/sql/table_test.go b/pkg/sql/table_test.go index e327b3d8ff0c..0850547be9fb 100644 --- a/pkg/sql/table_test.go +++ b/pkg/sql/table_test.go @@ -222,7 +222,7 @@ func TestMakeTableDescIndexes(t *testing.T) { Unique: true, KeyColumnNames: []string{"a"}, KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, ConstraintID: 1, @@ -237,7 +237,7 @@ func TestMakeTableDescIndexes(t *testing.T) { Unique: true, KeyColumnNames: []string{"b"}, KeyColumnIDs: []descpb.ColumnID{2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, StoreColumnNames: []string{"a"}, StoreColumnIDs: []descpb.ColumnID{1}, EncodingType: descpb.PrimaryIndexEncoding, @@ -252,7 +252,7 @@ func TestMakeTableDescIndexes(t *testing.T) { KeyColumnNames: []string{"a"}, KeyColumnIDs: []descpb.ColumnID{1}, KeySuffixColumnIDs: []descpb.ColumnID{2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, ConstraintID: 1, }, @@ -266,7 +266,7 @@ func TestMakeTableDescIndexes(t *testing.T) { Unique: true, KeyColumnNames: []string{"a", "b"}, KeyColumnIDs: []descpb.ColumnID{1, 2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, ConstraintID: 1, @@ -281,7 +281,7 @@ func TestMakeTableDescIndexes(t *testing.T) { Unique: true, KeyColumnNames: []string{"a", "b"}, KeyColumnIDs: []descpb.ColumnID{1, 2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, ConstraintID: 2, @@ -294,7 +294,7 @@ func TestMakeTableDescIndexes(t *testing.T) { KeyColumnNames: []string{"b"}, KeyColumnIDs: []descpb.ColumnID{2}, KeySuffixColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, ConstraintID: 1, }, @@ -308,7 +308,7 @@ func TestMakeTableDescIndexes(t *testing.T) { Unique: true, KeyColumnNames: []string{"a", "b"}, KeyColumnIDs: []descpb.ColumnID{1, 2}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, ConstraintID: 1, diff --git a/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go index b777b45278f3..c86ea7af20a2 100644 --- a/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go +++ b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go @@ -133,8 +133,8 @@ func getDeprecatedProtectedTimestampRecordsDescriptor() *descpb.TableDescriptor Unique: true, KeyColumnNames: []string{"id"}, KeyColumnIDs: []descpb.ColumnID{1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, }, NextIndexID: 2, diff --git a/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go b/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go index bef154231435..456748defed3 100644 --- a/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go +++ b/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go @@ -148,7 +148,7 @@ func getDeprecatedTableStatisticsDescriptor() *descpb.TableDescriptor { ID: 1, Unique: true, KeyColumnNames: []string{"tableID", "statisticID"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1, 2}, }, NextIndexID: 2, diff --git a/pkg/upgrade/upgrades/descriptor_utils_test.go b/pkg/upgrade/upgrades/descriptor_utils_test.go index 862fc3db627d..5b0b306e72d3 100644 --- a/pkg/upgrade/upgrades/descriptor_utils_test.go +++ b/pkg/upgrade/upgrades/descriptor_utils_test.go @@ -61,8 +61,8 @@ func TestCreateSystemTable(t *testing.T) { ID: 1, Unique: true, KeyColumnNames: []string{"id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{ - descpb.IndexDescriptor_ASC, + KeyColumnDirections: []catpb.IndexColumn_Direction{ + catpb.IndexColumn_ASC, }, KeyColumnIDs: []descpb.ColumnID{1}, }, diff --git a/pkg/upgrade/upgrades/sampled_stmt_diagnostics_requests_test.go b/pkg/upgrade/upgrades/sampled_stmt_diagnostics_requests_test.go index cb7545e7748b..0efebde61b5a 100644 --- a/pkg/upgrade/upgrades/sampled_stmt_diagnostics_requests_test.go +++ b/pkg/upgrade/upgrades/sampled_stmt_diagnostics_requests_test.go @@ -133,7 +133,7 @@ func getV2StmtDiagReqsDescriptor() *descpb.TableDescriptor { ID: 1, Unique: true, KeyColumnNames: []string{"id"}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, KeyColumnIDs: []descpb.ColumnID{1}, }, Indexes: []descpb.IndexDescriptor{ @@ -144,7 +144,7 @@ func getV2StmtDiagReqsDescriptor() *descpb.TableDescriptor { KeyColumnNames: []string{"completed", "id"}, StoreColumnNames: []string{"statement_fingerprint", "min_execution_latency", "expires_at"}, KeyColumnIDs: []descpb.ColumnID{2, 1}, - KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC, descpb.IndexDescriptor_ASC}, + KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC, catpb.IndexColumn_ASC}, StoreColumnIDs: []descpb.ColumnID{3, 6, 7}, Version: descpb.StrictIndexColumnIDGuaranteesVersion, },