Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
120045: plpgsql: allow nested blocks in a block with an exception handler r=DrewKimball a=DrewKimball

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

120207: server: remove interfaces with single implementation r=dt a=stevendanna

This removes some interfaces with only 1 implementation from the server controller code and moves more of the server controller methods into server_controller.go

While the intent of these interfaces was to facilitate testing, that work was never completed and the currently they mostly serve to make the code a bit harder to navigate.

While having the code in shorter files is sometimes nice, in this case I think in this case it is mostly a hinderance to seeing the full scope of behaviors.

Epic: none
Release note: None

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
Co-authored-by: Steven Danna <danna@cockroachlabs.com>
  • Loading branch information
3 people committed Mar 12, 2024
3 parents 38880d9 + dc19dfc + 6d3fc19 commit 431d568
Show file tree
Hide file tree
Showing 11 changed files with 594 additions and 713 deletions.
50 changes: 31 additions & 19 deletions pkg/ccl/logictestccl/testdata/logic_test/plpgsql_block
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,37 @@ NOTICE: outer handler
NOTICE: inner block
NOTICE: inner handler 100

# A block can be nested inside another block that has an exception handler.
statement ok
DROP PROCEDURE p;
CREATE PROCEDURE p() AS $$
DECLARE
x INT := 0;
BEGIN
RAISE NOTICE 'outer block: %', x;
BEGIN
x := x + 1;
RAISE NOTICE 'inner block: %', x;
SELECT 1 // 0;
EXCEPTION WHEN division_by_zero THEN
x := x + 1;
RAISE NOTICE 'inner handler: %', x;
SELECT 1 // 0;
END;
EXCEPTION WHEN division_by_zero THEN
x := x + 1;
RAISE NOTICE 'outer handler: %', x;
END
$$ LANGUAGE PLpgSQL;

query T noticetrace
CALL p();
----
NOTICE: outer block: 0
NOTICE: inner block: 1
NOTICE: inner handler: 2
NOTICE: outer handler: 3

subtest error

statement ok
Expand Down Expand Up @@ -457,25 +488,6 @@ CREATE PROCEDURE p() AS $$
END
$$ LANGUAGE PLpgSQL;

# A block cannot currently be nested in a block with an exception handler
# (tracked in #118551).
statement error pgcode 0A000 pq: unimplemented: PL/pgSQL blocks cannot yet be nested within a block that has an exception handler
CREATE PROCEDURE p() AS $$
DECLARE
x INT := 0;
BEGIN
RAISE NOTICE '%', x;
DECLARE
y INT := 1 // x;
BEGIN
RAISE NOTICE '% %', x, y;
END;
EXCEPTION
WHEN division_by_zero THEN
RAISE NOTICE 'oops!';
END
$$ LANGUAGE PLpgSQL;

# Regression test for the internal error in #119492.
subtest regression_119492

Expand Down
3 changes: 0 additions & 3 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ go_library(
"rlimit_unix.go",
"server.go",
"server_controller.go",
"server_controller_accessors.go",
"server_controller_channel_orchestrator.go",
"server_controller_http.go",
"server_controller_new_server.go",
"server_controller_orchestration.go",
"server_controller_orchestration_method.go",
"server_controller_sql.go",
"server_http.go",
"server_obs_service.go",
Expand Down

0 comments on commit 431d568

Please sign in to comment.