本节介绍ProcessQuery函数。
相关数据结构
//src/include/executor/execdesc.h
typedef struct QueryDesc
{
CmdType operation;
PlannedStmt *plannedstmt;
const char *sourceText;
Snapshot snapshot;
Snapshot crosscheck_snapshot;
DestReceiver *dest;
ParamListInfo params;
QueryEnvironment *queryEnv;
int instrument_options;
TupleDesc tupDesc;
EState *estate;
PlanState *planstate;
bool already_executed;
struct Instrumentation *totaltime;
} QueryDesc;
ProcessQuery函数
static void
ProcessQuery(PlannedStmt *plan,
const char *sourceText,
ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest,
char *completionTag);
//src/backend/tcop/pquery.c
queryDesc = CreateQueryDesc(plan, sourceText,
GetActiveSnapshot(), InvalidSnapshot,
dest, params, queryEnv, 0);
ExecutorStart(queryDesc, 0);
ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);
if (completionTag)
{
switch (queryDesc->operation)
{
case CMD_SELECT:
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
"SELECT " UINT64_FORMAT,
queryDesc->estate->es_processed);
break;
case CMD_INSERT:
lastOid = InvalidOid;
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
"INSERT %u " UINT64_FORMAT,
lastOid, queryDesc->estate->es_processed);
break;
case CMD_UPDATE:
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
"UPDATE " UINT64_FORMAT,
queryDesc->estate->es_processed);
break;
case CMD_DELETE:
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
"DELETE " UINT64_FORMAT,
queryDesc->estate->es_processed);
break;
default:
strcpy(completionTag, "???");
break;
}
}
ExecutorFinish(queryDesc);
ExecutorEnd(queryDesc);
FreeQueryDesc(queryDesc);