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.
This commit is contained in:
Tom Lane 2003-08-12 18:52:38 +00:00
parent fcb90fdc95
commit b6e5823eda
1 changed files with 45 additions and 44 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.358 2003/08/12 18:23:21 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.359 2003/08/12 18:52:38 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -2023,7 +2023,7 @@ PostgresMain(int argc, char *argv[], const char *username)
GucSource gucsource; GucSource gucsource;
char *tmp; char *tmp;
int firstchar; int firstchar;
StringInfo input_message; StringInfoData input_message;
volatile bool send_rfq = true; volatile bool send_rfq = true;
/* /*
@ -2646,7 +2646,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.358 $ $Date: 2003/08/12 18:23:21 $\n"); puts("$Revision: 1.359 $ $Date: 2003/08/12 18:52:38 $\n");
} }
/* /*
@ -2765,37 +2765,38 @@ PostgresMain(int argc, char *argv[], const char *username)
MemoryContextSwitchTo(MessageContext); MemoryContextSwitchTo(MessageContext);
MemoryContextResetAndDeleteChildren(MessageContext); MemoryContextResetAndDeleteChildren(MessageContext);
input_message = makeStringInfo(); initStringInfo(&input_message);
/* /*
* (1) tell the frontend we're ready for a new query. * (1) If we've reached idle state, tell the frontend we're ready
* for a new query.
* *
* Note: this includes fflush()'ing the last of the prior output. * Note: this includes fflush()'ing the last of the prior output.
*
* This is also a good time to send collected statistics to the
* collector, and to update the PS stats display. We avoid doing
* those every time through the message loop because it'd slow down
* processing of batched messages.
*/ */
if (send_rfq) if (send_rfq)
{ {
pgstat_report_tabstat();
if (IsTransactionBlock())
{
set_ps_display("idle in transaction");
pgstat_report_activity("<IDLE> in transaction");
}
else
{
set_ps_display("idle");
pgstat_report_activity("<IDLE>");
}
ReadyForQuery(whereToSendOutput); ReadyForQuery(whereToSendOutput);
send_rfq = false; send_rfq = false;
} }
/* ----------
* Tell the statistics collector what we've collected
* so far.
* ----------
*/
pgstat_report_tabstat();
if (IsTransactionBlock())
{
set_ps_display("idle in transaction");
pgstat_report_activity("<IDLE> in transaction");
}
else
{
set_ps_display("idle");
pgstat_report_activity("<IDLE>");
}
/* /*
* (2) deal with pending asynchronous NOTIFY from other backends, * (2) deal with pending asynchronous NOTIFY from other backends,
* and enable async.c's signal handler to execute NOTIFY directly. * and enable async.c's signal handler to execute NOTIFY directly.
@ -2815,7 +2816,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/* /*
* (3) read a command (loop blocks here) * (3) read a command (loop blocks here)
*/ */
firstchar = ReadCommand(input_message); firstchar = ReadCommand(&input_message);
/* /*
* (4) disable async signal conditions again. * (4) disable async signal conditions again.
@ -2848,8 +2849,8 @@ PostgresMain(int argc, char *argv[], const char *username)
{ {
const char *query_string; const char *query_string;
query_string = pq_getmsgstring(input_message); query_string = pq_getmsgstring(&input_message);
pq_getmsgend(input_message); pq_getmsgend(&input_message);
exec_simple_query(query_string); exec_simple_query(query_string);
@ -2864,18 +2865,18 @@ PostgresMain(int argc, char *argv[], const char *username)
int numParams; int numParams;
Oid *paramTypes = NULL; Oid *paramTypes = NULL;
stmt_name = pq_getmsgstring(input_message); stmt_name = pq_getmsgstring(&input_message);
query_string = pq_getmsgstring(input_message); query_string = pq_getmsgstring(&input_message);
numParams = pq_getmsgint(input_message, 2); numParams = pq_getmsgint(&input_message, 2);
if (numParams > 0) if (numParams > 0)
{ {
int i; int i;
paramTypes = (Oid *) palloc(numParams * sizeof(Oid)); paramTypes = (Oid *) palloc(numParams * sizeof(Oid));
for (i = 0; i < numParams; i++) for (i = 0; i < numParams; i++)
paramTypes[i] = pq_getmsgint(input_message, 4); paramTypes[i] = pq_getmsgint(&input_message, 4);
} }
pq_getmsgend(input_message); pq_getmsgend(&input_message);
exec_parse_message(query_string, stmt_name, exec_parse_message(query_string, stmt_name,
paramTypes, numParams); paramTypes, numParams);
@ -2888,7 +2889,7 @@ PostgresMain(int argc, char *argv[], const char *username)
* this message is complex enough that it seems best to * this message is complex enough that it seems best to
* put the field extraction out-of-line * put the field extraction out-of-line
*/ */
exec_bind_message(input_message); exec_bind_message(&input_message);
break; break;
case 'E': /* execute */ case 'E': /* execute */
@ -2896,9 +2897,9 @@ PostgresMain(int argc, char *argv[], const char *username)
const char *portal_name; const char *portal_name;
int max_rows; int max_rows;
portal_name = pq_getmsgstring(input_message); portal_name = pq_getmsgstring(&input_message);
max_rows = pq_getmsgint(input_message, 4); max_rows = pq_getmsgint(&input_message, 4);
pq_getmsgend(input_message); pq_getmsgend(&input_message);
exec_execute_message(portal_name, max_rows); exec_execute_message(portal_name, max_rows);
} }
@ -2914,7 +2915,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/* switch back to message context */ /* switch back to message context */
MemoryContextSwitchTo(MessageContext); MemoryContextSwitchTo(MessageContext);
if (HandleFunctionRequest(input_message) == EOF) if (HandleFunctionRequest(&input_message) == EOF)
{ {
/* lost frontend connection during F message input */ /* lost frontend connection during F message input */
@ -2939,9 +2940,9 @@ PostgresMain(int argc, char *argv[], const char *username)
int close_type; int close_type;
const char *close_target; const char *close_target;
close_type = pq_getmsgbyte(input_message); close_type = pq_getmsgbyte(&input_message);
close_target = pq_getmsgstring(input_message); close_target = pq_getmsgstring(&input_message);
pq_getmsgend(input_message); pq_getmsgend(&input_message);
switch (close_type) switch (close_type)
{ {
@ -2987,9 +2988,9 @@ PostgresMain(int argc, char *argv[], const char *username)
int describe_type; int describe_type;
const char *describe_target; const char *describe_target;
describe_type = pq_getmsgbyte(input_message); describe_type = pq_getmsgbyte(&input_message);
describe_target = pq_getmsgstring(input_message); describe_target = pq_getmsgstring(&input_message);
pq_getmsgend(input_message); pq_getmsgend(&input_message);
switch (describe_type) switch (describe_type)
{ {
@ -3010,13 +3011,13 @@ PostgresMain(int argc, char *argv[], const char *username)
break; break;
case 'H': /* flush */ case 'H': /* flush */
pq_getmsgend(input_message); pq_getmsgend(&input_message);
if (whereToSendOutput == Remote) if (whereToSendOutput == Remote)
pq_flush(); pq_flush();
break; break;
case 'S': /* sync */ case 'S': /* sync */
pq_getmsgend(input_message); pq_getmsgend(&input_message);
finish_xact_command(); finish_xact_command();
send_rfq = true; send_rfq = true;
break; break;