Skip to content

Commit

Permalink
opgen,rules: first-class support for transient targets
Browse files Browse the repository at this point in the history
This commit makes it possible to easily declare a transient target path
in opgen for any element, based on its public and absent paths. The
transient path is generated by taking these two and stitching them
together, so to speak.

This is motivated by the need to have a transient path for the primary
index element, to in turn support ALTER TABLE ... ADD COLUMN, DROP COLUMN
statements and especially in the near term, an ALTER PRIMARY KEY
implementation which drops the rowid column.

This change in turn forced a rewriting of the rules, so this was deemed
as good an opportunity as ever to streamline the index and column
dependency rules a bit.

Informs #80149.

Release note: None
  • Loading branch information
Marius Posta committed Aug 13, 2022
1 parent 886433e commit 6993039
Show file tree
Hide file tree
Showing 262 changed files with 10,271 additions and 8,888 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
└── 13 Mutation operations
├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
└── 7 Mutation operations
├── LogEvent {"TargetStatus":1}
├── CreateGcJobForIndex {"IndexID":2,"TableID":104}
├── MakeIndexAbsent {"IndexID":2,"TableID":104}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 12 Mutation operations
│ └── 6 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ ├── LogEvent {"TargetStatus":1}
│ ├── CreateGcJobForIndex {"IndexID":2,"TableID":104}
│ ├── MakeIndexAbsent {"IndexID":2,"TableID":104}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 12 Mutation operations
│ └── 6 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ ├── LogEvent {"TargetStatus":1}
│ ├── CreateGcJobForIndex {"IndexID":2,"TableID":104}
│ ├── MakeIndexAbsent {"IndexID":2,"TableID":104}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 12 Mutation operations
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ └── 6 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── LogEvent {"TargetStatus":1}
│ ├── CreateGcJobForIndex {"IndexID":2,"TableID":104}
│ ├── MakeIndexAbsent {"IndexID":2,"TableID":104}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 10 Mutation operations
│ └── 4 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
└── Stage 2 of 2 in PostCommitNonRevertiblePhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 10 Mutation operations
│ └── 4 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
└── Stage 2 of 2 in PostCommitNonRevertiblePhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ Schema change plan for rolling back CREATE INDEX ‹id1› ON ‹defaultdb›.pu
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ └── PUBLIC → ABSENT IndexPartitioning:{DescID: 104, IndexID: 3}
│ └── 10 Mutation operations
│ └── 4 Mutation operations
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":2,"TableID":104}
│ ├── MakeDroppedIndexDeleteOnly {"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":3,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"Kind":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104}
│ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"Kind":2,"TableID":104}
│ ├── SetJobStateOnDescriptor {"DescriptorID":104}
│ └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"PostCommitNonRev..."}
└── Stage 2 of 2 in PostCommitNonRevertiblePhase
Expand Down
52 changes: 28 additions & 24 deletions pkg/ccl/schemachangerccl/testdata/explain_verbose/create_index
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,52 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ rule: "index-column added to index after index exists"
│ │ │ rule: "index existence precedes index dependents"
│ │ │
│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ rule: "index-column added to index after index exists"
│ │ │ rule: "index existence precedes index dependents"
│ │ │
│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ rule: "index-column added to index after index exists"
│ │ │ rule: "index existence precedes index dependents"
│ │ │
│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ ABSENT → BACKFILL_ONLY
│ │ │
│ │ ├── • IndexPartitioning:{DescID: 104, IndexID: 2}
│ │ │ ABSENT → PUBLIC
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ rule: "index existence precedes index dependents"
│ │ │
│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0, SourceIndexID: 1}
│ │ │ rule: "temp index exists before columns, partitioning, and partial"
│ │ │ rule: "index-column added to index after temp index exists"
│ │ │ rule: "temp index existence precedes index dependents"
│ │ │
│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0, SourceIndexID: 1}
│ │ │ rule: "temp index exists before columns, partitioning, and partial"
│ │ │ rule: "index-column added to index after temp index exists"
│ │ │ rule: "temp index existence precedes index dependents"
│ │ │
│ │ ├── • IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0, SourceIndexID: 1}
│ │ │ rule: "temp index exists before columns, partitioning, and partial"
│ │ │ rule: "index-column added to index after temp index exists"
│ │ │ rule: "temp index existence precedes index dependents"
│ │ │
│ │ └── • IndexPartitioning:{DescID: 104, IndexID: 3}
│ │ │ ABSENT → PUBLIC
│ │ │
│ │ └── • Precedence dependency from DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0, SourceIndexID: 1}
│ │ rule: "temp index exists before columns, partitioning, and partial"
│ │ rule: "temp index existence precedes index dependents"
│ │
│ ├── • 1 element transitioning toward TRANSIENT_ABSENT
│ │ │
Expand Down Expand Up @@ -187,16 +187,7 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1
│ │ ├── • 1 element transitioning toward TRANSIENT_ABSENT
│ │ │ │
│ │ │ └── • TemporaryIndex:{DescID: 104, IndexID: 3, ConstraintID: 0, SourceIndexID: 1}
│ │ │ │ DELETE_ONLY → WRITE_ONLY
│ │ │ │
│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3}
│ │ │ │ rule: "index-column added to index before temp index receives writes"
│ │ │ │
│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3}
│ │ │ │ rule: "index-column added to index before temp index receives writes"
│ │ │ │
│ │ │ └── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 3}
│ │ │ rule: "index-column added to index before temp index receives writes"
│ │ │ DELETE_ONLY → WRITE_ONLY
│ │ │
│ │ └── • 3 Mutation operations
│ │ │
Expand Down Expand Up @@ -333,14 +324,27 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1
│ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ │ │ VALIDATED → PUBLIC
│ │ │ │
│ │ │ └── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: id1, IndexID: 2}
│ │ │ rule: "index named right before index becomes public"
│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2}
│ │ │ │ rule: "index dependents exist before index becomes public"
│ │ │ │
│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2}
│ │ │ │ rule: "index dependents exist before index becomes public"
│ │ │ │
│ │ │ ├── • Precedence dependency from PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2}
│ │ │ │ rule: "index dependents exist before index becomes public"
│ │ │ │
│ │ │ ├── • SameStagePrecedence dependency from PUBLIC IndexName:{DescID: 104, Name: id1, IndexID: 2}
│ │ │ │ rule: "index dependents exist before index becomes public"
│ │ │ │ rule: "index named right before index becomes public"
│ │ │ │
│ │ │ └── • Precedence dependency from PUBLIC IndexPartitioning:{DescID: 104, IndexID: 2}
│ │ │ rule: "index dependents exist before index becomes public"
│ │ │
│ │ └── • IndexName:{DescID: 104, Name: id1, IndexID: 2}
│ │ │ ABSENT → PUBLIC
│ │ │
│ │ └── • Precedence dependency from BACKFILL_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0, TemporaryIndexID: 3, SourceIndexID: 1}
│ │ rule: "index existence precedes index name and comment"
│ │ rule: "index existence precedes index dependents"
│ │
│ ├── • 1 element transitioning toward TRANSIENT_ABSENT
│ │ │
Expand Down
Loading

0 comments on commit 6993039

Please sign in to comment.