Skip to content

Commit 27e0441

Browse files
committed
Stop using PQsendQuery in libpq_pipeline
The "emulation" I wrote for PQsendQuery in pipeline mode to use extended query protocol, in commit acb7e4e, is problematic. Due to numerous bugs we'll soon remove it. As a first step and for all branches back to 14, stop using PQsendQuery in libpq_pipeline. Also remove a few test lines that will no longer be relevant. Backpatch to 14. Discussion: https://postgr.es/m/CA+mi_8ZGSQNmW6-mk_iSR4JZB_LJ4ww3suOF+1vGNs3MrLsv4g@mail.gmail.com
1 parent a2ab0ad commit 27e0441

File tree

3 files changed

+13
-198
lines changed

3 files changed

+13
-198
lines changed

src/test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 8 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ test_pipeline_abort(PGconn *conn)
499499
PQerrorMessage(conn));
500500

501501
/* Try to send two queries in one command */
502-
if (PQsendQuery(conn, "SELECT 1; SELECT 2") != 1)
502+
if (PQsendQueryParams(conn, "SELECT 1; SELECT 2", 0, NULL, NULL, NULL, NULL, 0) != 1)
503503
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
504504
if (PQpipelineSync(conn) != 1)
505505
pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
@@ -531,7 +531,8 @@ test_pipeline_abort(PGconn *conn)
531531
fprintf(stderr, "ok\n");
532532

533533
/* Test single-row mode with an error partways */
534-
if (PQsendQuery(conn, "SELECT 1.0/g FROM generate_series(3, -1, -1) g") != 1)
534+
if (PQsendQueryParams(conn, "SELECT 1.0/g FROM generate_series(3, -1, -1) g",
535+
0, NULL, NULL, NULL, NULL, 0) != 1)
535536
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
536537
if (PQpipelineSync(conn) != 1)
537538
pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
@@ -991,133 +992,10 @@ test_pipeline_idle(PGconn *conn)
991992

992993
PQsetNoticeProcessor(conn, notice_processor, &n_notices);
993994

