PostgreSQL Source Code  git master
nodeNestloop.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeNestloop.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NestLoopStateExecInitNestLoop (NestLoop *node, EState *estate, int eflags)
 
void ExecEndNestLoop (NestLoopState *node)
 
void ExecReScanNestLoop (NestLoopState *node)
 

Function Documentation

◆ ExecEndNestLoop()

void ExecEndNestLoop ( NestLoopState node)

Definition at line 362 of file nodeNestloop.c.

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), innerPlanState, NestLoopState::js, NL1_printf, outerPlanState, JoinState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecEndNode().

363 {
364  NL1_printf("ExecEndNestLoop: %s\n",
365  "ending node processing");
366 
367  /*
368  * Free the exprcontext
369  */
370  ExecFreeExprContext(&node->js.ps);
371 
372  /*
373  * clean out the tuple table
374  */
376 
377  /*
378  * close down subplans
379  */
382 
383  NL1_printf("ExecEndNestLoop: %s\n",
384  "node processing ended");
385 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
PlanState ps
Definition: execnodes.h:1831
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
#define outerPlanState(node)
Definition: execnodes.h:1034
#define NL1_printf(s, a)
Definition: execdebug.h:77
JoinState js
Definition: execnodes.h:1848
#define innerPlanState(node)
Definition: execnodes.h:1033

◆ ExecInitNestLoop()

NestLoopState* ExecInitNestLoop ( NestLoop node,
EState estate,
int  eflags 
)

Definition at line 263 of file nodeNestloop.c.

References Assert, elog, ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecGetResultType(), ExecInitNode(), ExecInitNullTupleSlot(), ExecInitQual(), ExecInitResultTupleSlotTL(), ExecNestLoop(), PlanState::ExecProcNode, Join::inner_unique, innerPlan, innerPlanState, NestLoop::join, JOIN_ANTI, JOIN_INNER, JOIN_LEFT, JOIN_SEMI, Join::joinqual, Join::jointype, NestLoopState::js, makeNode, NestLoop::nestParams, NIL, NL1_printf, outerPlan, outerPlanState, Join::plan, PlanState::plan, JoinState::ps, Plan::qual, PlanState::qual, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

264 {
265  NestLoopState *nlstate;
266 
267  /* check for unsupported flags */
268  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
269 
270  NL1_printf("ExecInitNestLoop: %s\n",
271  "initializing node");
272 
273  /*
274  * create state structure
275  */
276  nlstate = makeNode(NestLoopState);
277  nlstate->js.ps.plan = (Plan *) node;
278  nlstate->js.ps.state = estate;
279  nlstate->js.ps.ExecProcNode = ExecNestLoop;
280 
281  /*
282  * Miscellaneous initialization
283  *
284  * create expression context for node
285  */
286  ExecAssignExprContext(estate, &nlstate->js.ps);
287 
288  /*
289  * initialize child nodes
290  *
291  * If we have no parameters to pass into the inner rel from the outer,
292  * tell the inner child that cheap rescans would be good. If we do have
293  * such parameters, then there is no point in REWIND support at all in the
294  * inner child, because it will always be rescanned with fresh parameter
295  * values.
296  */
297  outerPlanState(nlstate) = ExecInitNode(outerPlan(node), estate, eflags);
298  if (node->nestParams == NIL)
299  eflags |= EXEC_FLAG_REWIND;
300  else
301  eflags &= ~EXEC_FLAG_REWIND;
302  innerPlanState(nlstate) = ExecInitNode(innerPlan(node), estate, eflags);
303 
304  /*
305  * Initialize result slot, type and projection.
306  */
308  ExecAssignProjectionInfo(&nlstate->js.ps, NULL);
309 
310  /*
311  * initialize child expressions
312  */
313  nlstate->js.ps.qual =
314  ExecInitQual(node->join.plan.qual, (PlanState *) nlstate);
315  nlstate->js.jointype = node->join.jointype;
316  nlstate->js.joinqual =
317  ExecInitQual(node->join.joinqual, (PlanState *) nlstate);
318 
319  /*
320  * detect whether we need only consider the first matching inner tuple
321  */
322  nlstate->js.single_match = (node->join.inner_unique ||
323  node->join.jointype == JOIN_SEMI);
324 
325  /* set up null tuples for outer joins, if needed */
326  switch (node->join.jointype)
327  {
328  case JOIN_INNER:
329  case JOIN_SEMI:
330  break;
331  case JOIN_LEFT:
332  case JOIN_ANTI:
333  nlstate->nl_NullInnerTupleSlot =
334  ExecInitNullTupleSlot(estate,
336  &TTSOpsVirtual);
337  break;
338  default:
339  elog(ERROR, "unrecognized join type: %d",
340  (int) node->join.jointype);
341  }
342 
343  /*
344  * finally, wipe the current outer tuple clean.
345  */
346  nlstate->nl_NeedNewOuter = true;
347  nlstate->nl_MatchedOuter = false;
348 
349  NL1_printf("ExecInitNestLoop: %s\n",
350  "node initialized");
351 
352  return nlstate;
353 }
JoinType jointype
Definition: execnodes.h:1832
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
bool nl_MatchedOuter
Definition: execnodes.h:1850
ExprState * joinqual
Definition: execnodes.h:1835
List * nestParams
Definition: plannodes.h:699
PlanState ps
Definition: execnodes.h:1831
bool nl_NeedNewOuter
Definition: execnodes.h:1849
bool single_match
Definition: execnodes.h:1833
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
EState * state
Definition: execnodes.h:942
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:207
JoinType jointype
Definition: plannodes.h:680
Join join
Definition: plannodes.h:698
#define ERROR
Definition: elog.h:43
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1034
#define innerPlan(node)
Definition: plannodes.h:169
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:499
#define EXEC_FLAG_REWIND
Definition: executor.h:57
#define outerPlan(node)
Definition: plannodes.h:170
static TupleTableSlot * ExecNestLoop(PlanState *pstate)
Definition: nodeNestloop.c:61
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:946
TupleTableSlot * nl_NullInnerTupleSlot
Definition: execnodes.h:1851
Plan * plan
Definition: execnodes.h:940
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
#define EXEC_FLAG_MARK
Definition: executor.h:59
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1812
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
#define NL1_printf(s, a)
Definition: execdebug.h:77
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:454
ExprState * qual
Definition: execnodes.h:961
JoinState js
Definition: execnodes.h:1848
#define elog(elevel,...)
Definition: elog.h:226
bool inner_unique
Definition: plannodes.h:681
#define innerPlanState(node)
Definition: execnodes.h:1033
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
List * joinqual
Definition: plannodes.h:682
Plan plan
Definition: plannodes.h:679

◆ ExecReScanNestLoop()

void ExecReScanNestLoop ( NestLoopState node)

Definition at line 392 of file nodeNestloop.c.

References PlanState::chgParam, ExecReScan(), NestLoopState::nl_MatchedOuter, NestLoopState::nl_NeedNewOuter, outerPlan, and outerPlanState.

Referenced by ExecReScan().

393 {
395 
396  /*
397  * If outerPlan->chgParam is not null then plan will be automatically
398  * re-scanned by first ExecProcNode.
399  */
400  if (outerPlan->chgParam == NULL)
401  ExecReScan(outerPlan);
402 
403  /*
404  * innerPlan is re-scanned for each new outer tuple and MUST NOT be
405  * re-scanned from here or you'll get troubles from inner index scans when
406  * outer Vars are used as run-time keys...
407  */
408 
409  node->nl_NeedNewOuter = true;
410  node->nl_MatchedOuter = false;
411 }
bool nl_MatchedOuter
Definition: execnodes.h:1850
bool nl_NeedNewOuter
Definition: execnodes.h:1849
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
#define outerPlanState(node)
Definition: execnodes.h:1034
Bitmapset * chgParam
Definition: execnodes.h:972
#define outerPlan(node)
Definition: plannodes.h:170