Use PG_FINALLY to simplify code

Started by Hou, Zhijiealmost 6 years ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t43010
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 06:29 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t43010_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t43010_1 && git checkout t43010_1

Patchset v1 (message #1) is on t43010_1

Jump to latest
#1Hou, Zhijie
houzj.fnst@cn.fujitsu.com

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:

t43010_1
0001-adjust-code-to-use-PG_FINALLY.patchapplication/octet-stream; name=0001-adjust-code-to-use-PG_FINALLY.patchDownload+1-6
#2Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Hou, Zhijie (#1)
Re: Use PG_FINALLY to simplify code

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kyotaro Horiguchi (#2)
Re: Use PG_FINALLY to simplify code

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

#4Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Tom Lane (#3)
Re: Use PG_FINALLY to simplify code

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