1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Restructure command destination handling so that we pass around

DestReceiver pointers instead of just CommandDest values.  The DestReceiver
is made at the point where the destination is selected, rather than
deep inside the executor.  This cleans up the original kluge implementation
of tstoreReceiver.c, and makes it easy to support retrieving results
from utility statements inside portals.  Thus, you can now do fun things
like Bind and Execute a FETCH or EXPLAIN command, and it'll all work
as expected (e.g., you can Describe the portal, or use Execute's count
parameter to suspend the output partway through).  Implementation involves
stuffing the utility command's output into a Tuplestore, which would be
kind of annoying for huge output sets, but should be quite acceptable
for typical uses of utility commands.
This commit is contained in:
Tom Lane
2003-05-06 20:26:28 +00:00
parent 299fbb4b37
commit 79913910d4
28 changed files with 698 additions and 349 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.335 2003/05/06 05:15:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.336 2003/05/06 20:26:27 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -656,6 +656,8 @@ pg_plan_queries(List *querytrees, bool needSnapshot)
static void
exec_simple_query(const char *query_string)
{
CommandDest dest = whereToSendOutput;
DestReceiver *receiver;
MemoryContext oldcontext;
List *parsetree_list,
*parsetree_item;
@ -682,6 +684,12 @@ exec_simple_query(const char *query_string)
if (save_log_statement_stats)
ResetUsage();
/*
* Create destination receiver object --- we can reuse it for all
* queries in the string. Note it is created in MessageContext.
*/
receiver = CreateDestReceiver(dest);
/*
* Start up a transaction command. All queries generated by the
* query_string will be in this same command block, *unless* we find a
@ -745,7 +753,7 @@ exec_simple_query(const char *query_string)
set_ps_display(commandTag);
BeginCommand(commandTag, whereToSendOutput);
BeginCommand(commandTag, dest);
/*
* If we are in an aborted transaction, reject all commands except
@ -819,8 +827,8 @@ exec_simple_query(const char *query_string)
(void) PortalRun(portal,
FETCH_ALL,
whereToSendOutput,
whereToSendOutput,
receiver,
receiver,
completionTag);
PortalDrop(portal, false);
@ -868,14 +876,16 @@ exec_simple_query(const char *query_string)
* (But a command aborted by error will not send an EndCommand
* report at all.)
*/
EndCommand(completionTag, whereToSendOutput);
EndCommand(completionTag, dest);
} /* end loop over parsetrees */
/*
* If there were no parsetrees, return EmptyQueryResponse message.
*/
if (!parsetree_list)
NullCommand(whereToSendOutput);
NullCommand(dest);
(*receiver->destroy) (receiver);
QueryContext = NULL;
@ -1282,6 +1292,7 @@ static void
exec_execute_message(const char *portal_name, int is_binary, long max_rows)
{
CommandDest dest;
DestReceiver *receiver;
Portal portal;
bool is_trans_stmt = false;
bool is_trans_exit = false;
@ -1363,15 +1374,19 @@ exec_execute_message(const char *portal_name, int is_binary, long max_rows)
/*
* Okay to run the portal.
*/
receiver = CreateDestReceiver(dest);
if (max_rows <= 0)
max_rows = FETCH_ALL;
completed = PortalRun(portal,
max_rows,
dest,
dest,
receiver,
receiver,
completionTag);
(*receiver->destroy) (receiver);
if (completed)
{
if (is_trans_stmt)
@ -2344,7 +2359,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.335 $ $Date: 2003/05/06 05:15:45 $\n");
puts("$Revision: 1.336 $ $Date: 2003/05/06 20:26:27 $\n");
}
/*
@ -2412,7 +2427,6 @@ PostgresMain(int argc, char *argv[], const char *username)
*/
MemoryContextSwitchTo(TopMemoryContext);
MemoryContextResetAndDeleteChildren(ErrorContext);
CurrentPortal = NULL;
PortalContext = NULL;
QueryContext = NULL;