PostgreSQL源码学习–执行器#10,11

PostgreSQL源码学习–执行器#10,11本节介绍standard_ExecutorRun和ExecutorRun函数。 standard_ExecutorRun函数 //src/include/execurot/executor.h ex…

PostgreSQL源码学习--执行器#10,11

本节介绍standard_ExecutorRun和ExecutorRun函数。

standard_ExecutorRun函数

//src/include/execurot/executor.h

extern void standard_ExecutorRun(QueryDesc *queryDesc,
			 ScanDirection direction, uint64 count, bool execute_once);

代码100分

代码100分//src/backend/executor/execMain.c

Assert(queryDesc != NULL);

estate = queryDesc->estate;

Assert(estate != NULL);
Assert(!(estate->es_top_eflags & EXEC_FLAG_EXPLAIN_ONLY));

/* 切换为每个查询对应的内存上下文 */
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);

/* 视情况开始执行器运行时间统计 */
if (queryDesc->totaltime)
	InstrStartNode(queryDesc->totaltime);

operation = queryDesc->operation;
dest = queryDesc->dest;

/* 若要发送元组,启动元组接收器 */
estate->es_processed = 0;

sendTuples = (operation == CMD_SELECT ||
		  queryDesc->plannedstmt->hasReturning);

if (sendTuples)
	dest->rStartup(dest, operation, queryDesc->tupDesc);

/* 执行plan */
if (!ScanDirectionIsNoMovement(direction))
{
	if (execute_once && queryDesc->already_executed)
		elog(ERROR, "can"t re-execute query flagged for single execution");
	queryDesc->already_executed = true;

	ExecutePlan(estate,
		queryDesc->planstate,
		queryDesc->plannedstmt->parallelModeNeeded,
		operation,
		sendTuples,
		count,
		direction,
		dest,
		execute_once);
}

/* 关闭元组接收器 */
if (sendTuples)
	dest->rShutdown(dest);

/* 结束执行器计时 */
if (queryDesc->totaltime)
	InstrStopNode(queryDesc->totaltime, estate->es_processed);

/* 切回内存上下文 */
MemoryContextSwitchTo(oldcontext);

ExecutorRun函数

void
ExecutorRun(QueryDesc *queryDesc,
			ScanDirection direction, uint64 count,
			bool execute_once)
{
	if (ExecutorRun_hook)
		(*ExecutorRun_hook) (queryDesc, direction, count, execute_once);
	else
		standard_ExecutorRun(queryDesc, direction, count, execute_once);
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/7889.html

(0)
上一篇 2023-03-11
下一篇 2023-03-12

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注