Skip to content

Commit

Permalink
sql: clarify comments/naming of descriptorChanged flag
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
rafiss committed Oct 20, 2023
1 parent b6d7758 commit 28ff1e6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,10 @@ func dropColumnImpl(
return droppedViews, validateDescriptor(params.ctx, params.p, tableDesc)
}

// handleTTLStorageParamChange changes TTL storage parameters. descriptorChanged
// must be true if the descriptor was modified directly. The caller
// (alterTableNode), has a separate check to see if any mutations were
// enqueued.
func handleTTLStorageParamChange(
params runParams, tn *tree.TableName, tableDesc *tabledesc.Mutable, after *catpb.RowLevelTTL,
) (descriptorChanged bool, err error) {
Expand Down Expand Up @@ -1957,15 +1961,16 @@ func handleTTLStorageParamChange(
// Adding TTL requires adding the TTL job before adding the TTL fields.
// Removing TTL requires removing the TTL job before removing the TTL fields.
var direction descpb.DescriptorMutation_Direction
directlyModifiesDescriptor := false
switch {
case before == nil && after != nil:
direction = descpb.DescriptorMutation_ADD
case before != nil && after == nil:
direction = descpb.DescriptorMutation_DROP
default:
descriptorChanged = true
directlyModifiesDescriptor = true
}
if !descriptorChanged {
if !directlyModifiesDescriptor {
// Add TTL mutation so that job is scheduled in SchemaChanger.
tableDesc.AddModifyRowLevelTTLMutation(
&descpb.ModifyRowLevelTTL{RowLevelTTL: after},
Expand All @@ -1984,11 +1989,11 @@ func handleTTLStorageParamChange(
}

// Modify the TTL fields here because it will not be done in a mutation.
if descriptorChanged {
if directlyModifiesDescriptor {
tableDesc.RowLevelTTL = after
}

return descriptorChanged, nil
return directlyModifiesDescriptor, nil
}

// tryRemoveFKBackReferences determines whether the provided unique constraint
Expand Down

0 comments on commit 28ff1e6

Please sign in to comment.