994-
/*
995-
* Cause a Close message to be sent to the server, and watch libpq's
996-
* reaction to the resulting CloseComplete. libpq must not get in IDLE
997-
* state until that has been received.
998-
*/
999-
if (PQenterPipelineMode(conn) != 1)
1000-
pg_fatal("failed to enter pipeline mode: %s", PQerrorMessage(conn));
1001-
1002-
if (PQsendQuery(conn, "SELECT 1") != 1)
1003-
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
1004-
PQsendFlushRequest(conn);
1005-
res = PQgetResult(conn);
1006-
if (res == NULL)
1007-
pg_fatal("PQgetResult returned null when there's a pipeline item: %s",
1008-
PQerrorMessage(conn));
1009-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1010-
pg_fatal("Unexpected result code %s from first pipeline item",
1011-
PQresStatus(PQresultStatus(res)));
1012-
PQclear(res);
1013-
1014-
res = PQgetResult(conn);
1015-
if (res != NULL)
1016-
pg_fatal("expected NULL result");
1017-
1018-
if (PQpipelineSync(conn) != 1)
1019-
pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
1020-
res = PQgetResult(conn);
1021-
if (res == NULL)
1022-
pg_fatal("PQgetResult returned null when there's a pipeline item: %s",
1023-
PQerrorMessage(conn));
1024-
if (PQresultStatus(res) != PGRES_PIPELINE_SYNC)
1025-
pg_fatal("Unexpected result code %s instead of PGRES_PIPELINE_SYNC, error: %s",
1026-
PQresStatus(PQresultStatus(res)), PQerrorMessage(conn));
1027-
PQclear(res);
1028-
res = NULL;
1029-
1030-
if (PQexitPipelineMode(conn) != 1)
1031-
pg_fatal("attempt to exit pipeline mode failed when it should've succeeded: %s",
1032-
PQerrorMessage(conn));
1033-
1034-
/*
1035-
* Must not have got any notices here; note bug as described in
1036-
* https://postgr.es/m/CA+mi_8bvD0_CW3sumgwPvWdNzXY32itoG_16tDYRu_1S2gV2iw@mail.gmail.com
1037-
*/
1038-
if (n_notices > 0)
1039-
pg_fatal("got %d notice(s)", n_notices);
1040-
fprintf(stderr, "ok - 1\n");
1041-
1042-
/*
1043-
* Verify that we can send a query using simple query protocol after one
1044-
* in pipeline mode.
1045-
*/
1046-
if (PQenterPipelineMode(conn) != 1)
1047-
pg_fatal("failed to enter pipeline mode: %s", PQerrorMessage(conn));
1048-
if (PQsendQuery(conn, "SELECT 1") != 1)
1049-
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
1050-
PQsendFlushRequest(conn);
1051-
res = PQgetResult(conn);
1052-
if (res == NULL)
1053-
pg_fatal("PQgetResult returned null when there's a pipeline item: %s",
1054-
PQerrorMessage(conn));
1055-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1056-
pg_fatal("unexpected result code %s from first pipeline item",
1057-
PQresStatus(PQresultStatus(res)));
1058-
res = PQgetResult(conn);
1059-
if (res != NULL)
1060-
pg_fatal("got unexpected non-null result");
1061-
/* We can exit pipeline mode now */
1062-
if (PQexitPipelineMode(conn) != 1)
1063-
pg_fatal("attempt to exit pipeline mode failed when it should've succeeded: %s",
1064-
PQerrorMessage(conn));
1065-
res = PQexec(conn, "SELECT 2");
1066-
if (n_notices > 0)
1067-
pg_fatal("got %d notice(s)", n_notices);
1068-
if (res == NULL)
1069-
pg_fatal("PQexec returned NULL");
1070-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1071-
pg_fatal("unexpected result code %s from non-pipeline query",
1072-
PQresStatus(PQresultStatus(res)));
1073-
res = PQgetResult(conn);
1074-
if (res != NULL)
1075-
pg_fatal("did not receive terminating NULL");
1076-
if (n_notices > 0)
1077-
pg_fatal("got %d notice(s)", n_notices);
1078-
fprintf(stderr, "ok - 2\n");
1079-
1080-
/*
1081-
* Case 2: exiting pipeline mode is not OK if a second command is sent.
1082-
*/
1083-
1084-
if (PQenterPipelineMode(conn) != 1)
1085-
pg_fatal("failed to enter pipeline mode: %s", PQerrorMessage(conn));
1086-
if (PQsendQuery(conn, "SELECT 1") != 1)
1087-
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
1088-
PQsendFlushRequest(conn);
1089-
res = PQgetResult(conn);
1090-
if (res == NULL)
1091-
pg_fatal("PQgetResult returned null when there's a pipeline item: %s",
1092-
PQerrorMessage(conn));
1093-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1094-
pg_fatal("unexpected result code %s from first pipeline item",
1095-
PQresStatus(PQresultStatus(res)));
1096-
if (PQsendQuery(conn, "SELECT 2") != 1)
1097-
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
1098-
PQsendFlushRequest(conn);
1099-
/* read terminating null from first query */
1100-
res = PQgetResult(conn);
1101-
if (res != NULL)
1102-
pg_fatal("did not receive terminating NULL");
1103-
res = PQgetResult(conn);
1104-
if (res == NULL)
1105-
pg_fatal("PQgetResult returned null when there's a pipeline item: %s",
1106-
PQerrorMessage(conn));
1107-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1108-
pg_fatal("unexpected result code %s from first pipeline item",
1109-
PQresStatus(PQresultStatus(res)));
1110-
res = PQgetResult(conn);
1111-
if (res != NULL)
1112-
pg_fatal("did not receive terminating NULL");
1113-
if (PQexitPipelineMode(conn) != 1)
1114-
pg_fatal("attempt to exit pipeline mode failed when it should've succeeded: %s",
1115-
PQerrorMessage(conn));
1116-
1117995
/* Try to exit pipeline mode in pipeline-idle state */
1118996
if (PQenterPipelineMode(conn) != 1)
1119997
pg_fatal("failed to enter pipeline mode: %s", PQerrorMessage(conn));
1120-
if (PQsendQuery(conn, "SELECT 1") != 1)
998+
if (PQsendQueryParams(conn, "SELECT 1", 0, NULL, NULL, NULL, NULL, 0) != 1)
1121999
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
11221000
PQsendFlushRequest(conn);
11231001
res = PQgetResult(conn);
@@ -1131,7 +1009,7 @@ test_pipeline_idle(PGconn *conn)
11311009
res = PQgetResult(conn);
11321010
if (res != NULL)
11331011
pg_fatal("did not receive terminating NULL");
1134-
if (PQsendQuery(conn, "SELECT 2") != 1)
1012+
if (PQsendQueryParams(conn, "SELECT 2", 0, NULL, NULL, NULL, NULL, 0) != 1)
11351013
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
11361014
if (PQexitPipelineMode(conn) == 1)
11371015
pg_fatal("exiting pipeline succeeded when it shouldn't");
@@ -1153,12 +1031,12 @@ test_pipeline_idle(PGconn *conn)
11531031

