Skip to content

Commit

Permalink
workload/schemachanger: fix foreign key operation generation
Browse files Browse the repository at this point in the history
Certain errors were supposed to be ignored when validating foreign keys,
when column types are not comparable. These are meant to be ignored and
when foreign keys refer to the table itself we were also using the wrong
column information when running queries. To address this, the error
detection for foreign key validation has been updated and the correct
column information is passed. This could lead to intermittent failures
in the workload.

Fixes: cockroachdb#131365

Release note: None
  • Loading branch information
fqazi committed Oct 8, 2024
1 parent 74008d0 commit 0661446
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,9 @@ SELECT count(*) FROM %s
if err != nil {
rbkErr := joinTx.Rollback(ctx)
// UndefinedFunction errors mean that the column type is not comparable.
if pgErr := new(pgconn.PgError); errors.As(err, &pgErr) && pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedFunction {
if pgErr := new(pgconn.PgError); errors.As(err, &pgErr) &&
((pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedFunction) ||
(pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedColumn)) {
return false, rbkErr
}
return false, errors.WithSecondaryError(err, rbkErr)
Expand Down Expand Up @@ -1196,7 +1198,7 @@ func (og *operationGenerator) violatesFkConstraintsHelper(
for name, idx := range columnNameToIndexMap {
columnsToValues[name] = rowToInsert[idx]
}
parentValueInSameInsert, err = og.generateColumn(ctx, tx, colsInfo[parentColInfo.ordinal], columnsToValues)
parentValueInSameInsert, err = og.generateColumn(ctx, tx, *parentColInfo, columnsToValues)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 0661446

Please sign in to comment.