From 06614468d74b236c8953ef4a4932355de10acf4a Mon Sep 17 00:00:00 2001 From: Faizan Qazi Date: Mon, 7 Oct 2024 09:41:43 -0400 Subject: [PATCH] workload/schemachanger: fix foreign key operation generation 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: #131365 Release note: None --- pkg/workload/schemachange/error_screening.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/workload/schemachange/error_screening.go b/pkg/workload/schemachange/error_screening.go index 9e9b65bd8fab..617ba34a1921 100644 --- a/pkg/workload/schemachange/error_screening.go +++ b/pkg/workload/schemachange/error_screening.go @@ -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) @@ -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 }