11541032
if (n_notices > 0)
11551033
pg_fatal("got %d notice(s)", n_notices);
1156-
fprintf(stderr, "ok - 3\n");
1034+
fprintf(stderr, "ok - 1\n");
11571035

11581036
/* Have a WARNING in the middle of a resultset */
11591037
if (PQenterPipelineMode(conn) != 1)
11601038
pg_fatal("entering pipeline mode failed: %s", PQerrorMessage(conn));
1161-
if (PQsendQuery(conn, "SELECT pg_catalog.pg_advisory_unlock(1,1)") != 1)
1039+
if (PQsendQueryParams(conn, "SELECT pg_catalog.pg_advisory_unlock(1,1)", 0, NULL, NULL, NULL, NULL, 0) != 1)
11621040
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
11631041
PQsendFlushRequest(conn);
11641042
res = PQgetResult(conn);
@@ -1168,7 +1046,7 @@ test_pipeline_idle(PGconn *conn)
11681046
pg_fatal("unexpected result code %s", PQresStatus(PQresultStatus(res)));
11691047
if (PQexitPipelineMode(conn) != 1)
11701048
pg_fatal("failed to exit pipeline mode: %s", PQerrorMessage(conn));
1171-
fprintf(stderr, "ok - 4\n");
1049+
fprintf(stderr, "ok - 2\n");
11721050
}
11731051

