* pquery.c
* POSTGRES process query command code
*
- * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.126 2008/11/30 20:51:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.134 2010/01/02 16:57:52 momjian 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,
ParamListInfo params,
- bool doInstrument)
+ int instrument_options)
{
QueryDesc *qd = (QueryDesc *) palloc(sizeof(QueryDesc));
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);
qd->dest = dest; /* output dest */
qd->params = params; /* parameter values passed into query */
- qd->doInstrument = doInstrument; /* instrumentation wanted? */
+ qd->instrument_options = instrument_options; /* instrumentation wanted? */
/* null these fields until set by ExecutorStart */
qd->tupDesc = NULL;
*/
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 */
qd->params = params; /* parameter values passed into query */
- qd->doInstrument = false; /* uninteresting for utilities */
+ qd->instrument_options = false; /* uninteresting for utilities */
/* null these fields until set by ExecutorStart */
qd->tupDesc = NULL;
* 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);
+ dest, params, 0);
/*
* Set up to collect AFTER triggers
{
if (++nSetTag > 1)
return PORTAL_MULTI_QUERY; /* no need to look further */
- if (pstmt->returningLists == NIL)
+ if (!pstmt->hasReturning)
return PORTAL_MULTI_QUERY; /* no need to look further */
}
}
pstmt->utilityStmt == NULL &&
pstmt->intoClause == NULL)
return pstmt->planTree->targetlist;
- if (pstmt->returningLists)
- return (List *) linitial(pstmt->returningLists);
+ if (pstmt->hasReturning)
+ return pstmt->planTree->targetlist;
return NIL;
}
if (IsA(stmt, FetchStmt))
* the destination to DestNone.
*/
queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),
+ portal->sourceText,
GetActiveSnapshot(),
InvalidSnapshot,
None_Receiver,
params,
- false);
+ 0);
/*
* We do *not* call AfterTriggerBeginQuery() here. We assume
pstmt = (PlannedStmt *) PortalGetPrimaryStmt(portal);
Assert(IsA(pstmt, PlannedStmt));
- Assert(pstmt->returningLists);
+ Assert(pstmt->hasReturning);
portal->tupDesc =
- ExecCleanTypeFromTL((List *) linitial(pstmt->returningLists),
+ ExecCleanTypeFromTL(pstmt->planTree->targetlist,
false);
}
if (log_executor_stats && portal->strategy != PORTAL_MULTI_QUERY)
ShowUsage("EXECUTOR STATISTICS");
-
+
TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
return result;
treceiver = CreateDestReceiver(DestTuplestore);
SetTuplestoreDestReceiverParams(treceiver,
portal->holdStore,
- portal->holdContext);
+ portal->holdContext,
+ false);
completionTag[0] = '\0';
oldcontext = MemoryContextSwitchTo(portal->holdContext);
- ok = tuplestore_gettupleslot(portal->holdStore, forward, slot);
+ ok = tuplestore_gettupleslot(portal->holdStore, forward, false,
+ slot);
MemoryContextSwitchTo(oldcontext);
PortalRunUtility(Portal portal, Node *utilityStmt, bool isTopLevel,
DestReceiver *dest, char *completionTag)
{
- bool active_snapshot_set;
+ bool active_snapshot_set;
elog(DEBUG3, "ProcessUtility");
/*
* Some utility commands may pop the ActiveSnapshot stack from under us,
- * so we only pop the stack if we actually see a snapshot set. Note that
+ * so we only pop the stack if we actually see a snapshot set. Note that
* the set of utility commands that do this must be the same set
* disallowed to run inside a transaction; otherwise, we could be popping
* a snapshot that belongs to some other operation.
{
/* 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);
}