*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.303 2009/01/01 17:23:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.304 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
((DR_copy *) dest)->cstate = cstate;
/* Create a QueryDesc requesting no output */
- cstate->queryDesc = CreateQueryDesc(plan, GetActiveSnapshot(),
+ cstate->queryDesc = CreateQueryDesc(plan, queryString,
+ GetActiveSnapshot(),
InvalidSnapshot,
dest, NULL, false);
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.183 2009/01/01 17:23:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.184 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
plan = pg_plan_query(query, 0, params);
/* run it (if needed) and produce output */
- ExplainOnePlan(plan, params, stmt, tstate);
+ ExplainOnePlan(plan, stmt, queryString, params, tstate);
}
}
* to call it.
*/
void
-ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
- ExplainStmt *stmt, TupOutputState *tstate)
+ExplainOnePlan(PlannedStmt *plannedstmt, ExplainStmt *stmt,
+ const char *queryString, ParamListInfo params,
+ TupOutputState *tstate)
{
QueryDesc *queryDesc;
instr_time starttime;
PushUpdatedSnapshot(GetActiveSnapshot());
/* Create a QueryDesc requesting no output */
- queryDesc = CreateQueryDesc(plannedstmt,
+ queryDesc = CreateQueryDesc(plannedstmt, queryString,
GetActiveSnapshot(), InvalidSnapshot,
None_Receiver, params,
stmt->analyze);
* Copyright (c) 2002-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.95 2009/01/01 17:23:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.96 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Implements the 'EXPLAIN EXECUTE' utility statement.
+ *
+ * Note: the passed-in queryString is that of the EXPLAIN EXECUTE,
+ * not the original PREPARE; we get the latter string from the plancache.
*/
void
ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt,
ParamListInfo params, TupOutputState *tstate)
{
PreparedStatement *entry;
+ const char *query_string;
CachedPlan *cplan;
List *plan_list;
ListCell *p;
if (!entry->plansource->fixed_result)
elog(ERROR, "EXPLAIN EXECUTE does not support variable-result cached plans");
+ query_string = entry->plansource->query_string;
+
/* Replan if needed, and acquire a transient refcount */
cplan = RevalidateCachedPlan(entry->plansource, true);
pstmt->intoClause = execstmt->into;
}
- ExplainOnePlan(pstmt, paramLI, stmt, tstate);
+ ExplainOnePlan(pstmt, stmt, query_string,
+ paramLI, tstate);
}
else
{
- ExplainOneUtility((Node *) pstmt, stmt, queryString,
+ ExplainOneUtility((Node *) pstmt, stmt, query_string,
params, tstate);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.131 2009/01/01 17:23:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.132 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (IsA(es->stmt, PlannedStmt))
es->qd = CreateQueryDesc((PlannedStmt *) es->stmt,
+ fcache->src,
snapshot, InvalidSnapshot,
dest,
fcache->paramLI, false);
else
es->qd = CreateUtilityQueryDesc(es->stmt,
+ fcache->src,
snapshot,
dest,
fcache->paramLI);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.203 2009/01/01 17:23:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.204 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
snap = InvalidSnapshot;
qdesc = CreateQueryDesc((PlannedStmt *) stmt,
+ plansource->query_string,
snap, crosscheck_snapshot,
dest,
paramLI, false);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.128 2009/01/01 17:23:48 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.129 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void ProcessQuery(PlannedStmt *plan,
+ const char *sourceText,
ParamListInfo params,
DestReceiver *dest,
char *completionTag);
*/
QueryDesc *
CreateQueryDesc(PlannedStmt *plannedstmt,
+ const char *sourceText,
Snapshot snapshot,
Snapshot crosscheck_snapshot,
DestReceiver *dest,
qd->operation = plannedstmt->commandType; /* operation */
qd->plannedstmt = plannedstmt; /* plan */
qd->utilitystmt = plannedstmt->utilityStmt; /* in case DECLARE CURSOR */
+ qd->sourceText = sourceText; /* query text */
qd->snapshot = RegisterSnapshot(snapshot); /* snapshot */
/* RI check snapshot */
qd->crosscheck_snapshot = RegisterSnapshot(crosscheck_snapshot);
*/
QueryDesc *
CreateUtilityQueryDesc(Node *utilitystmt,
+ const char *sourceText,
Snapshot snapshot,
DestReceiver *dest,
ParamListInfo params)
qd->operation = CMD_UTILITY; /* operation */
qd->plannedstmt = NULL;
qd->utilitystmt = utilitystmt; /* utility command */
+ qd->sourceText = sourceText; /* query text */
qd->snapshot = RegisterSnapshot(snapshot); /* snapshot */
qd->crosscheck_snapshot = InvalidSnapshot; /* RI check snapshot */
qd->dest = dest; /* output dest */
* or PORTAL_ONE_RETURNING portal
*
* plan: the plan tree for the query
+ * sourceText: the source text of the query
* params: any parameters needed
* dest: where to send results
* completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
*/
static void
ProcessQuery(PlannedStmt *plan,
+ const char *sourceText,
ParamListInfo params,
DestReceiver *dest,
char *completionTag)
/*
* Create the QueryDesc object
*/
- queryDesc = CreateQueryDesc(plan,
+ queryDesc = CreateQueryDesc(plan, sourceText,
GetActiveSnapshot(), InvalidSnapshot,
dest, params, false);
* the destination to DestNone.
*/
queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),
+ portal->sourceText,
GetActiveSnapshot(),
InvalidSnapshot,
None_Receiver,
{
/* statement can set tag string */
ProcessQuery(pstmt,
+ portal->sourceText,
portal->portalParams,
dest, completionTag);
}
{
/* stmt added by rewrite cannot set tag */
ProcessQuery(pstmt,
+ portal->sourceText,
portal->portalParams,
altdest, NULL);
}
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.37 2009/01/01 17:23:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.38 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ParamListInfo params,
TupOutputState *tstate);
-extern void ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
- ExplainStmt *stmt, TupOutputState *tstate);
+extern void ExplainOnePlan(PlannedStmt *plannedstmt, ExplainStmt *stmt,
+ const char *queryString,
+ ParamListInfo params,
+ TupOutputState *tstate);
extern void ExplainPrintPlan(StringInfo str, QueryDesc *queryDesc,
bool analyze, bool verbose);
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/executor/execdesc.h,v 1.39 2009/01/01 17:23:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/executor/execdesc.h,v 1.40 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
CmdType operation; /* CMD_SELECT, CMD_UPDATE, etc. */
PlannedStmt *plannedstmt; /* planner's output, or null if utility */
Node *utilitystmt; /* utility statement, or null */
+ const char *sourceText; /* source text of the query */
Snapshot snapshot; /* snapshot to use for query */
Snapshot crosscheck_snapshot; /* crosscheck for RI update/delete */
DestReceiver *dest; /* the destination for tuple output */
/* in pquery.c */
extern QueryDesc *CreateQueryDesc(PlannedStmt *plannedstmt,
+ const char *sourceText,
Snapshot snapshot,
Snapshot crosscheck_snapshot,
DestReceiver *dest,
bool doInstrument);
extern QueryDesc *CreateUtilityQueryDesc(Node *utilitystmt,
+ const char *sourceText,
Snapshot snapshot,
DestReceiver *dest,
ParamListInfo params);