Consider pipeline implicit transaction as a transaction block

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Consider pipeline implicit transaction as a transaction block
Date: 2024-10-30 09:14:55
Message-ID: CAO6_XqrWO8uNBQrSu5r6jh+vTGi5Oiyk4y8yXDORdE2jbzw8xw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

When using pipelining with implicit transaction, a transaction will
start from the first command and be committed with the Sync message.
Functions like IsInTransactionBlock and PreventInTransactionBlock
already assimilate this implicit transaction as a transaction block,
relying on the XACT_FLAGS_PIPELINING flag. However, this is not the
case in CheckTransactionBlock. This function is used for things like
warning when a local GUC is set outside of a transaction block.

The attached patch adds the detection of implicit transactions started
by a pipeline in CheckTransactionBlock, avoiding warnings when
commands like `set local` are called within a pipeline, and making the
detection of transaction block coherent with what's done in
IsInTransactionBlock and PreventInTransactionBlock.

One thing that's still not fixed by the patch is that the first
command won't be seen as part of a transaction block. For example,
with pgbench:

\startpipeline
SET LOCAL statement_timeout='200ms';
SELECT * FROM pgbench_accounts where aid=1;
\endpipeline

The XACT_FLAGS_PIPELINING will only be set after the first command, so
the warning about `set local` happening outside of a transaction block
will still be generated. However, I'm not sure if it's something
fixable (or worth fixing?). This would require to know beforehand that
there are multiple executes before the sync message, which doesn't
seem doable.

Regards,
Anthonin

Attachment Content-Type Size
v01-0001-Consider-pipeline-implicit-transaction-as-a-tran.patch application/octet-stream 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-10-30 09:21:04 Re: Add isolation test template in injection_points for wait/wakeup/detach
Previous Message Kirill Reshke 2024-10-30 09:07:41 Re: Useless field ispartitioned in CreateStmtContext