Use PG_FINALLY to simplify code
Hi
In (/src/pl/plpgsql/src/pl_exec.c), I found some code like the following:
PG_CATCH();
{
if (expr->plan && !expr->plan->saved)
expr->plan = NULL;
PG_RE_THROW();
}
PG_END_TRY();
if (expr->plan && !expr->plan->saved)
expr->plan = NULL;
Since PG_FINALLY can be used now, I think we can use PG_FINALLY to simplify code here.
Best regards,
houzj
Attachments:
0001-adjust-code-to-use-PG_FINALLY.patchapplication/octet-stream; name=0001-adjust-code-to-use-PG_FINALLY.patchDownload
From a2f690f92acaced14ee8f1ce8889ef27e6705237 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Tue, 29 Sep 2020 04:50:33 -0400
Subject: [PATCH] adjust code to use PG_FINALLY
---
src/pl/plpgsql/src/pl_exec.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index d4a3d58..1fe4974 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -2313,7 +2313,7 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
rc = SPI_execute_plan_with_paramlist(expr->plan, paramLI,
estate->readonly_func, 0);
}
- PG_CATCH();
+ PG_FINALLY();
{
/*
* If we aren't saving the plan, unset the pointer. Note that it
@@ -2321,13 +2321,9 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
*/
if (expr->plan && !expr->plan->saved)
expr->plan = NULL;
- PG_RE_THROW();
}
PG_END_TRY();
- if (expr->plan && !expr->plan->saved)
- expr->plan = NULL;
-
if (rc < 0)
elog(ERROR, "SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
expr->query, SPI_result_code_string(rc));
--
1.8.3.1
At Tue, 29 Sep 2020 01:03:13 +0000, "Hou, Zhijie" <houzj.fnst@cn.fujitsu.com> wrote in
In (/src/pl/plpgsql/src/pl_exec.c), I found some code like the following:
PG_CATCH();
{
if (expr->plan && !expr->plan->saved)
expr->plan = NULL;
PG_RE_THROW();
}
PG_END_TRY();if (expr->plan && !expr->plan->saved)
expr->plan = NULL;Since PG_FINALLY can be used now, I think we can use PG_FINALLY to simplify code here.
The patch removes PG_RETHROW(), which is crucial in the code
path. There's at least one other instance of that coding in pquery.c
but PG_FINALLY() is not applicable there for the same reason, too.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Kyotaro Horiguchi <horikyota.ntt@gmail.com> writes:
At Tue, 29 Sep 2020 01:03:13 +0000, "Hou, Zhijie" <houzj.fnst@cn.fujitsu.com> wrote in
Since PG_FINALLY can be used now, I think we can use PG_FINALLY to simplify code here.
The patch removes PG_RETHROW(), which is crucial in the code
path.
No, that's not a problem, because PG_FINALLY incorporates logic
to reproduce the PG_RE_THROW action if we get to the code block
due to an error being thrown.
The patch is nonetheless moot, because after a6b1f5365 those
two code paths are no longer identical.
regards, tom lane
At Tue, 29 Sep 2020 23:10:52 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in
tgl> Kyotaro Horiguchi <horikyota.ntt@gmail.com> writes:
tgl> > At Tue, 29 Sep 2020 01:03:13 +0000, "Hou, Zhijie" <houzj.fnst@cn.fujitsu.com> wrote in
tgl> >> Since PG_FINALLY can be used now, I think we can use PG_FINALLY to simplify code here.
tgl>
tgl> > The patch removes PG_RETHROW(), which is crucial in the code
tgl> > path.
tgl>
tgl> No, that's not a problem, because PG_FINALLY incorporates logic
tgl> to reproduce the PG_RE_THROW action if we get to the code block
tgl> due to an error being thrown.
Oops! Sorry. It's exactly the definition of finally block.
tgl> The patch is nonetheless moot, because after a6b1f5365 those
tgl> two code paths are no longer identical.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center