diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-06 20:26:28 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-06 20:26:28 +0000 |
commit | 79913910d4b518a42c893b6dd459656798ffa591 (patch) | |
tree | f0cd5c25dff8d026b9d8d4736717a4d38c278134 /src/backend/tcop/postgres.c | |
parent | 299fbb4b379003557f79d2732a85ece168d04ec4 (diff) | |
download | postgresql-79913910d4b518a42c893b6dd459656798ffa591.tar.gz postgresql-79913910d4b518a42c893b6dd459656798ffa591.zip |
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.
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 0ec7fcf71d8..a7dd5cb904a 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -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; @@ -683,6 +685,12 @@ exec_simple_query(const char *query_string) 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 * BEGIN/COMMIT/ABORT statement; we have to force a new xact command @@ -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; |