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.
<what you did about it: To address this, this patch ...>

Release note: None
  • Loading branch information
fqazi committed Jul 14, 2022
1 parent ce5e0f1 commit 411c0f1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 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 @@ -343,9 +340,12 @@ GROUP BY name;
continue
}
evalTxn, err := tx.Begin(ctx)
if err != nil {
return false, nil, err
}
newCols[colInfo.name], err = og.generateColumn(ctx, tx, colInfo, columnsToValues)
evalTxn.Rollback(ctx)
if err != nil {
_ = evalTxn.Rollback(ctx)
var pgErr *pgconn.PgError
if !errors.As(err, &pgErr) {
return false, nil, err
Expand All @@ -359,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 411c0f1

Please sign in to comment.