From 411c0f19fea51a4f2ca3d90e95d4855adfd9ae93 Mon Sep 17 00:00:00 2001 From: Faizan Qazi Date: Wed, 13 Jul 2022 17:20:23 -0400 Subject: [PATCH] sql/schemachange: skip constraint validation if column generation fails 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 --- pkg/workload/schemachange/error_screening.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/workload/schemachange/error_screening.go b/pkg/workload/schemachange/error_screening.go index 2b91909b2d8b..4963e89303f7 100644 --- a/pkg/workload/schemachange/error_screening.go +++ b/pkg/workload/schemachange/error_screening.go @@ -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++ { @@ -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 @@ -359,8 +359,10 @@ GROUP BY name; {code: pgcode.MakeCode(pgErr.Code), condition: true}, }..., ) + hasGenerationError = true continue } + err = evalTxn.Commit(ctx) if err != nil { return false, nil, err } @@ -368,6 +370,10 @@ GROUP BY name; 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]