Skip to content

Commit d11a41a

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 e3e6ee6 commit d11a41a

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
@@ -497,7 +497,7 @@ test_pipeline_abort(PGconn *conn)
497497
PQerrorMessage(conn));
498498

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

531531
/* Test single-row mode with an error partways */
532-
if (PQsendQuery(conn, "SELECT 1.0/g FROM generate_series(3, -1, -1) g") != 1)
532+
if (PQsendQueryParams(conn, "SELECT 1.0/g FROM generate_series(3, -1, -1) g",
533+
0, NULL, NULL, NULL, NULL, 0) != 1)
533534
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
534535
if (PQpipelineSync(conn) != 1)
535536
pg_fatal("pipeline sync failed: %s", PQerrorMessage(conn));
@@ -989,133 +990,10 @@ test_pipeline_idle(PGconn *conn)
989990

990991
PQsetNoticeProcessor(conn, notice_processor, &n_notices);
991992

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

11521030
if (n_notices > 0)
11531031
pg_fatal("got %d notice(s)", n_notices);
1154-
fprintf(stderr, "ok - 3\n");
1032+
fprintf(stderr, "ok - 1\n");
11551033

11561034
/* Have a WARNING in the middle of a resultset */
11571035
if (PQenterPipelineMode(conn) != 1)
11581036
pg_fatal("entering pipeline mode failed: %s", PQerrorMessage(conn));
1159-
if (PQsendQuery(conn, "SELECT pg_catalog.pg_advisory_unlock(1,1)") != 1)
1037+
if (PQsendQueryParams(conn, "SELECT pg_catalog.pg_advisory_unlock(1,1)", 0, NULL, NULL, NULL, NULL, 0) != 1)
11601038
pg_fatal("failed to send query: %s", PQerrorMessage(conn));
11611039
PQsendFlushRequest(conn);
11621040
res = PQgetResult(conn);
@@ -1166,7 +1044,7 @@ test_pipeline_idle(PGconn *conn)
11661044
pg_fatal("unexpected result code %s", PQresStatus(PQresultStatus(res)));
11671045
if (PQexitPipelineMode(conn) != 1)
11681046
pg_fatal("failed to exit pipeline mode: %s", PQerrorMessage(conn));
1169-
fprintf(stderr, "ok - 4\n");
1047+
fprintf(stderr, "ok - 2\n");
11701048
}
11711049

11721050
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)