11741052
static void

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,16 @@ B 4 NoData
3535
B 15 CommandComplete "INSERT 0 1"
3636
B 5 ReadyForQuery I
3737
F 26 Parse "" "SELECT 1; SELECT 2" 0
38-
F 12 Bind "" "" 0 0 0
38+
F 14 Bind "" "" 0 0 1 0
3939
F 6 Describe P ""
4040
F 9 Execute "" 0
41-
F 6 Close P ""
4241
F 4 Sync
4342
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
4443
B 5 ReadyForQuery I
4544
F 54 Parse "" "SELECT 1.0/g FROM generate_series(3, -1, -1) g" 0
46-
F 12 Bind "" "" 0 0 0
45+
F 14 Bind "" "" 0 0 1 0
4746
F 6 Describe P ""
4847
F 9 Execute "" 0
49-
F 6 Close P ""
5048
F 4 Sync
5149
B 4 ParseComplete
5250
B 4 BindComplete
Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,32 @@
11
F 16 Parse "" "SELECT 1" 0
2-
F 12 Bind "" "" 0 0 0
2+
F 14 Bind "" "" 0 0 1 0
33
F 6 Describe P ""
44
F 9 Execute "" 0
5-
F 6 Close P ""
65
F 4 Flush
76
B 4 ParseComplete
87
B 4 BindComplete
98
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
109
B 11 DataRow 1 1 '1'
1110
B 13 CommandComplete "SELECT 1"
12-
B 4 CloseComplete
13-
F 4 Sync
14-
B 5 ReadyForQuery I
15-
F 16 Parse "" "SELECT 1" 0
16-
F 12 Bind "" "" 0 0 0
17-
F 6 Describe P ""
18-
F 9 Execute "" 0
19-
F 6 Close P ""
20-
F 4 Flush
21-
B 4 ParseComplete
22-
B 4 BindComplete
23-
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
24-
B 11 DataRow 1 1 '1'
25-
B 13 CommandComplete "SELECT 1"
26-
B 4 CloseComplete
27-
F 13 Query "SELECT 2"
28-
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
29-
B 11 DataRow 1 1 '2'
30-
B 13 CommandComplete "SELECT 1"
31-
B 5 ReadyForQuery I
32-
F 16 Parse "" "SELECT 1" 0
33-
F 12 Bind "" "" 0 0 0
34-
F 6 Describe P ""
35-
F 9 Execute "" 0
36-
F 6 Close P ""
37-
F 4 Flush
38-
B 4 ParseComplete
39-
B 4 BindComplete
40-
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
41-
B 11 DataRow 1 1 '1'
42-
B 13 CommandComplete "SELECT 1"
43-
B 4 CloseComplete
44-
F 16 Parse "" "SELECT 2" 0
45-
F 12 Bind "" "" 0 0 0
46-
F 6 Describe P ""
47-
F 9 Execute "" 0
48-
F 6 Close P ""
49-
F 4 Flush
50-
B 4 ParseComplete
51-
B 4 BindComplete
52-
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
53-
B 11 DataRow 1 1 '2'
54-
B 13 CommandComplete "SELECT 1"
55-
B 4 CloseComplete
56-
F 16 Parse "" "SELECT 1" 0
57-
F 12 Bind "" "" 0 0 0
58-
F 6 Describe P ""
59-
F 9 Execute "" 0
60-
F 6 Close P ""
61-
F 4 Flush
62-
B 4 ParseComplete
63-
B 4 BindComplete
64-
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
65-
B 11 DataRow 1 1 '1'
66-
B 13 CommandComplete "SELECT 1"
67-
B 4 CloseComplete
6811
F 16 Parse "" "SELECT 2" 0
69-
F 12 Bind "" "" 0 0 0
12+
F 14 Bind "" "" 0 0 1 0
7013
F 6 Describe P ""
7114
F 9 Execute "" 0
72-
F 6 Close P ""
7315
F 4 Flush
7416
B 4 ParseComplete
7517
B 4 BindComplete
7618
B 33 RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
7719
B 11 DataRow 1 1 '2'
7820
B 13 CommandComplete "SELECT 1"
79-
B 4 CloseComplete
8021
F 49 Parse "" "SELECT pg_catalog.pg_advisory_unlock(1,1)" 0
81-
F 12 Bind "" "" 0 0 0
22+
F 14 Bind "" "" 0 0 1 0
8223
F 6 Describe P ""
8324
F 9 Execute "" 0
84-
F 6 Close P ""
8525
F 4 Flush
8626
B 4 ParseComplete
8727
B 4 BindComplete
8828
B 43 RowDescription 1 "pg_advisory_unlock" NNNN 0 NNNN 1 -1 0
8929
B NN NoticeResponse S "WARNING" V "WARNING" C "01000" M "you don't own a lock of type ExclusiveLock" F "SSSS" L "SSSS" R "SSSS" \x00
9030
B 11 DataRow 1 1 'f'
9131
B 13 CommandComplete "SELECT 1"
92-
B 4 CloseComplete
9332
F 4 Terminate

0 commit comments

Comments
 (0)