Skip to content

Commit b6e5823

Browse files
committed
Marginal hacks to move some processing out of the per-client-message
processing loop; avoids extra overhead when using parse/bind/execute messages instead of single Query message.
1 parent fcb90fd commit b6e5823

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

src/backend/tcop/postgres.c

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.358 2003/08/12 18:23:21 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.359 2003/08/12 18:52:38 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2023,7 +2023,7 @@ PostgresMain(int argc, char *argv[], const char *username)
20232023
GucSource gucsource;
20242024
char *tmp;
20252025
int firstchar;
2026-
StringInfo input_message;
2026+
StringInfoData input_message;
20272027
volatile bool send_rfq = true;
20282028

20292029
/*
@@ -2646,7 +2646,7 @@ PostgresMain(int argc, char *argv[], const char *username)
26462646
if (!IsUnderPostmaster)
26472647
{
26482648
puts("\nPOSTGRES backend interactive interface ");
2649-
puts("$Revision: 1.358 $ $Date: 2003/08/12 18:23:21 $\n");
2649+
puts("$Revision: 1.359 $ $Date: 2003/08/12 18:52:38 $\n");
26502650
}
26512651

26522652
/*
@@ -2765,35 +2765,36 @@ PostgresMain(int argc, char *argv[], const char *username)
27652765
MemoryContextSwitchTo(MessageContext);
27662766
MemoryContextResetAndDeleteChildren(MessageContext);
27672767

2768-
input_message = makeStringInfo();
2768+
initStringInfo(&input_message);
27692769

27702770
/*
2771-
* (1) tell the frontend we're ready for a new query.
2771+
* (1) If we've reached idle state, tell the frontend we're ready
2772+
* for a new query.
27722773
*
27732774
* Note: this includes fflush()'ing the last of the prior output.
2775+
*
2776+
* This is also a good time to send collected statistics to the
2777+
* collector, and to update the PS stats display. We avoid doing
2778+
* those every time through the message loop because it'd slow down
2779+
* processing of batched messages.
27742780
*/
27752781
if (send_rfq)
27762782
{
2777-
ReadyForQuery(whereToSendOutput);
2778-
send_rfq = false;
2779-
}
2783+
pgstat_report_tabstat();
27802784

2781-
/* ----------
2782-
* Tell the statistics collector what we've collected
2783-
* so far.
2784-
* ----------
2785-
*/
2786-
pgstat_report_tabstat();
2785+
if (IsTransactionBlock())
2786+
{
2787+
set_ps_display("idle in transaction");
2788+
pgstat_report_activity("<IDLE> in transaction");
2789+
}
2790+
else
2791+
{
2792+
set_ps_display("idle");
2793+
pgstat_report_activity("<IDLE>");
2794+
}
27872795

2788-
if (IsTransactionBlock())
2789-
{
2790-
set_ps_display("idle in transaction");
2791-
pgstat_report_activity("<IDLE> in transaction");
2792-
}
2793-
else
2794-
{
2795-
set_ps_display("idle");
2796-
pgstat_report_activity("<IDLE>");
2796+
ReadyForQuery(whereToSendOutput);
2797+
send_rfq = false;
27972798
}
27982799

27992800
/*
@@ -2815,7 +2816,7 @@ PostgresMain(int argc, char *argv[], const char *username)
28152816
/*
28162817
* (3) read a command (loop blocks here)
28172818
*/
2818-
firstchar = ReadCommand(input_message);
2819+
firstchar = ReadCommand(&input_message);
28192820

