1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* execProcnode.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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,
|
2000-01-05 19:23:54 +01:00
|
|
|
* ExecProcNode, or ExecEndNode on its subnodes and do the appropriate
|
2002-12-05 16:50:39 +01:00
|
|
|
* processing.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2004-08-29 06:13:13 +02:00
|
|
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2004-09-24 03:36:37 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.45 2004/09/24 01:36:30 neilc Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* INTERFACE ROUTINES
|
2002-12-05 16:50:39 +01:00
|
|
|
* ExecCountSlotsNode - count tuple slots needed by plan tree
|
2000-01-05 19:23:54 +01:00
|
|
|
* ExecInitNode - initialize a plan node and its subplans
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecProcNode - get a tuple by executing the plan node
|
2000-01-05 19:23:54 +01:00
|
|
|
* ExecEndNode - shut down a plan node and its subplans
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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:
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* retrieve (DEPT.no_emps, EMP.age)
|
|
|
|
* where EMP.name = DEPT.mgr and
|
|
|
|
* DEPT.name = "shoe"
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Suppose the planner gives us the following plan:
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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
|
2003-08-04 02:43:34 +02:00
|
|
|
* and so forth until the entire plan is initialized. The result
|
2002-12-05 16:50:39 +01:00
|
|
|
* of ExecInitNode() is a plan state tree built with the same structure
|
|
|
|
* as the underlying plan tree.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2002-12-05 16:50:39 +01:00
|
|
|
* * Then when ExecRun() is called, it calls ExecutePlan() which calls
|
|
|
|
* ExecProcNode() repeatedly on the top node of the plan state tree.
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1996-10-31 11:12:26 +01:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "executor/executor.h"
|
2001-09-18 03:59:07 +02:00
|
|
|
#include "executor/instrument.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "executor/nodeAgg.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "executor/nodeAppend.h"
|
2002-12-05 16:50:39 +01:00
|
|
|
#include "executor/nodeFunctionscan.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "executor/nodeGroup.h"
|
|
|
|
#include "executor/nodeHash.h"
|
|
|
|
#include "executor/nodeHashjoin.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "executor/nodeIndexscan.h"
|
2000-10-26 23:38:24 +02:00
|
|
|
#include "executor/nodeLimit.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "executor/nodeMaterial.h"
|
|
|
|
#include "executor/nodeMergejoin.h"
|
|
|
|
#include "executor/nodeNestloop.h"
|
|
|
|
#include "executor/nodeResult.h"
|
|
|
|
#include "executor/nodeSeqscan.h"
|
2000-10-05 21:11:39 +02:00
|
|
|
#include "executor/nodeSetOp.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "executor/nodeSort.h"
|
1998-02-13 04:26:53 +01:00
|
|
|
#include "executor/nodeSubplan.h"
|
2000-09-29 20:21:41 +02:00
|
|
|
#include "executor/nodeSubqueryscan.h"
|
2002-12-05 16:50:39 +01:00
|
|
|
#include "executor/nodeTidscan.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "executor/nodeUnique.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "tcop/tcopprot.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecInitNode
|
|
|
|
*
|
|
|
|
* Recursively initializes all the nodes in the plan rooted
|
|
|
|
* at 'node'.
|
|
|
|
*
|
|
|
|
* Initial States:
|
|
|
|
* 'node' is the plan produced by the query planner
|
2002-12-05 16:50:39 +01:00
|
|
|
* 'estate' is the shared execution state for the query tree
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2002-12-05 16:50:39 +01:00
|
|
|
* Returns a PlanState node corresponding to the given Plan node.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
PlanState *
|
|
|
|
ExecInitNode(Plan *node, EState *estate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-05 16:50:39 +01:00
|
|
|
PlanState *result;
|
|
|
|
List *subps;
|
2004-05-26 06:41:50 +02:00
|
|
|
ListCell *l;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* do nothing when we get to the end of a leaf on tree.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
if (node == NULL)
|
2002-12-05 16:50:39 +01:00
|
|
|
return NULL;
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (nodeTag(node))
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* control nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_Result:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitResult((Result *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_Append:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitAppend((Append *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* scan nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_SeqScan:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitSeqScan((SeqScan *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_IndexScan:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitIndexScan((IndexScan *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2000-09-29 20:21:41 +02:00
|
|
|
case T_TidScan:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitTidScan((TidScan *) node, estate);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SubqueryScan:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitSubqueryScan((SubqueryScan *) node, estate);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-05-12 22:10:05 +02:00
|
|
|
case T_FunctionScan:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitFunctionScan((FunctionScan *) node, estate);
|
2002-05-12 22:10:05 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* join nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_NestLoop:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitNestLoop((NestLoop *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MergeJoin:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitMergeJoin((MergeJoin *) node, estate);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_HashJoin:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitHashJoin((HashJoin *) node, estate);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* materialization nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_Material:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitMaterial((Material *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_Sort:
|
2002-12-05 16:50:39 +01:00
|
|
|
result = (PlanState *) ExecInitSort((Sort *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Group:
|
|
|
|
result = (PlanState *) ExecInitGroup((Group *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Agg:
|
|
|
|
result = (PlanState *) ExecInitAgg((Agg *) node, estate);
|
2000-10-05 21:11:39 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Unique:
|
|
|
|
result = (PlanState *) ExecInitUnique((Unique *) node, estate);
|
2000-10-26 23:38:24 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Hash:
|
|
|
|
result = (PlanState *) ExecInitHash((Hash *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SetOp:
|
|
|
|
result = (PlanState *) ExecInitSetOp((SetOp *) node, estate);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_Limit:
|
|
|
|
result = (PlanState *) ExecInitLimit((Limit *) node, estate);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-21 19:05:12 +02:00
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
2002-12-05 16:50:39 +01:00
|
|
|
result = NULL; /* keep compiler quiet */
|
2001-09-18 03:59:07 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/*
|
|
|
|
* Initialize any initPlans present in this node. The planner put
|
|
|
|
* them in a separate list for us.
|
|
|
|
*/
|
|
|
|
subps = NIL;
|
2004-05-26 06:41:50 +02:00
|
|
|
foreach(l, node->initPlan)
|
1998-02-13 04:26:53 +01:00
|
|
|
{
|
2004-05-26 06:41:50 +02:00
|
|
|
SubPlan *subplan = (SubPlan *) lfirst(l);
|
2002-12-14 01:17:59 +01:00
|
|
|
SubPlanState *sstate;
|
2002-12-05 16:50:39 +01:00
|
|
|
|
2002-12-14 01:17:59 +01:00
|
|
|
Assert(IsA(subplan, SubPlan));
|
2002-12-13 20:46:01 +01:00
|
|
|
sstate = ExecInitExprInitPlan(subplan, result);
|
|
|
|
ExecInitSubPlan(sstate, estate);
|
|
|
|
subps = lappend(subps, sstate);
|
1998-02-13 04:26:53 +01:00
|
|
|
}
|
2002-12-05 16:50:39 +01:00
|
|
|
result->initPlan = subps;
|
|
|
|
|
|
|
|
/*
|
2003-08-04 02:43:34 +02:00
|
|
|
* 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
|
2002-12-13 20:46:01 +01:00
|
|
|
* contain subPlans (is that actually possible? perhaps not).
|
2002-12-05 16:50:39 +01:00
|
|
|
*/
|
2004-05-26 06:41:50 +02:00
|
|
|
foreach(l, result->subPlan)
|
2002-12-05 16:50:39 +01:00
|
|
|
{
|
2004-05-26 06:41:50 +02:00
|
|
|
SubPlanState *sstate = (SubPlanState *) lfirst(l);
|
2002-12-05 16:50:39 +01:00
|
|
|
|
2002-12-14 01:17:59 +01:00
|
|
|
Assert(IsA(sstate, SubPlanState));
|
2002-12-13 20:46:01 +01:00
|
|
|
ExecInitSubPlan(sstate, estate);
|
2002-12-05 16:50:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up instrumentation for this node if requested */
|
|
|
|
if (estate->es_instrument)
|
|
|
|
result->instrument = InstrAlloc();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecProcNode
|
|
|
|
*
|
2002-12-05 16:50:39 +01:00
|
|
|
* Execute the given node to return a(nother) tuple.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
TupleTableSlot *
|
2003-08-08 23:42:59 +02:00
|
|
|
ExecProcNode(PlanState *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
TupleTableSlot *result;
|
|
|
|
|
2001-01-14 06:08:17 +01:00
|
|
|
CHECK_FOR_INTERRUPTS();
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* deal with NULL nodes..
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
if (node->chgParam != NULL) /* something changed */
|
2002-12-05 16:50:39 +01:00
|
|
|
ExecReScan(node, NULL); /* let ReScan handle this */
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2001-09-18 03:59:07 +02:00
|
|
|
if (node->instrument)
|
|
|
|
InstrStartNode(node->instrument);
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (nodeTag(node))
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
/*
|
|
|
|
* control nodes
|
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_ResultState:
|
|
|
|
result = ExecResult((ResultState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_AppendState:
|
2004-09-24 03:36:37 +02:00
|
|
|
result = ExecAppend((AppendState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* scan nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SeqScanState:
|
|
|
|
result = ExecSeqScan((SeqScanState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_IndexScanState:
|
|
|
|
result = ExecIndexScan((IndexScanState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_TidScanState:
|
|
|
|
result = ExecTidScan((TidScanState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SubqueryScanState:
|
|
|
|
result = ExecSubqueryScan((SubqueryScanState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_FunctionScanState:
|
|
|
|
result = ExecFunctionScan((FunctionScanState *) node);
|
2002-05-12 22:10:05 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* join nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_NestLoopState:
|
|
|
|
result = ExecNestLoop((NestLoopState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_MergeJoinState:
|
|
|
|
result = ExecMergeJoin((MergeJoinState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_HashJoinState:
|
|
|
|
result = ExecHashJoin((HashJoinState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* materialization nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_MaterialState:
|
|
|
|
result = ExecMaterial((MaterialState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SortState:
|
|
|
|
result = ExecSort((SortState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_GroupState:
|
|
|
|
result = ExecGroup((GroupState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_AggState:
|
|
|
|
result = ExecAgg((AggState *) node);
|
2000-10-05 21:11:39 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_UniqueState:
|
|
|
|
result = ExecUnique((UniqueState *) node);
|
2000-10-26 23:38:24 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_HashState:
|
|
|
|
result = ExecHash((HashState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SetOpState:
|
|
|
|
result = ExecSetOp((SetOpState *) node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LimitState:
|
|
|
|
result = ExecLimit((LimitState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-21 19:05:12 +02:00
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
1998-02-13 04:26:53 +01:00
|
|
|
result = NULL;
|
2001-09-18 03:59:07 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
2001-09-18 03:59:07 +02:00
|
|
|
if (node->instrument)
|
|
|
|
InstrStopNode(node->instrument, !TupIsNull(result));
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/*
|
|
|
|
* ExecCountSlotsNode - count up the number of tuple table slots needed
|
|
|
|
*
|
|
|
|
* Note that this scans a Plan tree, not a PlanState tree, because we
|
|
|
|
* haven't built the PlanState tree yet ...
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
int
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecCountSlotsNode(Plan *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-05 16:50:39 +01:00
|
|
|
if (node == NULL)
|
1997-09-07 07:04:48 +02:00
|
|
|
return 0;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (nodeTag(node))
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* control nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_Result:
|
|
|
|
return ExecCountSlotsResult((Result *) node);
|
|
|
|
|
|
|
|
case T_Append:
|
|
|
|
return ExecCountSlotsAppend((Append *) node);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* scan nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_SeqScan:
|
|
|
|
return ExecCountSlotsSeqScan((SeqScan *) node);
|
|
|
|
|
|
|
|
case T_IndexScan:
|
|
|
|
return ExecCountSlotsIndexScan((IndexScan *) node);
|
|
|
|
|
2000-09-29 20:21:41 +02:00
|
|
|
case T_TidScan:
|
|
|
|
return ExecCountSlotsTidScan((TidScan *) node);
|
|
|
|
|
|
|
|
case T_SubqueryScan:
|
|
|
|
return ExecCountSlotsSubqueryScan((SubqueryScan *) node);
|
|
|
|
|
2002-05-12 22:10:05 +02:00
|
|
|
case T_FunctionScan:
|
|
|
|
return ExecCountSlotsFunctionScan((FunctionScan *) node);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* join nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_NestLoop:
|
|
|
|
return ExecCountSlotsNestLoop((NestLoop *) node);
|
|
|
|
|
|
|
|
case T_MergeJoin:
|
|
|
|
return ExecCountSlotsMergeJoin((MergeJoin *) node);
|
|
|
|
|
2000-09-29 20:21:41 +02:00
|
|
|
case T_HashJoin:
|
|
|
|
return ExecCountSlotsHashJoin((HashJoin *) node);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* materialization nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
case T_Material:
|
|
|
|
return ExecCountSlotsMaterial((Material *) node);
|
|
|
|
|
|
|
|
case T_Sort:
|
|
|
|
return ExecCountSlotsSort((Sort *) node);
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Group:
|
|
|
|
return ExecCountSlotsGroup((Group *) node);
|
|
|
|
|
|
|
|
case T_Agg:
|
|
|
|
return ExecCountSlotsAgg((Agg *) node);
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_Unique:
|
|
|
|
return ExecCountSlotsUnique((Unique *) node);
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_Hash:
|
|
|
|
return ExecCountSlotsHash((Hash *) node);
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
case T_SetOp:
|
|
|
|
return ExecCountSlotsSetOp((SetOp *) node);
|
|
|
|
|
2000-10-26 23:38:24 +02:00
|
|
|
case T_Limit:
|
|
|
|
return ExecCountSlotsLimit((Limit *) node);
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
2003-07-21 19:05:12 +02:00
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2002-12-05 16:50:39 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return 0;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ExecEndNode
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Recursively cleans up all the nodes in the plan rooted
|
|
|
|
* at 'node'.
|
|
|
|
*
|
|
|
|
* After this operation, the query plan will not be able to
|
|
|
|
* processed any further. This should be called only after
|
|
|
|
* the query plan has been fully executed.
|
|
|
|
* ----------------------------------------------------------------
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
2003-08-08 23:42:59 +02:00
|
|
|
ExecEndNode(PlanState *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2004-05-26 06:41:50 +02:00
|
|
|
ListCell *subp;
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* do nothing when we get to the end of a leaf on tree.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
if (node == NULL)
|
|
|
|
return;
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/* Clean up initPlans and subPlans */
|
1998-02-26 05:46:47 +01:00
|
|
|
foreach(subp, node->initPlan)
|
2002-12-14 01:17:59 +01:00
|
|
|
ExecEndSubPlan((SubPlanState *) lfirst(subp));
|
1998-02-26 05:46:47 +01:00
|
|
|
foreach(subp, node->subPlan)
|
2002-12-14 01:17:59 +01:00
|
|
|
ExecEndSubPlan((SubPlanState *) lfirst(subp));
|
2002-12-05 16:50:39 +01:00
|
|
|
|
2003-02-09 01:30:41 +01:00
|
|
|
if (node->chgParam != NULL)
|
1998-02-13 04:26:53 +01:00
|
|
|
{
|
2003-02-09 01:30:41 +01:00
|
|
|
bms_free(node->chgParam);
|
|
|
|
node->chgParam = NULL;
|
1998-02-13 04:26:53 +01:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
switch (nodeTag(node))
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
/*
|
|
|
|
* control nodes
|
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_ResultState:
|
|
|
|
ExecEndResult((ResultState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_AppendState:
|
|
|
|
ExecEndAppend((AppendState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* scan nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SeqScanState:
|
|
|
|
ExecEndSeqScan((SeqScanState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_IndexScanState:
|
|
|
|
ExecEndIndexScan((IndexScanState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_TidScanState:
|
|
|
|
ExecEndTidScan((TidScanState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SubqueryScanState:
|
|
|
|
ExecEndSubqueryScan((SubqueryScanState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_FunctionScanState:
|
|
|
|
ExecEndFunctionScan((FunctionScanState *) node);
|
2002-05-12 22:10:05 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* join nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_NestLoopState:
|
|
|
|
ExecEndNestLoop((NestLoopState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_MergeJoinState:
|
|
|
|
ExecEndMergeJoin((MergeJoinState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_HashJoinState:
|
|
|
|
ExecEndHashJoin((HashJoinState *) node);
|
2000-09-29 20:21:41 +02:00
|
|
|
break;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* materialization nodes
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_MaterialState:
|
|
|
|
ExecEndMaterial((MaterialState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SortState:
|
|
|
|
ExecEndSort((SortState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_GroupState:
|
|
|
|
ExecEndGroup((GroupState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_AggState:
|
|
|
|
ExecEndAgg((AggState *) node);
|
2000-10-05 21:11:39 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_UniqueState:
|
|
|
|
ExecEndUnique((UniqueState *) node);
|
2000-10-26 23:38:24 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_HashState:
|
|
|
|
ExecEndHash((HashState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
case T_SetOpState:
|
|
|
|
ExecEndSetOp((SetOpState *) node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LimitState:
|
|
|
|
ExecEndLimit((LimitState *) node);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-21 19:05:12 +02:00
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|