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 8, 2023
1 parent 073ca1f commit 12afc89
Show file tree
Hide file tree
Showing 276 changed files with 5,715 additions and 3,199 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ EXPLAIN (ddl) DROP TABLE multi_region_test_db.public.table_regional_by_table CAS
Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table› CASCADE;
├── StatementPhase
│ └── Stage 1 of 1 in StatementPhase
│ ├── 20 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT Namespace:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table", ReferencedDescID: 104 (multi_region_test_db)}
│ │ ├── PUBLIC → ABSENT Owner:{DescID: 108 (table_regional_by_table-)}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "admin"}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "root"}
│ │ ├── PUBLIC → DROPPED Table:{DescID: 108 (table_regional_by_table-)}
│ │ ├── PUBLIC → ABSENT SchemaChild:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 105 (public)}
│ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 106 (#106)}
│ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108 (table_regional_by_table-), Name: "primary", ColumnFamilyID: 0 (primary-)}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "a", ColumnID: 1 (a-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 1 (a-)}
│ │ ├── PUBLIC → VALIDATED ColumnNotNull:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 0}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "crdb_internal_mvcc_timestamp", ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "tableoid", ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108 (table_regional_by_table-), IndexID: 1 (table_regional_by_table_pkey-), ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table_pkey", IndexID: 1 (table_regional_by_table_pkey-)}
│ └── 17 Mutation operations
│ ├── 21 elements transitioning toward ABSENT
│ │ ├── PUBLIC → ABSENT Namespace:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table", ReferencedDescID: 104 (multi_region_test_db)}
│ │ ├── PUBLIC → ABSENT Owner:{DescID: 108 (table_regional_by_table-)}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "admin"}
│ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "root"}
│ │ ├── PUBLIC → DROPPED Table:{DescID: 108 (table_regional_by_table-)}
│ │ ├── PUBLIC → ABSENT SchemaChild:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 105 (public)}
│ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 106 (#106)}
│ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108 (table_regional_by_table-), Name: "primary", ColumnFamilyID: 0 (primary-)}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "a", ColumnID: 1 (a-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 1 (a-)}
│ │ ├── PUBLIC → ABSENT ColumnNotNull:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 0}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "crdb_internal_mvcc_timestamp", ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ ├── PUBLIC → ABSENT Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108 (table_regional_by_table-), Name: "tableoid", ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967294 (tableoid-)}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 1 (table_regional_by_table_pkey-)}
│ │ ├── PUBLIC → ABSENT PrimaryIndex:{DescID: 108 (table_regional_by_table-), IndexID: 1 (table_regional_by_table_pkey-), ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table_pkey", IndexID: 1 (table_regional_by_table_pkey-)}
│ └── 27 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108}
Expand All @@ -48,30 +49,41 @@ 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"}
│ └── AssertColumnFamilyIsRemoved {"TableID":108}
│ ├── AssertColumnFamilyIsRemoved {"TableID":108}
│ ├── RemoveColumnNotNull {"ColumnID":1,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":4294967295,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":4294967294,"TableID":108}
│ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":1,"TableID":108}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":108}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":108}
│ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":1,"TableID":108}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":1,"TableID":108}
│ ├── MakeIndexAbsent {"IndexID":1,"TableID":108}
│ └── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108}
├── PreCommitPhase
│ ├── Stage 1 of 2 in PreCommitPhase
│ │ ├── 20 elements transitioning toward ABSENT
│ │ │ ├── ABSENT → PUBLIC Namespace:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table", ReferencedDescID: 104 (multi_region_test_db)}
│ │ │ ├── ABSENT → PUBLIC Owner:{DescID: 108 (table_regional_by_table-)}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "admin"}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "root"}
│ │ │ ├── DROPPED → PUBLIC Table:{DescID: 108 (table_regional_by_table-)}
│ │ │ ├── ABSENT → PUBLIC SchemaChild:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 105 (public)}
│ │ │ ├── ABSENT → PUBLIC TableLocalitySecondaryRegion:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 106 (#106)}
│ │ │ ├── ABSENT → PUBLIC ColumnFamily:{DescID: 108 (table_regional_by_table-), Name: "primary", ColumnFamilyID: 0 (primary-)}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "a", ColumnID: 1 (a-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 1 (a-)}
│ │ │ ├── VALIDATED → PUBLIC ColumnNotNull:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 0}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "crdb_internal_mvcc_timestamp", ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "tableoid", ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 108 (table_regional_by_table-), IndexID: 1 (table_regional_by_table_pkey-), ConstraintID: 1}
│ │ │ └── ABSENT → PUBLIC IndexName:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table_pkey", IndexID: 1 (table_regional_by_table_pkey-)}
│ │ ├── 21 elements transitioning toward ABSENT
│ │ │ ├── ABSENT → PUBLIC Namespace:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table", ReferencedDescID: 104 (multi_region_test_db)}
│ │ │ ├── ABSENT → PUBLIC Owner:{DescID: 108 (table_regional_by_table-)}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "admin"}
│ │ │ ├── ABSENT → PUBLIC UserPrivileges:{DescID: 108 (table_regional_by_table-), Name: "root"}
│ │ │ ├── DROPPED → PUBLIC Table:{DescID: 108 (table_regional_by_table-)}
│ │ │ ├── ABSENT → PUBLIC SchemaChild:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 105 (public)}
│ │ │ ├── ABSENT → PUBLIC TableLocalitySecondaryRegion:{DescID: 108 (table_regional_by_table-), ReferencedDescID: 106 (#106)}
│ │ │ ├── ABSENT → PUBLIC ColumnFamily:{DescID: 108 (table_regional_by_table-), Name: "primary", ColumnFamilyID: 0 (primary-)}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "a", ColumnID: 1 (a-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 1 (a-)}
│ │ │ ├── ABSENT → PUBLIC ColumnNotNull:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 0}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "crdb_internal_mvcc_timestamp", ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967295 (crdb_internal_mvcc_timestamp-)}
│ │ │ ├── ABSENT → PUBLIC Column:{DescID: 108 (table_regional_by_table-), ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 108 (table_regional_by_table-), Name: "tableoid", ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 108 (table_regional_by_table-), ColumnFamilyID: 0 (primary-), ColumnID: 4294967294 (tableoid-)}
│ │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 108 (table_regional_by_table-), ColumnID: 1 (a-), IndexID: 1 (table_regional_by_table_pkey-)}
│ │ │ ├── ABSENT → PUBLIC PrimaryIndex:{DescID: 108 (table_regional_by_table-), IndexID: 1 (table_regional_by_table_pkey-), ConstraintID: 1}
│ │ │ └── ABSENT → PUBLIC IndexName:{DescID: 108 (table_regional_by_table-), Name: "table_regional_by_table_pkey", IndexID: 1 (table_regional_by_table_pkey-)}
│ │ └── 1 Mutation operation
│ │ └── UndoAllInTxnImmediateMutationOpSideEffects
│ └── Stage 2 of 2 in PreCommitPhase
Expand Down
Loading

0 comments on commit 12afc89

Please sign in to comment.