Re: Using PQexecQuery in pipeline mode produces unexpected Close messages

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: alvherre(at)alvh(dot)no-ip(dot)org
Cc: daniele(dot)varrazzo(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Using PQexecQuery in pipeline mode produces unexpected Close messages
Date: 2022-06-10 06:25:44
Message-ID: 20220610.152544.1597540405935332165.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

(Moved to -hackers)

At Wed, 8 Jun 2022 17:08:47 +0200, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote in
> What that Close message is doing is closing the unnamed portal, which
> is otherwise closed implicitly when the next one is opened. That's how
> single-query mode works: if you run a single portal, it'll be kept open.
>
> I believe that the right fix is to not send that Close message in
> PQsendQuery.

Agreed. At least Close message in that context is useless and
PQsendQueryGuts doesn't send it. And removes the Close message surely
fixes the issue.

The doc [1] says:

[1] https://www.postgresql.org/docs/14/protocol-flow.html

> The simple Query message is approximately equivalent to the series
> Parse, Bind, portal Describe, Execute, Close, Sync, using the
> unnamed prepared statement and portal objects and no parameters. One

The current implement of PQsendQueryInternal looks like the result of
a misunderstanding of the doc. In the regression tests, that path is
excercised only for an error case, where no CloseComplete comes.

The attached adds a test for the normal-path of pipelined
PQsendQuery() to simple_pipeline test then modifies that function not
to send Close message. Without the fix, the test fails by "unexpected
notice" even if the trace matches the "expected" content.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
0001-Remove-useless-Close-message-from-PQsendQuery-in-pip.patch text/x-patch 5.7 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kyotaro Horiguchi 2022-06-10 06:33:36 Re: Using PQexecQuery in pipeline mode produces unexpected Close messages
Previous Message okano.naoki@fujitsu.com 2022-06-10 05:09:19 RE: BUG #17514: Application with embedded SQL crashes when executing EXEC SQL PREPARE

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-06-10 06:26:57 Re: Support logical replication of DDLs
Previous Message Thomas Munro 2022-06-10 05:56:35 Re: Collation version tracking for macOS