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: allow nested blocks in a block with an exception handler #120045

Merged
merged 2 commits into from Mar 12, 2024

Conversation

DrewKimball
Copy link
Collaborator

execbuilder,plpgsql: don't build redundant exception handler

There was some leftover logic for building the branches of a routine's
exception handler after some refactoring in #110998. This didn't affect
correctness, but added unnecessary overhead. This commit removes the
extra work.

plpgsql: allow nested blocks in a block with an exception handler

This commit removes the restriction on nesting PL/pgSQL blocks within
a block that has an exception handler. This is accomplished by tracking
the number of variables that are in scope for each block, and using that
information to determine which arguments to supply to the exception
handler for a block. This relies on the invariant that the variables of
a parent block always form a prefix of the variables of a child block.

Fixes #118551

Release note (sql change): PL/pgSQL blocks can now be nested in a block
that has an exception handler.

@DrewKimball DrewKimball requested review from a team as code owners March 7, 2024 11:33
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@DrewKimball
Copy link
Collaborator Author

The first two commits are #120043.

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

There was some leftover logic for building the branches of a routine's
exception handler after some refactoring in cockroachdb#110998. This didn't affect
correctness, but added unnecessary overhead. This commit removes the
extra work.

Epic: None

Release note: None
This commit removes the restriction on nesting PL/pgSQL blocks within
a block that has an exception handler. This is accomplished by tracking
the number of variables that are in scope for each block, and using that
information to determine which arguments to supply to the exception
handler for a block. This relies on the invariant that the variables of
a parent block always form a prefix of the variables of a child block.

Fixes cockroachdb#118551

Release note (sql change): PL/pgSQL blocks can now be nested in a block
that has an exception handler.
@DrewKimball
Copy link
Collaborator Author

The tests exposed a bug - subsequent branches of an exception handler were considered even if an earlier branch matched and returned its own exception. I fixed that by breaking out of the exception branch-checking loop before attempting to handle the error.

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

@DrewKimball
Copy link
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 12, 2024

Build succeeded:

@craig craig bot merged commit 431d568 into cockroachdb:master Mar 12, 2024
19 checks passed
@DrewKimball DrewKimball deleted the nested-exception branch March 12, 2024 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plpgsql: support nested blocks with exception handlers
3 participants