From 79913910d4b518a42c893b6dd459656798ffa591 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 6 May 2003 20:26:28 +0000 Subject: 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. --- src/backend/commands/explain.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/backend/commands/explain.c') 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) { @@ -119,6 +113,22 @@ ExplainQuery(ExplainStmt *stmt, CommandDest dest) end_tup_output(tstate); } +/* + * 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); -- cgit v1.2.3