Skip to content

Commit

Permalink
Merge pull request #89154 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.2-89086
  • Loading branch information
Marius Posta authored Oct 3, 2022
2 parents f421fb9 + 1397baa commit 1c77c26
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
2 changes: 2 additions & 0 deletions pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ func errMsgPrefix(b BuildCtx, id catid.DescID) string {
func dropElementWhenDroppingDescriptor(b BuildCtx, e scpb.Element) {
switch t := e.(type) {
case *scpb.ColumnType:
//lint:ignore SA1019 IsRelationBeingDropped is deprecated
t.IsRelationBeingDropped = true
case *scpb.SecondaryIndexPartial:
//lint:ignore SA1019 IsRelationBeingDropped is deprecated
t.IsRelationBeingDropped = true
}
b.Drop(e)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/schemachanger/scpb/elements.proto
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ message ColumnType {
//
// TODO(postamar): remove this when we can have more expressive rule defs
// See the dep rules for how this is used, and why it's not ideal.
bool is_relation_being_dropped = 10;
bool is_relation_being_dropped = 10 [deprecated = true];
}

message ColumnFamily {
Expand Down Expand Up @@ -243,7 +243,7 @@ message SecondaryIndexPartial {
//
// TODO(postamar): remove this when we can have more expressive rule defs
// See the dep rules for how this is used, and why it's not ideal.
bool is_relation_being_dropped = 10;
bool is_relation_being_dropped = 10 [deprecated = true];
}

// SchemaParent models the schema to parent database relationship.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,30 @@ func init() {
"index", "column",
scpb.Status_ABSENT, scpb.Status_ABSENT,
func(from, to nodeVars) rel.Clauses {
ic, ct := mkNodeVars("index-column"), mkNodeVars("column-type")
ic := mkNodeVars("index-column")
relationID, columnID := rel.Var("table-id"), rel.Var("column-id")
return rel.Clauses{
from.Type((*scpb.PrimaryIndex)(nil), (*scpb.SecondaryIndex)(nil)),
to.Type((*scpb.Column)(nil)),
ct.Type((*scpb.ColumnType)(nil)),
columnInIndex(ic, from, relationID, columnID, "index-id"),
joinOnColumnID(ic, to, relationID, columnID),
joinOnColumnID(ic, ct, relationID, columnID),
rel.Filter("relationIsNotBeingDropped", ct.el)(
func(ct *scpb.ColumnType) bool {
return !ct.IsRelationBeingDropped
},
),
ic.descriptorIsNotBeingDropped(),
}
})

registerDepRule("secondary indexes containing column as key reach write-only before column",
scgraph.Precedence,
"index", "column",
func(from, to nodeVars) rel.Clauses {
ic, ct := mkNodeVars("index-column"), mkNodeVars("column-type")
ic := mkNodeVars("index-column")
relationID, columnID := rel.Var("table-id"), rel.Var("column-id")
return rel.Clauses{
from.Type((*scpb.SecondaryIndex)(nil)),
to.Type((*scpb.Column)(nil)),
columnInIndex(ic, from, relationID, columnID, "index-id"),
joinOnColumnID(ic, to, relationID, columnID),
statusesToAbsent(from, scpb.Status_VALIDATED, to, scpb.Status_WRITE_ONLY),
ct.Type((*scpb.ColumnType)(nil)),
joinOnColumnID(ic, ct, relationID, columnID),
rel.Filter("relationIsNotBeingDropped", ct.el)(
func(ct *scpb.ColumnType) bool {
return !ct.IsRelationBeingDropped
},
),
ic.descriptorIsNotBeingDropped(),
rel.Filter("isIndexKeyColumnKey", ic.el)(
func(ic *scpb.IndexColumn) bool {
return ic.Kind == scpb.IndexColumn_KEY
Expand Down
20 changes: 5 additions & 15 deletions pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules
Original file line number Diff line number Diff line change
Expand Up @@ -1863,11 +1863,9 @@ deprules
query:
- $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex']
- $column[Type] = '*scpb.Column'
- $column-type[Type] = '*scpb.ColumnType'
- columnInIndex($index-column, $index, $table-id, $column-id, $index-id)
- joinOnColumnID($index-column, $column, $table-id, $column-id)
- joinOnColumnID($index-column, $column-type, $table-id, $column-id)
- relationIsNotBeingDropped(*scpb.ColumnType)($column-type)
- descriptorIsNotBeingDropped($index-column)
- $index-target[TargetStatus] = TRANSIENT_ABSENT
- $index-node[CurrentStatus] = TRANSIENT_ABSENT
- $column-target[TargetStatus] = ABSENT
Expand All @@ -1881,11 +1879,9 @@ deprules
query:
- $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex']
- $column[Type] = '*scpb.Column'
- $column-type[Type] = '*scpb.ColumnType'
- columnInIndex($index-column, $index, $table-id, $column-id, $index-id)
- joinOnColumnID($index-column, $column, $table-id, $column-id)
- joinOnColumnID($index-column, $column-type, $table-id, $column-id)
- relationIsNotBeingDropped(*scpb.ColumnType)($column-type)
- descriptorIsNotBeingDropped($index-column)
- $index-target[TargetStatus] = ABSENT
- $index-node[CurrentStatus] = ABSENT
- $column-target[TargetStatus] = TRANSIENT_ABSENT
Expand All @@ -1899,11 +1895,9 @@ deprules
query:
- $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex']
- $column[Type] = '*scpb.Column'
- $column-type[Type] = '*scpb.ColumnType'
- columnInIndex($index-column, $index, $table-id, $column-id, $index-id)
- joinOnColumnID($index-column, $column, $table-id, $column-id)
- joinOnColumnID($index-column, $column-type, $table-id, $column-id)
- relationIsNotBeingDropped(*scpb.ColumnType)($column-type)
- descriptorIsNotBeingDropped($index-column)
- transient($index-target, $column-target)
- $index-node[CurrentStatus] = TRANSIENT_ABSENT
- $column-node[CurrentStatus] = TRANSIENT_ABSENT
Expand All @@ -1916,11 +1910,9 @@ deprules
query:
- $index[Type] IN ['*scpb.PrimaryIndex', '*scpb.SecondaryIndex']
- $column[Type] = '*scpb.Column'
- $column-type[Type] = '*scpb.ColumnType'
- columnInIndex($index-column, $index, $table-id, $column-id, $index-id)
- joinOnColumnID($index-column, $column, $table-id, $column-id)
- joinOnColumnID($index-column, $column-type, $table-id, $column-id)
- relationIsNotBeingDropped(*scpb.ColumnType)($column-type)
- descriptorIsNotBeingDropped($index-column)
- toAbsent($index-target, $column-target)
- $index-node[CurrentStatus] = ABSENT
- $column-node[CurrentStatus] = ABSENT
Expand Down Expand Up @@ -2148,9 +2140,7 @@ deprules
- toAbsent($index-target, $column-target)
- $index-node[CurrentStatus] = VALIDATED
- $column-node[CurrentStatus] = WRITE_ONLY
- $column-type[Type] = '*scpb.ColumnType'
- joinOnColumnID($index-column, $column-type, $table-id, $column-id)
- relationIsNotBeingDropped(*scpb.ColumnType)($column-type)
- descriptorIsNotBeingDropped($index-column)
- isIndexKeyColumnKey(*scpb.IndexColumn)($index-column)
- joinTargetNode($index, $index-target, $index-node)
- joinTargetNode($column, $column-target, $column-node)
Expand Down

0 comments on commit 1c77c26

Please sign in to comment.