Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c03166

Browse files
committed
Stop using PQsendQuery in libpq_pipeline
The "emulation" I wrote for PQsendQuery in pipeline mode to use extendedquery protocol, in commitacb7e4e, is problematic. Due to numerousbugs we'll soon remove it. As a first step and for all branches back to14, stop using PQsendQuery in libpq_pipeline. Also remove a few testlines 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 parent2193461 commit1c03166

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
staticvoid

‎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 @@ B4NoData
3535
B15CommandComplete "INSERT 0 1"
3636
B5ReadyForQuery I
3737
F26Parse "" "SELECT 1; SELECT 2" 0
38-
F12Bind "" "" 0 0 0
38+
F14Bind "" "" 0 0 1 0
3939
F6Describe P ""
4040
F9Execute "" 0
41-
F6Close P ""
4241
F4Sync
4342
BNNErrorResponse S "ERROR" V "ERROR" C "42601" M "cannot insert multiple commands into a prepared statement" F "SSSS" L "SSSS" R "SSSS" \x00
4443
B5ReadyForQuery I
4544
F54Parse "" "SELECT 1.0/g FROM generate_series(3, -1, -1) g" 0
46-
F12Bind "" "" 0 0 0
45+
F14Bind "" "" 0 0 1 0
4746
F6Describe P ""
4847
F9Execute "" 0
49-
F6Close P ""
5048
F4Sync
5149
B4ParseComplete
5250
B4BindComplete
Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,32 @@
11
F16Parse "" "SELECT 1" 0
2-
F12Bind "" "" 0 0 0
2+
F14Bind "" "" 0 0 1 0
33
F6Describe P ""
44
F9Execute "" 0
5-
F6Close P ""
65
F4Flush
76
B4ParseComplete
87
B4BindComplete
98
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
109
B11DataRow 1 1 '1'
1110
B13CommandComplete "SELECT 1"
12-
B4CloseComplete
13-
F4Sync
14-
B5ReadyForQuery I
15-
F16Parse "" "SELECT 1" 0
16-
F12Bind "" "" 0 0 0
17-
F6Describe P ""
18-
F9Execute "" 0
19-
F6Close P ""
20-
F4Flush
21-
B4ParseComplete
22-
B4BindComplete
23-
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
24-
B11DataRow 1 1 '1'
25-
B13CommandComplete "SELECT 1"
26-
B4CloseComplete
27-
F13Query "SELECT 2"
28-
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
29-
B11DataRow 1 1 '2'
30-
B13CommandComplete "SELECT 1"
31-
B5ReadyForQuery I
32-
F16Parse "" "SELECT 1" 0
33-
F12Bind "" "" 0 0 0
34-
F6Describe P ""
35-
F9Execute "" 0
36-
F6Close P ""
37-
F4Flush
38-
B4ParseComplete
39-
B4BindComplete
40-
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
41-
B11DataRow 1 1 '1'
42-
B13CommandComplete "SELECT 1"
43-
B4CloseComplete
44-
F16Parse "" "SELECT 2" 0
45-
F12Bind "" "" 0 0 0
46-
F6Describe P ""
47-
F9Execute "" 0
48-
F6Close P ""
49-
F4Flush
50-
B4ParseComplete
51-
B4BindComplete
52-
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
53-
B11DataRow 1 1 '2'
54-
B13CommandComplete "SELECT 1"
55-
B4CloseComplete
56-
F16Parse "" "SELECT 1" 0
57-
F12Bind "" "" 0 0 0
58-
F6Describe P ""
59-
F9Execute "" 0
60-
F6Close P ""
61-
F4Flush
62-
B4ParseComplete
63-
B4BindComplete
64-
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
65-
B11DataRow 1 1 '1'
66-
B13CommandComplete "SELECT 1"
67-
B4CloseComplete
6811
F16Parse "" "SELECT 2" 0
69-
F12Bind "" "" 0 0 0
12+
F14Bind "" "" 0 0 1 0
7013
F6Describe P ""
7114
F9Execute "" 0
72-
F6Close P ""
7315
F4Flush
7416
B4ParseComplete
7517
B4BindComplete
7618
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
7719
B11DataRow 1 1 '2'
7820
B13CommandComplete "SELECT 1"
79-
B4CloseComplete
8021
F49Parse "" "SELECT pg_catalog.pg_advisory_unlock(1,1)" 0
81-
F12Bind "" "" 0 0 0
22+
F14Bind "" "" 0 0 1 0
8223
F6Describe P ""
8324
F9Execute "" 0
84-
F6Close P ""
8525
F4Flush
8626
B4ParseComplete
8727
B4BindComplete
8828
B43RowDescription 1 "pg_advisory_unlock" NNNN 0 NNNN 1 -1 0
8929
BNNNoticeResponse S "WARNING" V "WARNING" C "01000" M "you don't own a lock of type ExclusiveLock" F "SSSS" L "SSSS" R "SSSS" \x00
9030
B11DataRow 1 1 'f'
9131
B13CommandComplete "SELECT 1"
92-
B4CloseComplete
9332
F4Terminate

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp