Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules: suppress a dep-rule in special case #87196

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pkg/sql/schemachanger/rel/schema_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,26 @@ func (sc *Schema) DefNotJoin1(name string, a Var, def func(a Var) Clauses) Rule1
return sc.rule(name, notJoin, def, a).(Rule1)
}

// DefNotJoin2 defines a not-join rule with two bound variable arguments.
func (sc *Schema) DefNotJoin2(name string, a, b Var, def func(a, b Var) Clauses) Rule2 {
return sc.rule(name, notJoin, def, a, b).(Rule2)
}

// Def2 defines a Rule2.
func (sc *Schema) Def2(name string, a, b Var, def func(a, b Var) Clauses) Rule2 {
return sc.rule(name, regular, def, a, b).(Rule2)
}

// DefNotJoin2 defines a not-join rule with two bound variable arguments.
func (sc *Schema) DefNotJoin2(name string, a, b Var, def func(a, b Var) Clauses) Rule2 {
return sc.rule(name, notJoin, def, a, b).(Rule2)
}

// Def3 defines a Rule3.
func (sc *Schema) Def3(name string, a, b, c Var, def func(a, b, c Var) Clauses) Rule3 {
return sc.rule(name, regular, def, a, b, c).(Rule3)
}

// DefNotJoin3 defines a not-join rule with three bound variable arguments.
func (sc *Schema) DefNotJoin3(name string, a, b, c Var, def func(a, b, c Var) Clauses) Rule3 {
return sc.rule(name, notJoin, def, a, b, c).(Rule3)
}

// Def4 defines a Rule4.
func (sc *Schema) Def4(name string, a, b, c, d Var, def func(a, b, c, d Var) Clauses) Rule4 {
return sc.rule(name, regular, def, a, b, c, d).(Rule4)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/schemachanger/scplan/internal/opgen/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ func validateTargets(targets []target) error {
}

for s := range allStatuses {
if !absentStatuses[s] {
if nonAbsentStatuses[s] && !absentStatuses[s] {
return errors.Errorf("status %s is featured in non-ABSENT targets but not in the ABSENT target", s)
}
if !nonAbsentStatuses[s] {
if absentStatuses[s] && !nonAbsentStatuses[s] {
return errors.Errorf("status %s is featured in ABSENT target but not in any non-ABSENT targets", s)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func init() {
to.typeFilter(isSimpleDependent),
joinOnDescID(from, to, "desc-id"),
statusesToAbsent(from, scpb.Status_DROPPED, to, scpb.Status_ABSENT),
fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL(from.target, from.el, to.el),
}
})

Expand Down
27 changes: 27 additions & 0 deletions pkg/sql/schemachanger/scplan/internal/rules/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,30 @@ var descriptorIsNotBeingDropped = screl.Schema.DefNotJoin1(
}
},
)

// fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL creates
// a clause which leads to the outer clause failing to unify
// if the passed element `from` is a Table, `to` is a RowLevelTTl,
// and there does not exist a node with the same target as
// `fromTarget` in PUBLIC status.
// It is used to suppress rule "descriptor drop right before dependent element removal"
// for the special case where we drop a rowLevelTTL table in mixed
// version state for forward compatibility (issue #86672).
var fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL = screl.Schema.DefNotJoin3(
"fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL",
"fromTarget", "fromEl", "toEl", func(fromTarget, fromEl, toEl rel.Var) rel.Clauses {
n := rel.Var("n")
return rel.Clauses{
fromEl.Type((*scpb.Table)(nil)),
toEl.Type((*scpb.RowLevelTTL)(nil)),
n.Type((*screl.Node)(nil)),
n.AttrEqVar(screl.Target, fromTarget),
screl.Schema.DefNotJoin1("nodeHasNoPublicStatus", "n", func(n rel.Var) rel.Clauses {
public := rel.Var("public")
return rel.Clauses{
public.Eq(scpb.Status_PUBLIC),
n.AttrEqVar(screl.CurrentStatus, public),
}
})(n),
}
})
12 changes: 12 additions & 0 deletions pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ descriptorIsNotBeingDropped($element):
- joinTarget($descriptor, $descriptor-target)
- joinOnDescID($descriptor, $element, $id)
- $descriptor-target[TargetStatus] = ABSENT
fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL($fromTarget, $fromEl, $toEl):
not-join:
- $fromEl[Type] = '*scpb.Table'
- $toEl[Type] = '*scpb.RowLevelTTL'
- $n[Type] = '*screl.Node'
- $n[Target] = $fromTarget
- nodeHasNoPublicStatus($n)
joinOnColumnID($a, $b, $desc-id, $col-id):
- joinOnDescID($a, $b, $desc-id)
- $a[ColumnID] = $col-id
Expand All @@ -41,6 +48,10 @@ joinTargetNode($element, $target, $node):
- joinTarget($element, $target)
- $node[Type] = '*screl.Node'
- $node[Target] = $target
nodeHasNoPublicStatus($n):
not-join:
- $public = PUBLIC
- $n[CurrentStatus] = $public
nodeNotExistsWithStatusIn_BACKFILLED_BACKFILL_ONLY($sharedTarget):
not-join:
- $n[Type] = '*screl.Node'
Expand Down Expand Up @@ -1664,6 +1675,7 @@ deprules
- toAbsent($descriptor-target, $dependent-target)
- $descriptor-node[CurrentStatus] = DROPPED
- $dependent-node[CurrentStatus] = ABSENT
- fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL($descriptor-target, $descriptor, $dependent)
- joinTargetNode($descriptor, $descriptor-target, $descriptor-node)
- joinTargetNode($dependent, $dependent-target, $dependent-node)
- name: descriptor drop right before removing dependent with attr ref
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ descriptorIsNotBeingDropped($element):
- joinTarget($descriptor, $descriptor-target)
- joinOnDescID($descriptor, $element, $id)
- $descriptor-target[TargetStatus] = ABSENT
fromHasPublicStatusIfFromIsTableAndToIsRowLevelTTL($fromTarget, $fromEl, $toEl):
not-join:
- $fromEl[Type] = '*scpb.Table'
- $toEl[Type] = '*scpb.RowLevelTTL'
- $n[Type] = '*screl.Node'
- $n[Target] = $fromTarget
- nodeHasNoPublicStatus($n)
joinOnColumnID($a, $b, $desc-id, $col-id):
- joinOnDescID($a, $b, $desc-id)
- $a[ColumnID] = $col-id
Expand All @@ -41,6 +48,10 @@ joinTargetNode($element, $target, $node):
- joinTarget($element, $target)
- $node[Type] = '*screl.Node'
- $node[Target] = $target
nodeHasNoPublicStatus($n):
not-join:
- $public = PUBLIC
- $n[CurrentStatus] = $public
nodeNotExistsWithStatusIn_BACKFILLED_BACKFILL_ONLY($sharedTarget):
not-join:
- $n[Type] = '*screl.Node'
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/scplan/internal/scgraph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/cockroachdb/redact"
)

// Graph is a graph whose nodes are *scpb.Nodes. Graphs are constructed during
// Graph is a graph whose nodes are *screl.Nodes. Graphs are constructed during
// schema change planning. Edges in the graph represent dependencies between
// nodes, either due to the sequencing of statuses for a single target or due to
// inter-target dependencies between statuses.
Expand Down