Skip to content

Commit

Permalink
sql/schemachange: skip constraint validation if column generation fails
Browse files Browse the repository at this point in the history
Previously, we would still try to validate constraints, if any of
the generated columns could be evaluated. To address this, this
patch will skip constraint validation in these scenarios.

Release note: None
  • Loading branch information
fqazi committed Aug 9, 2022
1 parent 21bc7f1 commit 867a8eb
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,8 @@ GROUP BY name;
for range constraints {
constraintTuples = append(constraintTuples, make(map[string]struct{}))
}

for _, row := range rows {
if err != nil {
return false, nil, err
}
hasGenerationError := false
// Put values to be inserted into a column name to value map to simplify lookups.
columnsToValues := map[string]string{}
for i := 0; i < len(columns); i++ {
Expand All @@ -347,15 +344,8 @@ GROUP BY name;
return false, nil, err
}
newCols[colInfo.name], err = og.generateColumn(ctx, tx, colInfo, columnsToValues)
rbkErr := evalTxn.Rollback(ctx)
if rbkErr != nil {
// If we also failed to generate the column include that error too.
if err != nil {
return false, nil, errors.WithSecondaryError(err, rbkErr)
}
return false, nil, rbkErr
}
if err != nil {
_ = evalTxn.Rollback(ctx)
var pgErr *pgconn.PgError
if !errors.As(err, &pgErr) {
return false, nil, err
Expand All @@ -369,15 +359,21 @@ GROUP BY name;
{code: pgcode.MakeCode(pgErr.Code), condition: true},
}...,
)
hasGenerationError = true
continue
}
err = evalTxn.Commit(ctx)
if err != nil {
return false, nil, err
}
}
for k, v := range newCols {
columnsToValues[k] = v
}
// Skip over constraint validation, since we know an expression is bad here.
if hasGenerationError {
continue
}
// Next validate the uniqueness of both constraints and index expressions.
for constraintIdx, constraint := range constraints {
nonTupleConstraint := constraint[0]
Expand Down

0 comments on commit 867a8eb

Please sign in to comment.