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

plpgsql: disallow txn control in udfs and nested procedures #122657

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

DrewKimball
Copy link
Collaborator

This patch adds validation for transaction control statements, so that attempting to use them from within a UDF results in an error. In addition, attempting to use a transaction control statement from a nested stored procedure call will now result in an "unimplemented" error.

Informs #122266

Release note: None

@DrewKimball DrewKimball requested a review from a team as a code owner April 18, 2024 20:39
@DrewKimball DrewKimball requested review from yuzefovich and removed request for a team April 18, 2024 20:39
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@DrewKimball DrewKimball added the backport-24.1.x Flags PRs that need to be backported to 24.1. label Apr 18, 2024
@DrewKimball DrewKimball requested review from mgartner and a team and removed request for yuzefovich April 18, 2024 20:40
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball and @mgartner)


pkg/sql/opt/optbuilder/builder.go line 155 at r1 (raw file):

	// insideDataSource is true when we are processing a data source.
	insideDataSource bool
  

nit: dangling spaces.


pkg/sql/opt/optbuilder/create_function.go line 381 at r1 (raw file):

		plpgsqltree.Walk(&tc, stmt.AST)
		if tc.foundTxnControlStatement {
			if !cf.IsProcedure {

nit: should we only perform the walk for functions? I.e. for procedures the walk seems redundant.


pkg/sql/opt/optbuilder/plpgsql.go line 290 at r1 (raw file):

			if b.ob.insideNestedPLpgSQLCall {
				// Disallow transaction control statements in nested routines for now.
				// TODO(#12345): once we support this, make sure to validate that

nit: is this the right issue number?


pkg/ccl/logictestccl/testdata/logic_test/plpgsql_txn line 995 at r1 (raw file):


statement error pgcode 2D000 pq: invalid transaction termination
CREATE FUNCTION f() RETURNS INT LANGUAGE PLpgSQL AS $$ BEGIN COMMIT; END $$;

nit: did you mean to use ROLLBACK in this case?

Copy link
Collaborator Author

@DrewKimball DrewKimball 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 @mgartner and @yuzefovich)


pkg/sql/opt/optbuilder/builder.go line 155 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: dangling spaces.

Done.


pkg/sql/opt/optbuilder/create_function.go line 381 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: should we only perform the walk for functions? I.e. for procedures the walk seems redundant.

Good idea, Done.


pkg/sql/opt/optbuilder/plpgsql.go line 290 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: is this the right issue number?

Hmmm... Done.


pkg/ccl/logictestccl/testdata/logic_test/plpgsql_txn line 995 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: did you mean to use ROLLBACK in this case?

Yes, good catch.

Copy link
Member

@yuzefovich yuzefovich 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 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)

This patch adds validation for transaction control statements, so that
attempting to use them from within a UDF results in an error. In addition,
attempting to use a transaction control statement from a nested stored
procedure call will now result in an "unimplemented" error.

Informs cockroachdb#122266

Release note: None
@DrewKimball
Copy link
Collaborator Author

TFYR!

bors r+

@craig craig bot merged commit fade49a into cockroachdb:master Apr 24, 2024
22 checks passed
Copy link

blathers-crl bot commented Apr 24, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from e354328 to blathers/backport-release-24.1-122657: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

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.

None yet

3 participants