aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-05-06 20:26:28 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-05-06 20:26:28 +0000
commit79913910d4b518a42c893b6dd459656798ffa591 (patch)
treef0cd5c25dff8d026b9d8d4736717a4d38c278134 /src/backend/commands/explain.c
parent299fbb4b379003557f79d2732a85ece168d04ec4 (diff)
downloadpostgresql-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/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 2504d69fd06..28a6e0378c8 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.107 2003/05/06 00:20:31 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.108 2003/05/06 20:26:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -67,21 +67,15 @@ static Node *make_ors_ands_explicit(List *orclauses);
* execute an EXPLAIN command
*/
void
-ExplainQuery(ExplainStmt *stmt, CommandDest dest)
+ExplainQuery(ExplainStmt *stmt, DestReceiver *dest)
{
Query *query = stmt->query;
TupOutputState *tstate;
- TupleDesc tupdesc;
List *rewritten;
List *l;
- /* need a tuple descriptor representing a single TEXT column */
- tupdesc = CreateTemplateTupleDesc(1, false);
- TupleDescInitEntry(tupdesc, (AttrNumber) 1, "QUERY PLAN",
- TEXTOID, -1, 0, false);
-
/* prepare for projection of tuples */
- tstate = begin_tup_output_tupdesc(dest, tupdesc);
+ tstate = begin_tup_output_tupdesc(dest, ExplainResultDesc(stmt));
if (query->commandType == CMD_UTILITY)
{
@@ -120,6 +114,22 @@ ExplainQuery(ExplainStmt *stmt, CommandDest dest)
}
/*
+ * ExplainResultDesc -
+ * construct the result tupledesc for an EXPLAIN
+ */
+TupleDesc
+ExplainResultDesc(ExplainStmt *stmt)
+{
+ TupleDesc tupdesc;
+
+ /* need a tuple descriptor representing a single TEXT column */
+ tupdesc = CreateTemplateTupleDesc(1, false);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 1, "QUERY PLAN",
+ TEXTOID, -1, 0, false);
+ return tupdesc;
+}
+
+/*
* ExplainOneQuery -
* print out the execution plan for one query
*/
@@ -169,7 +179,7 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
plan = planner(query, isCursor, cursorOptions);
/* Create a QueryDesc requesting no output */
- queryDesc = CreateQueryDesc(query, plan, None, NULL, NULL,
+ queryDesc = CreateQueryDesc(query, plan, None_Receiver, NULL, NULL,
stmt->analyze);
ExplainOnePlan(queryDesc, stmt, tstate);