-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: fix exception handling for nested blocks #122321
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit prevents inlining for the continuation that transitions out of a PL/pgSQL block with an exception handler. This is necessary to ensure that the statements following the nested block are considered part of the parent block, not the nested block. Otherwise, an error thrown after the nested block might still be caught by the nested block's exception handler, which is incorrect behavior. Informs cockroachdb#122278 Release note: None
This commit adds logic to keep track of the PL/pgSQL sub-routine that logically transitions into a PL/pgSQL block with an exception handler. This is necessary to ensure that the state shared between sub-routines within the same block is correctly initialized. Previously, the block state was only initialized once, but this is incorrect for loops, which need to re-initialize the state on each iteration. Fixes cockroachdb#122278 Release note: None
This commit fixes handling for cursors opened within the scope of a block with an exception handler that has nested blocks or nested routine calls. Previously, if a PL/pgSQL block caught an exception, only the cursors opened directly by that block would be rolled back. Any cursors opened by a nested block or routine call would remain open. Now, the block state tracks the timestamp when the block's execution began. Once an exception is caught, all cursors with a timestamp later than the block's start are rolled back. Fixes cockroachdb#121078 Release note: None
yuzefovich
approved these changes
Apr 15, 2024
There was a problem hiding this 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, 7 of 7 files at r2, 3 of 3 files at r3, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)
DrewKimball
added
the
backport-24.1.x
Flags PRs that need to be backported to 24.1.
label
Apr 16, 2024
TFYR! bors r+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
plpgsql: prevent inlining for block-exit continuation
This commit prevents inlining for the continuation that transitions out
of a PL/pgSQL block with an exception handler. This is necessary to
ensure that the statements following the nested block are considered
part of the parent block, not the nested block. Otherwise, an error thrown
after the nested block might still be caught by the nested block's
exception handler, which is incorrect behavior.
plpgsql: keep track of the subroutine that begins a PL/pgSQL block
This commit adds logic to keep track of the PL/pgSQL sub-routine that
logically transitions into a PL/pgSQL block with an exception handler.
This is necessary to ensure that the state shared between sub-routines
within the same block is correctly initialized. Previously, the block
state was only initialized once, but this is incorrect for loops, which
need to re-initialize the state on each iteration.
plpgsql: roll back all cursors within a block that handles an exception
This commit fixes handling for cursors opened within the scope of a
block with an exception handler that has nested blocks or nested routine
calls. Previously, if a PL/pgSQL block caught an exception, only the cursors
opened directly by that block would be rolled back. Any cursors opened by
a nested block or routine call would remain open. Now, the block state
tracks the timestamp when the block's execution began. Once an exception
is caught, all cursors with a timestamp later than the block's start are
rolled back.
Fixes #122278
Fixes #121078
Release note: None