28202821
/*
28212822
* (4) disable async signal conditions again.
@@ -2848,8 +2849,8 @@ PostgresMain(int argc, char *argv[], const char *username)
28482849
{
28492850
const char *query_string;
28502851

2851-
query_string = pq_getmsgstring(input_message);
2852-
pq_getmsgend(input_message);
2852+
query_string = pq_getmsgstring(&input_message);
2853+
pq_getmsgend(&input_message);
28532854

28542855
exec_simple_query(query_string);
28552856

@@ -2864,18 +2865,18 @@ PostgresMain(int argc, char *argv[], const char *username)
28642865
int numParams;
28652866
Oid *paramTypes = NULL;
28662867

2867-
stmt_name = pq_getmsgstring(input_message);
2868-
query_string = pq_getmsgstring(input_message);
2869-
numParams = pq_getmsgint(input_message, 2);
2868+
stmt_name = pq_getmsgstring(&input_message);
2869+
query_string = pq_getmsgstring(&input_message);
2870+
numParams = pq_getmsgint(&input_message, 2);
28702871
if (numParams > 0)
28712872
{
28722873
int i;
28732874

28742875
paramTypes = (Oid *) palloc(numParams * sizeof(Oid));
28752876
for (i = 0; i < numParams; i++)
2876-
paramTypes[i] = pq_getmsgint(input_message, 4);
2877+
paramTypes[i] = pq_getmsgint(&input_message, 4);
28772878
}
2878-
pq_getmsgend(input_message);
2879+
pq_getmsgend(&input_message);
28792880

28802881
exec_parse_message(query_string, stmt_name,
28812882
paramTypes, numParams);
@@ -2888,17 +2889,17 @@ PostgresMain(int argc, char *argv[], const char *username)
28882889
* this message is complex enough that it seems best to
28892890
* put the field extraction out-of-line
28902891
*/
2891-
exec_bind_message(input_message);
2892+
exec_bind_message(&input_message);
28922893
break;
28932894

28942895
case 'E': /* execute */
28952896
{
28962897
const char *portal_name;
28972898
int max_rows;
28982899

2899-
portal_name = pq_getmsgstring(input_message);
2900-
max_rows = pq_getmsgint(input_message, 4);
2901-
pq_getmsgend(input_message);
2900+
portal_name = pq_getmsgstring(&input_message);
2901+
max_rows = pq_getmsgint(&input_message, 4);
2902+
pq_getmsgend(&input_message);
29022903

29032904
exec_execute_message(portal_name, max_rows);
29042905
}
@@ -2914,7 +2915,7 @@ PostgresMain(int argc, char *argv[], const char *username)
29142915
/* switch back to message context */
29152916
MemoryContextSwitchTo(MessageContext);
29162917

2917-
if (HandleFunctionRequest(input_message) == EOF)
2918+
if (HandleFunctionRequest(&input_message) == EOF)
29182919
{
29192920
/* lost frontend connection during F message input */
29202921

@@ -2939,9 +2940,9 @@ PostgresMain(int argc, char *argv[], const char *username)
29392940
int close_type;
29402941
const char *close_target;
29412942

2942-
close_type = pq_getmsgbyte(input_message);
2943-
close_target = pq_getmsgstring(input_message);
2944-
pq_getmsgend(input_message);
2943+
close_type = pq_getmsgbyte(&input_message);
2944+
close_target = pq_getmsgstring(&input_message);
2945+
pq_getmsgend(&input_message);
29452946

29462947
switch (close_type)
29472948
{
@@ -2987,9 +2988,9 @@ PostgresMain(int argc, char *argv[], const char *username)
29872988
int describe_type;
29882989
const char *describe_target;
29892990

2990-
describe_type = pq_getmsgbyte(input_message);
2991-
describe_target = pq_getmsgstring(input_message);
2992-
pq_getmsgend(input_message);
2991+
describe_type = pq_getmsgbyte(&input_message);
2992+
describe_target = pq_getmsgstring(&input_message);
2993+
pq_getmsgend(&input_message);
29932994

29942995
switch (describe_type)
29952996
{
@@ -3010,13 +3011,13 @@ PostgresMain(int argc, char *argv[], const char *username)
30103011
break;
30113012

30123013
case 'H': /* flush */
3013-
pq_getmsgend(input_message);
3014+
pq_getmsgend(&input_message);
30143015
if (whereToSendOutput == Remote)
30153016
pq_flush();
30163017
break;
30173018

30183019
case 'S': /* sync */
3019-
pq_getmsgend(input_message);
3020+
pq_getmsgend(&input_message);
30203021
finish_xact_command();
30213022
send_rfq = true;
30223023
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy