Re: pgbench: using prepared BEGIN statement in a pipeline could cause an error

From: Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgbench: using prepared BEGIN statement in a pipeline could cause an error
Date: 2022-09-30 01:07:43
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Mon, 12 Sep 2022 17:03:43 +0200
Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:

> On 2022-Mar-28, Yugo NAGATA wrote:
> > On Fri, 25 Mar 2022 16:19:54 -0400
> > Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > > I am not convinced this is a great idea. The current behavior is that
> > > a statement is not prepared until it's about to be executed, and I think
> > > we chose that deliberately to avoid semantic differences between prepared
> > > and not-prepared mode. For example, if a script looks like
> > >
> > > CREATE FUNCTION foo(...) ...;
> > > SELECT foo(...);
> > > DROP FUNCTION foo;
> > >
> > > trying to prepare the SELECT in advance would lead to failure.
> > >
> > > We could perhaps get away with preparing the commands within a pipeline
> > > just before we start to execute the pipeline, but it looks to me like
> > > this patch tries to prepare the entire script in advance.
> Maybe it would work to have one extra boolean in struct Command, indicating
> that the i-th command in the script is inside a pipeline; in -M
> prepared, issue PREPARE for each command marked with that flag ahead of
> time, and for all other commands, do as today. That way, we don't
> change behavior for anything except those commands that need the change.

Well, I still don't understand why we need to prepare only "the
commands within a pipeline" before starting pipeline. In the current
behavior, the entire script is prepared in advance just before executing
the first SQL command in the script, instead of preparing each command
one by one. This patch also prepare the entire script in advance, so
there is no behavioural change in this sense.

However, there are a few behavioural changes. One is that the preparation
is not counted in the command performance statistics as Fabien mentioned.
Another is that all meta-commands including \shell and \sleep etc. are
executed before the preparation.

To reduce impact of these changes, I updated the patch to prepare the
commands just before executing the first SQL command or \startpipeline
meta-command instead of at the beginning of the script.

Yugo Nagata

> --
> Álvaro Herrera 48°01'N 7°57'E —
> "Digital and video cameras have this adjustment and film cameras don't for the
> same reason dogs and cats lick themselves: because they can." (Ken Rockwell)

Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
v6-pgbench-prepare.patch text/x-diff 3.7 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo NAGATA 2022-09-30 01:12:13 Re: SI-read predicate locks on materialized views
Previous Message Andres Freund 2022-09-30 00:40:18 Re: longfin and tamandua aren't too happy but I'm not sure why