Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4efcf47

Browse files
committed
Add 'Portal Close' message to pipelined PQsendQuery()
Commit acb7e4e added a new implementation for PQsendQuery so that it works in pipeline mode (by using extended query protocol), but it behaves differently from the 'Q' message (in simple query protocol) used by regular implementation: the new one doesn't close the unnamed portal. Change the new code to have identical behavior to the old. Reported-by: Yura Sokolov <y.sokolov@postgrespro.ru> Author: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/202106072107.d4i55hdscxqj@alvherre.pgsql
1 parent 1632ea4 commit 4efcf47

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,8 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
13291329
{
13301330
/*
13311331
* In pipeline mode we cannot use the simple protocol, so we send
1332-
* Parse, Bind, Describe Portal, Execute.
1332+
* Parse, Bind, Describe Portal, Execute, Close Portal (with the
1333+
* unnamed portal).
13331334
*/
13341335
if (pqPutMsgStart('P', conn) < 0 ||
13351336
pqPuts("", conn) < 0 ||
@@ -1355,6 +1356,11 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
13551356
pqPutInt(0, 4, conn) < 0 ||
13561357
pqPutMsgEnd(conn) < 0)
13571358
goto sendFailed;
1359+
if (pqPutMsgStart('C', conn) < 0 ||
1360+
pqPutc('P', conn) < 0 ||
1361+
pqPuts("", conn) < 0 ||
1362+
pqPutMsgEnd(conn) < 0)
1363+
goto sendFailed;
13581364

13591365
entry->queryclass = PGQUERY_EXTENDED;
13601366
entry->query = strdup(query);

src/test/modules/libpq_pipeline/traces/pipeline_abort.trace

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ F 26 Parse "" "SELECT 1; SELECT 2" 0
3838
F 12 Bind "" "" 0 0 0
3939
F 6 Describe P ""
4040
F 9 Execute "" 0
41+
F 6 Close P ""
4142
F 4 Sync
4243
B NN ErrorResponse S "ERROR" V "ERROR" C "42601" M "cannot insert multiple commands into a prepared statement" F "SSSS" L "SSSS" R "SSSS" \x00
4344
B 5 ReadyForQuery I
4445
F 54 Parse "" "SELECT 1.0/g FROM generate_series(3, -1, -1) g" 0
4546
F 12 Bind "" "" 0 0 0
4647
F 6 Describe P ""
4748
F 9 Execute "" 0
49+
F 6 Close P ""
4850
F 4 Sync
4951
B 4 ParseComplete
5052
B 4 BindComplete

0 commit comments

Comments
 (0)