Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workload/schemachange: expect incomparable types #124887

Merged
merged 1 commit into from
May 31, 2024

Conversation

annrpom
Copy link
Contributor

@annrpom annrpom commented May 30, 2024

This patch ensures that our schemachange workload will
allow for invalid columns of incomparable types to pass the
rowsSatisfyFkConstraint check -- as they are expected to
fail later on with a foreign key violation.

Epic: none

Fixes: #124719
Release note: None

@annrpom annrpom requested review from rafiss and a team May 30, 2024 22:26
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@annrpom annrpom marked this pull request as ready for review May 30, 2024 22:26
@annrpom annrpom requested a review from a team as a code owner May 30, 2024 22:26
@annrpom annrpom requested review from DarrylWong and renatolabs and removed request for a team May 30, 2024 22:26
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DarrylWong, @rafiss, and @renatolabs)

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @annrpom, @DarrylWong, and @renatolabs)


pkg/workload/schemachange/operation_generator.go line 3276 at r1 (raw file):

		       ) AS cons ON cons.conrelid = cols.tableid
		 WHERE table_name SIMILAR TO 'table_w[0-9]_+%'
     AND crdb_sql_type != 'REFCURSOR'

hm, well i think the idea with this function is that it occasionally will return an invalid parent column. so i believe we would want it to keep returning refcursor columns, even though they are invalid for foreign keys.

would it make sense to change rowsSatisfyFkConstraint instead?

diff --git a/pkg/workload/schemachange/error_screening.go b/pkg/workload/schemachange/error_screening.go
index 786ac08e36c..169348e9571 100644
--- a/pkg/workload/schemachange/error_screening.go
+++ b/pkg/workload/schemachange/error_screening.go
@@ -1029,6 +1029,10 @@ SELECT count(*) FROM %s
 
 	numJoinRows, err := og.scanInt(ctx, tx, q)
 	if err != nil {
+		// 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 {
+			return false, nil
+		}
 		return false, err
 	}
 	return numJoinRows == childRows, err

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @annrpom, @DarrylWong, and @renatolabs)


pkg/workload/schemachange/operation_generator.go line 3276 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

hm, well i think the idea with this function is that it occasionally will return an invalid parent column. so i believe we would want it to keep returning refcursor columns, even though they are invalid for foreign keys.

would it make sense to change rowsSatisfyFkConstraint instead?

diff --git a/pkg/workload/schemachange/error_screening.go b/pkg/workload/schemachange/error_screening.go
index 786ac08e36c..169348e9571 100644
--- a/pkg/workload/schemachange/error_screening.go
+++ b/pkg/workload/schemachange/error_screening.go
@@ -1029,6 +1029,10 @@ SELECT count(*) FROM %s
 
 	numJoinRows, err := og.scanInt(ctx, tx, q)
 	if err != nil {
+		// 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 {
+			return false, nil
+		}
 		return false, err
 	}
 	return numJoinRows == childRows, err

the other reason to avoid the check here is so that we don't need to maintain a list of non-comparable types here. refcursor may not always be the only one.

@annrpom annrpom force-pushed the deflake-fk-refcursor branch 2 times, most recently from b3036eb to 2b31ea9 Compare May 31, 2024 16:37
@annrpom
Copy link
Contributor Author

annrpom commented May 31, 2024

it occasionally will return an invalid parent column
ah you're right

that makes sense -- fixed

@annrpom annrpom requested a review from rafiss May 31, 2024 16:38
@annrpom annrpom changed the title workload/schemachange: restrict refcursor type from FK constraint workload/schemachange: expect incomparable types May 31, 2024
This patch ensures that our schemachange workload will
allow for invalid columns of incomparable types to pass the
`rowsSatisfyFkConstraint` check -- as they are expected to
fail later on with a foreign key violation.

Epic: none

Fixes: cockroachdb#124719
Release note: None
@annrpom
Copy link
Contributor Author

annrpom commented May 31, 2024

TFTR! ('-')7

bors r+

@craig craig bot merged commit 6f79468 into cockroachdb:master May 31, 2024
21 of 22 checks passed
@rafiss
Copy link
Collaborator

rafiss commented May 31, 2024

blathers backport 24.1

@rafiss rafiss added the backport-24.1.x Flags PRs that need to be backported to 24.1. label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-24.1.x Flags PRs that need to be backported to 24.1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

roachtest: schemachange/random-load failed [ERROR: unsupported comparison operator: refcursor = refcursor]
4 participants