Skip to content

workload/schemachanger: check for duplicate trigger functions#153181

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
fqazi:fixDuplicateFn
Sep 9, 2025
Merged

workload/schemachanger: check for duplicate trigger functions#153181
craig[bot] merged 1 commit intocockroachdb:masterfrom
fqazi:fixDuplicateFn

Conversation

@fqazi
Copy link
Copy Markdown
Collaborator

@fqazi fqazi commented Sep 8, 2025

Previously, it was possible for trigger function names to collide if the workload was run mutliple times against a CRDB server. Certain tests like the mixed version tests will intentionally do this. So, before creating triggers or trigger functions we need to validate that function names do not collide.

Fixes: #152716

Release note: None

@fqazi fqazi requested a review from a team September 8, 2025 18:11
@fqazi fqazi requested a review from a team as a code owner September 8, 2025 18:12
@fqazi fqazi requested review from golgeek and srosenberg and removed request for a team September 8, 2025 18:12
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@spilchen spilchen 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! 0 of 0 LGTMs obtained (waiting on @golgeek and @srosenberg)


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

	// Check if the routine already exists.
	routineAlreadyExists, err := og.fnExistsByName(ctx, tx, schemaName, triggerFunctionName)

Doesn't triggerFunctionName have the schema now (a few lines up)? So, will it ever find a matching function name.

Copy link
Copy Markdown
Contributor

@spilchen spilchen 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! 0 of 0 LGTMs obtained (waiting on @golgeek and @srosenberg)


pkg/workload/schemachange/operation_generator.go line 5486 at r2 (raw file):

	// Build the SQL statement
	sqlStatement := fmt.Sprintf("%s;CREATE TRIGGER %s %s %s ON %s FOR EACH ROW EXECUTE FUNCTION %s()",

do we need to specify the schema for the ROW EXECUTE FUNCTION %s() portion?

Previously, it was possible for trigger function names to collide if the
workload was run mutliple times against a CRDB server. Certain tests
like the mixed version tests will intentionally do this. So, before
creating triggers or trigger functions we need to validate that function
names do not collide.

Fixes: cockroachdb#152716

Release note: None
Copy link
Copy Markdown
Collaborator Author

@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.

@fqazi reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @golgeek, @spilchen, and @srosenberg)


pkg/workload/schemachange/operation_generator.go line 5486 at r2 (raw file):

Previously, spilchen wrote…

do we need to specify the schema for the ROW EXECUTE FUNCTION %s() portion?

Done.

@fqazi fqazi requested a review from spilchen September 8, 2025 20:44
Copy link
Copy Markdown
Contributor

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice find BTW

@spilchen reviewed 1 of 2 files at r1, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @golgeek and @srosenberg)

@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Sep 9, 2025

@spilchen TFTR

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 9, 2025

@craig craig bot merged commit 6e67e13 into cockroachdb:master Sep 9, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

roachtest: schemachange/mixed-versions failed [duplicate function]

3 participants