本节介绍PortalRunMulti函数。
PortalRunMulti函数
static void
PortalRunMulti(Portal portal,
bool isTopLevel, bool setHoldSnapshot,
DestReceiver *dest, DestReceiver *altdest,
char *completionTag);
//src/backend/tcop/pquery.c
if (dest->mydest == DestRemoteExecute)
dest = None_Receiver;
if (altdest->mydest == DestRemoteExecute)
altdest = None_Receiver;
foreach(stmtlist_item, portal->stmts)
{
PlannedStmt *pstmt = lfirst_node(PlannedStmt, stmtlist_item);
CHECK_FOR_INTERRUPTS();
if (pstmt->utilityStmt == NULL)
{
TRACE_POSTGRESQL_QUERY_EXECUTE_START();
if (log_executor_stats)
ResetUsage();
if (!active_snapshot_set)
{
Snapshot snapshot = GetTransactionSnapshot();
if (setHoldSnapshot)
{
snapshot = RegisterSnapshot(snapshot);
portal->holdSnapshot = snapshot;
}
PushCopiedSnapshot(snapshot);
active_snapshot_set = true;
}
UpdateActiveSnapshotCommandId();
if (pstmt->canSetTag)
{
ProcessQuery(pstmt,
portal->sourceText,
portal->portalParams,
portal->queryEnv,
dest, completionTag);
}
else
{
ProcessQuery(pstmt,
portal->sourceText,
portal->portalParams,
portal->queryEnv,
altdest, NULL);
}
if (log_executor_stats)
ShowUsage("EXECUTOR STATISTICS");
TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
}
else
{
if (pstmt->canSetTag)
{
Assert(!active_snapshot_set);
PortalRunUtility(portal, pstmt, isTopLevel, false,
dest, completionTag);
}
else
{
Assert(IsA(pstmt->utilityStmt, NotifyStmt));
PortalRunUtility(portal, pstmt, isTopLevel, false,
altdest, NULL);
}
}
if (lnext(stmtlist_item) != NULL)
CommandCounterIncrement();
Assert(portal->portalContext == CurrentMemoryContext);
MemoryContextDeleteChildren(portal->portalContext);
}
if (active_snapshot_set)
PopActiveSnapshot();
if (completionTag && completionTag[0] == "")
{
if (portal->commandTag)
strcpy(completionTag, portal->commandTag);
if (strcmp(completionTag, "SELECT") == 0)
sprintf(completionTag, "SELECT 0 0");
else if (strcmp(completionTag, "INSERT") == 0)
strcpy(completionTag, "INSERT 0 0");
else if (strcmp(completionTag, "UPDATE") == 0)
strcpy(completionTag, "UPDATE 0");
else if (strcmp(completionTag, "DELETE") == 0)
strcpy(completionTag, "DELETE 0");
}