Skip to content

Commit

Permalink
opgen: ensure GC jobs for temp indexes have proper description
Browse files Browse the repository at this point in the history
Fixes #82169.

Release note: None
  • Loading branch information
Marius Posta committed Oct 3, 2022
1 parent 93e55b5 commit e1cfe36
Show file tree
Hide file tree
Showing 156 changed files with 1,022 additions and 237 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/schemachangerccl/testdata/end_to_end/create_index
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ upsert descriptor #104
- version: "7"
+ version: "8"
write *eventpb.FinishSchemaChange to event log
create job #2 (non-cancelable: true): "GC for "
create job #2 (non-cancelable: true): "GC for removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))"
descriptor IDs: [104]
update progress of schema change job #1: "all stages completed"
set schema change job #1 to non-cancellable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ EXPLAIN (ddl, verbose) CREATE INDEX id1
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 7;
│ IndexID: 2
│ StatementForDropJob:
│ Rollback: true
│ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand All @@ -131,6 +131,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 7;
│ │ IndexID: 2
│ │ StatementForDropJob:
│ │ Rollback: true
│ │ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ │ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ │ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ TableID: 104
│ │
│ ├── • MakeIndexAbsent
Expand Down Expand Up @@ -155,6 +155,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 3 of 7;
│ │ IndexID: 2
│ │ StatementForDropJob:
│ │ Rollback: true
│ │ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ │ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ │ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ TableID: 104
│ │
│ ├── • MakeIndexAbsent
Expand Down Expand Up @@ -155,6 +155,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 3 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 4 of 7;
│ │ IndexID: 2
│ │ StatementForDropJob:
│ │ Rollback: true
│ │ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ │ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ │ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ │ TableID: 104
│ │
│ ├── • MakeIndexAbsent
Expand Down Expand Up @@ -155,6 +155,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 4 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 5 of 7;
│ IndexID: 2
│ StatementForDropJob:
│ Rollback: true
│ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand All @@ -165,6 +165,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 5 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 6 of 7;
│ IndexID: 2
│ StatementForDropJob:
│ Rollback: true
│ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand All @@ -165,6 +165,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 6 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 7 of 7;
│ IndexID: 2
│ StatementForDropJob:
│ Rollback: true
│ Statement: CREATE INDEX id1 ON defaultdb.public.t1 (id, name) STORING (money) PARTITION
│ BY LIST (id) (PARTITION p1 VALUES IN (1))
│ Statement: removed secondary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand All @@ -165,6 +165,10 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 7 of 7;
├── • CreateGCJobForIndex
│ IndexID: 3
│ StatementForDropJob:
│ Rollback: true
│ Statement: removed temporary index; CREATE INDEX id1 ON defaultdb.public.t1 (id,
│ name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
│ TableID: 104
├── • MakeIndexAbsent
Expand Down
13 changes: 10 additions & 3 deletions pkg/sql/schemachanger/scplan/internal/opgen/op_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ func newLogEventOp(e scpb.Element, md *targetsWithElementMap) *scop.LogEvent {

func statementForDropJob(e scpb.Element, md *targetsWithElementMap) scop.StatementForDropJob {
stmtID := md.Targets[md.elementToTarget[e]].Metadata.StatementID
stmt := redact.RedactableString(md.Statements[stmtID].RedactedStatement).StripMarkers()
switch e.(type) {
case *scpb.PrimaryIndex:
stmt = "removed primary index; " + stmt
case *scpb.SecondaryIndex:
stmt = "removed secondary index; " + stmt
case *scpb.TemporaryIndex:
stmt = "removed temporary index; " + stmt
}
return scop.StatementForDropJob{
// Using the redactable string but with stripped markers gives us a
// normalized and fully-qualified string value for display use.
Statement: redact.RedactableString(
md.Statements[stmtID].RedactedStatement,
).StripMarkers(),
Statement: stmt,
StatementID: stmtID,
Rollback: md.InRollback,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ func init() {
}),
),
to(scpb.Status_ABSENT,
emit(func(this *scpb.TemporaryIndex) *scop.CreateGCJobForIndex {
emit(func(this *scpb.TemporaryIndex, md *targetsWithElementMap) *scop.CreateGCJobForIndex {
return &scop.CreateGCJobForIndex{
TableID: this.TableID,
IndexID: this.IndexID,
TableID: this.TableID,
IndexID: this.IndexID,
StatementForDropJob: statementForDropJob(this, md),
}
}),
emit(func(this *scpb.TemporaryIndex) *scop.MakeIndexAbsent {
Expand Down
36 changes: 31 additions & 5 deletions pkg/sql/schemachanger/scplan/testdata/alter_table_add_column
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ PostCommitNonRevertiblePhase stage 2 of 3 with 5 MutationType ops
ops:
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.foo ADD COLUMN
j INT8 NOT NULL DEFAULT 123
TableID: 104
*scop.MakeIndexAbsent
IndexID: 3
Expand All @@ -396,7 +399,8 @@ PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.foo ADD COLUMN j INT8 NOT NULL DEFAULT 123
Statement: removed primary index; ALTER TABLE defaultdb.public.foo ADD COLUMN j
INT8 NOT NULL DEFAULT 123
TableID: 104
*scop.MakeIndexAbsent
EventBase:
Expand Down Expand Up @@ -742,6 +746,9 @@ PostCommitNonRevertiblePhase stage 2 of 3 with 5 MutationType ops
ops:
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.foo ADD COLUMN
j INT8 DEFAULT 123
TableID: 104
*scop.MakeIndexAbsent
IndexID: 3
Expand All @@ -761,7 +768,8 @@ PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.foo ADD COLUMN j INT8 DEFAULT 123
Statement: removed primary index; ALTER TABLE defaultdb.public.foo ADD COLUMN j
INT8 DEFAULT 123
TableID: 104
*scop.MakeIndexAbsent
EventBase:
Expand Down Expand Up @@ -1023,6 +1031,9 @@ PostCommitNonRevertiblePhase stage 2 of 3 with 5 MutationType ops
ops:
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.foo ADD COLUMN
a INT8 AS (i + 1) STORED
TableID: 104
*scop.MakeIndexAbsent
IndexID: 3
Expand All @@ -1042,7 +1053,8 @@ PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.foo ADD COLUMN a INT8 AS (i + 1) STORED
Statement: removed primary index; ALTER TABLE defaultdb.public.foo ADD COLUMN a
INT8 AS (i + 1) STORED
TableID: 104
*scop.MakeIndexAbsent
EventBase:
Expand Down Expand Up @@ -1519,12 +1531,18 @@ PostCommitNonRevertiblePhase stage 2 of 3 with 7 MutationType ops
ops:
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY
KEY USING COLUMNS (j)
TableID: 108
*scop.MakeIndexAbsent
IndexID: 3
TableID: 108
*scop.CreateGCJobForIndex
IndexID: 5
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY
KEY USING COLUMNS (j)
TableID: 108
*scop.MakeIndexAbsent
IndexID: 5
Expand All @@ -1544,7 +1562,8 @@ PostCommitNonRevertiblePhase stage 3 of 3 with 4 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY USING COLUMNS (j)
Statement: removed primary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY
USING COLUMNS (j)
TableID: 108
*scop.MakeIndexAbsent
EventBase:
Expand Down Expand Up @@ -1947,7 +1966,8 @@ PostCommitNonRevertiblePhase stage 2 of 2 with 8 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.baz ADD COLUMN g INT8 UNIQUE DEFAULT 1
Statement: removed primary index; ALTER TABLE defaultdb.public.baz ADD COLUMN g
INT8 UNIQUE DEFAULT 1
TableID: 109
*scop.MakeIndexAbsent
EventBase:
Expand All @@ -1963,12 +1983,18 @@ PostCommitNonRevertiblePhase stage 2 of 2 with 8 MutationType ops
TableID: 109
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.baz ADD COLUMN
g INT8 UNIQUE DEFAULT 1
TableID: 109
*scop.MakeIndexAbsent
IndexID: 3
TableID: 109
*scop.CreateGCJobForIndex
IndexID: 5
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.baz ADD COLUMN
g INT8 UNIQUE DEFAULT 1
TableID: 109
*scop.MakeIndexAbsent
IndexID: 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ PostCommitNonRevertiblePhase stage 2 of 4 with 12 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 1
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY USING COLUMNS (k)
Statement: removed primary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY
USING COLUMNS (k)
TableID: 104
*scop.MakeIndexAbsent
EventBase:
Expand All @@ -380,6 +381,9 @@ PostCommitNonRevertiblePhase stage 2 of 4 with 12 MutationType ops
TableID: 104
*scop.CreateGCJobForIndex
IndexID: 3
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY
KEY USING COLUMNS (k)
TableID: 104
*scop.MakeIndexAbsent
IndexID: 3
Expand All @@ -390,6 +394,9 @@ PostCommitNonRevertiblePhase stage 2 of 4 with 12 MutationType ops
TableID: 104
*scop.CreateGCJobForIndex
IndexID: 5
StatementForDropJob:
Statement: removed temporary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY
KEY USING COLUMNS (k)
TableID: 104
*scop.MakeIndexAbsent
IndexID: 5
Expand Down Expand Up @@ -432,7 +439,8 @@ PostCommitNonRevertiblePhase stage 4 of 4 with 6 MutationType ops
*scop.CreateGCJobForIndex
IndexID: 2
StatementForDropJob:
Statement: ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY USING COLUMNS (k)
Statement: removed primary index; ALTER TABLE defaultdb.public.t ALTER PRIMARY KEY
USING COLUMNS (k)
TableID: 104
*scop.MakeIndexAbsent
EventBase:
Expand Down
Loading

0 comments on commit e1cfe36

Please sign in to comment.