Skip to content

Commit

Permalink
scplan: remove hard-coded 1-op-edge constraint on statement phase
Browse files Browse the repository at this point in the history
Previously, the declarative schema changer had this arbitrary constraint
which enforced that each element could transition at most once
towards its target during the statement phase(s) in the statement
transaction.

This commit removes this and relies on the two-version-invariant rules
instead. To do so, this commit reintroduces the
PreviousTransactionPrecedence dependency edge kind and expresses those
rules using that instead of the PreviousStagePrecedence kind, which is
now deprecated.

Removing this limitation is necessary for the side-effects of CREATE
statements to be visible inside the statement transaction. This change
does not otherwise significantly alter the plans which are generated.

Informs cockroachdb#104351.
Informs cockroachdb#104123.

Release note: None
  • Loading branch information
Marius Posta committed Jun 14, 2023
1 parent 72f551a commit 2d3e21b
Show file tree
Hide file tree
Showing 274 changed files with 5,764 additions and 3,264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ write *eventpb.DropDatabase to event log:
statement: DROP DATABASE ‹multi_region_test_db› CASCADE
tag: DROP DATABASE
user: root
## StatementPhase stage 1 of 1 with 47 MutationType ops
## StatementPhase stage 1 of 1 with 57 MutationType ops
delete database namespace entry {0 0 multi_region_test_db} -> 104
delete schema namespace entry {104 0 public} -> 105
delete object namespace entry {104 105 crdb_internal_region} -> 106
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ write *eventpb.DropTable to event log:
tag: DROP TABLE
user: root
tableName: multi_region_test_db.public.table_regional_by_row
## StatementPhase stage 1 of 1 with 24 MutationType ops
## StatementPhase stage 1 of 1 with 38 MutationType ops
delete object namespace entry {104 105 table_regional_by_row} -> 108
upsert descriptor #106
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ write *eventpb.DropTable to event log:
tag: DROP TABLE
user: root
tableName: multi_region_test_db.public.table_regional_by_table
## StatementPhase stage 1 of 1 with 17 MutationType ops
## StatementPhase stage 1 of 1 with 27 MutationType ops
delete object namespace entry {104 105 table_regional_by_table} -> 108
upsert descriptor #106
...
Expand Down

Large diffs are not rendered by default.

134 changes: 76 additions & 58 deletions pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,37 @@ EXPLAIN (ddl) DROP TABLE multi_region_test_db.public.table_regional_by_row;
Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_row›;
├── StatementPhase
│ └── Stage 1 of 1 in StatementPhase
│ ├── 27 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT Namespace:{DescID: 108, Name: table_regional_by_row, ReferencedDescID: 104}
│ │ ├── PUBLIC → ABSENT Owner:{DescID: 108}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: admin}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: root}
│ │ ├── PUBLIC → DROPPED Table:{DescID: 108}
│ │ ├── PUBLIC → ABSENT SchemaChild:{DescID: 108, ReferencedDescID: 105}
│ │ ├── PUBLIC → ABSENT TablePartitioning:{DescID: 108}
│ │ ├── PUBLIC → ABSENT TableLocalityRegionalByRow:{DescID: 108}
│ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 1}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: k, ColumnID: 1}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1}
│ │ ├── PUBLIC → VALIDATED ColumnNotNull:{DescID: 108, ColumnID: 1, IndexID: 0}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2}
│ │ ├── PUBLIC → VALIDATED ColumnNotNull:{DescID: 108, ColumnID: 2, IndexID: 0}
│ │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 4294967295}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 4294967294}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: tableoid, ColumnID: 4294967294}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967294}
│ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ ├── PUBLIC → ABSENT IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ └── 24 Mutation operations
│ ├── 29 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT Namespace:{DescID: 108, Name: table_regional_by_row, ReferencedDescID: 104}
│ │ ├── PUBLIC → ABSENT Owner:{DescID: 108}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: admin}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: root}
│ │ ├── PUBLIC → DROPPED Table:{DescID: 108}
│ │ ├── PUBLIC → ABSENT SchemaChild:{DescID: 108, ReferencedDescID: 105}
│ │ ├── PUBLIC → ABSENT TablePartitioning:{DescID: 108}
│ │ ├── PUBLIC → ABSENT TableLocalityRegionalByRow:{DescID: 108}
│ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108, ColumnID: 1}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: k, ColumnID: 1}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1}
│ │ ├── PUBLIC → ABSENT ColumnNotNull:{DescID: 108, ColumnID: 1, IndexID: 0}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2}
│ │ ├── PUBLIC → ABSENT ColumnNotNull:{DescID: 108, ColumnID: 2, IndexID: 0}
│ │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108, ColumnID: 4294967295}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108, ColumnID: 4294967294}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: tableoid, ColumnID: 4294967294}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967294}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 2, IndexID: 1}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ ├── PUBLIC → ABSENT IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ └── 38 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── NotImplementedForPublicObjects {"DescID":108,"ElementType":"scpb.TablePartit..."}
Expand All @@ -60,39 +62,55 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab
│ ├── NotImplementedForPublicObjects {"DescID":108,"ElementType":"scpb.Owner"}
│ ├── RemoveUserPrivileges {"DescriptorID":108,"User":"admin"}
│ ├── RemoveUserPrivileges {"DescriptorID":108,"User":"root"}
│ ├── RemoveColumnNotNull {"ColumnID":1,"TableID":108}
│ ├── RemoveDroppedColumnType {"ColumnID":2,"TableID":108}
│ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108}
│ └── AssertColumnFamilyIsRemoved {"TableID":108}
│ ├── RemoveColumnNotNull {"ColumnID":2,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":4294967295,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":4294967294,"TableID":108}
│ ├── AssertColumnFamilyIsRemoved {"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":1,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":2,"TableID":108}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":108}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":108}
│ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":1,"TableID":108}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":1,"TableID":108}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"Ordinal":1,"TableID":108}
│ ├── MakeIndexAbsent {"IndexID":1,"TableID":108}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108}
│ └── MakeDeleteOnlyColumnAbsent {"ColumnID":2,"TableID":108}
├── PreCommitPhase
│ ├── Stage 1 of 2 in PreCommitPhase
│ │ ├── 27 elements transitioning toward ABSENT
│ │ │ ├── ABSENT → PUBLIC Namespace:{DescID: 108, Name: table_regional_by_row, ReferencedDescID: 104}
│ │ │ ├── ABSENT → PUBLIC Owner:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108, Name: admin}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108, Name: root}
│ │ │ ├── DROPPED → PUBLIC Table:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC SchemaChild:{DescID: 108, ReferencedDescID: 105}
│ │ │ ├── ABSENT → PUBLIC TablePartitioning:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC TableLocalityRegionalByRow:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108, ColumnID: 1}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: k, ColumnID: 1}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1}
│ │ │ ├── VALIDATED → PUBLIC ColumnNotNull:{DescID: 108, ColumnID: 1, IndexID: 0}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108, ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2}
│ │ │ ├── VALIDATED → PUBLIC ColumnNotNull:{DescID: 108, ColumnID: 2, IndexID: 0}
│ │ │ ├── ABSENT → PUBLIC ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108, ColumnID: 4294967295}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108, ColumnID: 4294967294}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: tableoid, ColumnID: 4294967294}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967294}
│ │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ │ ├── ABSENT → PUBLIC IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ │ └── ABSENT → PUBLIC IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ │ ├── 29 elements transitioning toward ABSENT
│ │ │ ├── ABSENT → PUBLIC Namespace:{DescID: 108, Name: table_regional_by_row, ReferencedDescID: 104}
│ │ │ ├── ABSENT → PUBLIC Owner:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108, Name: admin}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108, Name: root}
│ │ │ ├── DROPPED → PUBLIC Table:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC SchemaChild:{DescID: 108, ReferencedDescID: 105}
│ │ │ ├── ABSENT → PUBLIC TablePartitioning:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC TableLocalityRegionalByRow:{DescID: 108}
│ │ │ ├── ABSENT → PUBLIC ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108, ColumnID: 1}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: k, ColumnID: 1}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1}
│ │ │ ├── ABSENT → PUBLIC ColumnNotNull:{DescID: 108, ColumnID: 1, IndexID: 0}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108, ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC ColumnNotNull:{DescID: 108, ColumnID: 2, IndexID: 0}
│ │ │ ├── ABSENT → PUBLIC ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108, ColumnID: 4294967295}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108, ColumnID: 4294967294}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108, Name: tableoid, ColumnID: 4294967294}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967294}
│ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 108, ColumnID: 2, IndexID: 1}
│ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ │ ├── ABSENT → PUBLIC PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ │ ├── ABSENT → PUBLIC IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ │ └── ABSENT → PUBLIC IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ │ └── 1 Mutation operation
│ │ └── UndoAllInTxnImmediateMutationOpSideEffects
│ └── Stage 2 of 2 in PreCommitPhase
Expand Down
Loading

0 comments on commit 2d3e21b

Please sign in to comment.