⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 execprocnode.c

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------- * * execProcnode.c *	 contains dispatch functions which call the appropriate "initialize", *	 "get a tuple", and "cleanup" routines for the given node type. *	 If the node has children, then it will presumably call ExecInitNode, *	 ExecProcNode, or ExecEndNode on its subnodes and do the appropriate *	 processing. * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.51 2005/10/15 02:49:16 momjian Exp $ * *------------------------------------------------------------------------- *//* *	 INTERFACE ROUTINES *		ExecCountSlotsNode -	count tuple slots needed by plan tree *		ExecInitNode	-		initialize a plan node and its subplans *		ExecProcNode	-		get a tuple by executing the plan node *		ExecEndNode		-		shut down a plan node and its subplans * *	 NOTES *		This used to be three files.  It is now all combined into *		one file so that it is easier to keep ExecInitNode, ExecProcNode, *		and ExecEndNode in sync when new nodes are added. * *	 EXAMPLE *		suppose we want the age of the manager of the shoe department and *		the number of employees in that department.  so we have the query: * *				retrieve (DEPT.no_emps, EMP.age) *				where EMP.name = DEPT.mgr and *					  DEPT.name = "shoe" * *		Suppose the planner gives us the following plan: * *						Nest Loop (DEPT.mgr = EMP.name) *						/		\ *					   /		 \ *				   Seq Scan		Seq Scan *					DEPT		  EMP *				(name = "shoe") * *		ExecStart() is called first. *		It calls InitPlan() which calls ExecInitNode() on *		the root of the plan -- the nest loop node. * *	  * ExecInitNode() notices that it is looking at a nest loop and *		as the code below demonstrates, it calls ExecInitNestLoop(). *		Eventually this calls ExecInitNode() on the right and left subplans *		and so forth until the entire plan is initialized.	The result *		of ExecInitNode() is a plan state tree built with the same structure *		as the underlying plan tree. * *	  * Then when ExecRun() is called, it calls ExecutePlan() which calls *		ExecProcNode() repeatedly on the top node of the plan state tree. *		Each time this happens, ExecProcNode() will end up calling *		ExecNestLoop(), which calls ExecProcNode() on its subplans. *		Each of these subplans is a sequential scan so ExecSeqScan() is *		called.  The slots returned by ExecSeqScan() may contain *		tuples which contain the attributes ExecNestLoop() uses to *		form the tuples it returns. * *	  * Eventually ExecSeqScan() stops returning tuples and the nest *		loop join ends.  Lastly, ExecEnd() calls ExecEndNode() which *		calls ExecEndNestLoop() which in turn calls ExecEndNode() on *		its subplans which result in ExecEndSeqScan(). * *		This should show how the executor works by having *		ExecInitNode(), ExecProcNode() and ExecEndNode() dispatch *		their work to the appopriate node support routines which may *		in turn call these routines themselves on their subplans. */#include "postgres.h"#include "executor/executor.h"#include "executor/instrument.h"#include "executor/nodeAgg.h"#include "executor/nodeAppend.h"#include "executor/nodeBitmapAnd.h"#include "executor/nodeBitmapHeapscan.h"#include "executor/nodeBitmapIndexscan.h"#include "executor/nodeBitmapOr.h"#include "executor/nodeFunctionscan.h"#include "executor/nodeGroup.h"#include "executor/nodeHash.h"#include "executor/nodeHashjoin.h"#include "executor/nodeIndexscan.h"#include "executor/nodeLimit.h"#include "executor/nodeMaterial.h"#include "executor/nodeMergejoin.h"#include "executor/nodeNestloop.h"#include "executor/nodeResult.h"#include "executor/nodeSeqscan.h"#include "executor/nodeSetOp.h"#include "executor/nodeSort.h"#include "executor/nodeSubplan.h"#include "executor/nodeSubqueryscan.h"#include "executor/nodeTidscan.h"#include "executor/nodeUnique.h"#include "miscadmin.h"#include "tcop/tcopprot.h"/* ------------------------------------------------------------------------ *		ExecInitNode * *		Recursively initializes all the nodes in the plan rooted *		at 'node'. * *		Initial States: *		  'node' is the plan produced by the query planner *		  'estate' is the shared execution state for the query tree * *		Returns a PlanState node corresponding to the given Plan node. * ------------------------------------------------------------------------ */PlanState *ExecInitNode(Plan *node, EState *estate){	PlanState  *result;	List	   *subps;	ListCell   *l;	/*	 * do nothing when we get to the end of a leaf on tree.	 */	if (node == NULL)		return NULL;	switch (nodeTag(node))	{			/*			 * control nodes			 */		case T_Result:			result = (PlanState *) ExecInitResult((Result *) node, estate);			break;		case T_Append:			result = (PlanState *) ExecInitAppend((Append *) node, estate);			break;		case T_BitmapAnd:			result = (PlanState *) ExecInitBitmapAnd((BitmapAnd *) node, estate);			break;		case T_BitmapOr:			result = (PlanState *) ExecInitBitmapOr((BitmapOr *) node, estate);			break;			/*			 * scan nodes			 */		case T_SeqScan:			result = (PlanState *) ExecInitSeqScan((SeqScan *) node, estate);			break;		case T_IndexScan:			result = (PlanState *) ExecInitIndexScan((IndexScan *) node, estate);			break;		case T_BitmapIndexScan:			result = (PlanState *) ExecInitBitmapIndexScan((BitmapIndexScan *) node, estate);			break;		case T_BitmapHeapScan:			result = (PlanState *) ExecInitBitmapHeapScan((BitmapHeapScan *) node, estate);			break;		case T_TidScan:			result = (PlanState *) ExecInitTidScan((TidScan *) node, estate);			break;		case T_SubqueryScan:			result = (PlanState *) ExecInitSubqueryScan((SubqueryScan *) node, estate);			break;		case T_FunctionScan:			result = (PlanState *) ExecInitFunctionScan((FunctionScan *) node, estate);			break;			/*			 * join nodes			 */		case T_NestLoop:			result = (PlanState *) ExecInitNestLoop((NestLoop *) node, estate);			break;		case T_MergeJoin:			result = (PlanState *) ExecInitMergeJoin((MergeJoin *) node, estate);			break;		case T_HashJoin:			result = (PlanState *) ExecInitHashJoin((HashJoin *) node, estate);			break;			/*			 * materialization nodes			 */		case T_Material:			result = (PlanState *) ExecInitMaterial((Material *) node, estate);			break;		case T_Sort:			result = (PlanState *) ExecInitSort((Sort *) node, estate);			break;		case T_Group:			result = (PlanState *) ExecInitGroup((Group *) node, estate);			break;		case T_Agg:			result = (PlanState *) ExecInitAgg((Agg *) node, estate);			break;		case T_Unique:			result = (PlanState *) ExecInitUnique((Unique *) node, estate);			break;		case T_Hash:			result = (PlanState *) ExecInitHash((Hash *) node, estate);			break;		case T_SetOp:			result = (PlanState *) ExecInitSetOp((SetOp *) node, estate);			break;		case T_Limit:			result = (PlanState *) ExecInitLimit((Limit *) node, estate);			break;		default:			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));			result = NULL;		/* keep compiler quiet */			break;	}	/*	 * Initialize any initPlans present in this node.  The planner put them in	 * a separate list for us.	 */	subps = NIL;	foreach(l, node->initPlan)	{		SubPlan    *subplan = (SubPlan *) lfirst(l);		SubPlanState *sstate;		Assert(IsA(subplan, SubPlan));		sstate = ExecInitExprInitPlan(subplan, result);		ExecInitSubPlan(sstate, estate);		subps = lappend(subps, sstate);	}	result->initPlan = subps;	/*	 * Initialize any subPlans present in this node.  These were found by	 * ExecInitExpr during initialization of the PlanState.  Note we must do	 * this after initializing initPlans, in case their arguments contain	 * subPlans (is that actually possible? perhaps not).	 */	foreach(l, result->subPlan)	{		SubPlanState *sstate = (SubPlanState *) lfirst(l);		Assert(IsA(sstate, SubPlanState));		ExecInitSubPlan(sstate, estate);	}	/* Set up instrumentation for this node if requested */	if (estate->es_instrument)		result->instrument = InstrAlloc(1);	return result;}/* ---------------------------------------------------------------- *		ExecProcNode * *		Execute the given node to return a(nother) tuple. * ---------------------------------------------------------------- */TupleTableSlot *ExecProcNode(PlanState *node){	TupleTableSlot *result;	CHECK_FOR_INTERRUPTS();	if (node->chgParam != NULL) /* something changed */		ExecReScan(node, NULL); /* let ReScan handle this */	if (node->instrument)		InstrStartNode(node->instrument);	switch (nodeTag(node))	{			/*			 * control nodes			 */		case T_ResultState:			result = ExecResult((ResultState *) node);			break;		case T_AppendState:			result = ExecAppend((AppendState *) node);			break;			/* BitmapAndState does not yield tuples */			/* BitmapOrState does not yield tuples */			/*			 * scan nodes			 */		case T_SeqScanState:			result = ExecSeqScan((SeqScanState *) node);			break;		case T_IndexScanState:			result = ExecIndexScan((IndexScanState *) node);			break;			/* BitmapIndexScanState does not yield tuples */		case T_BitmapHeapScanState:			result = ExecBitmapHeapScan((BitmapHeapScanState *) node);			break;		case T_TidScanState:			result = ExecTidScan((TidScanState *) node);			break;		case T_SubqueryScanState:			result = ExecSubqueryScan((SubqueryScanState *) node);			break;		case T_FunctionScanState:			result = ExecFunctionScan((FunctionScanState *) node);			break;			/*			 * join nodes			 */		case T_NestLoopState:			result = ExecNestLoop((NestLoopState *) node);			break;		case T_MergeJoinState:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -