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 361 of file nodeNestloop.c.

362 {
363  NL1_printf("ExecEndNestLoop: %s\n",
364  "ending node processing");
365 
366  /*
367  * close down subplans
368  */
371 
372  NL1_printf("ExecEndNestLoop: %s\n",
373  "node processing ended");
374 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define NL1_printf(s, a)
Definition: execdebug.h:77
#define outerPlanState(node)
Definition: execnodes.h:1213
#define innerPlanState(node)
Definition: execnodes.h:1212

References ExecEndNode(), innerPlanState, NL1_printf, and outerPlanState.

Referenced by ExecEndNode().

◆ ExecInitNestLoop()

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

Definition at line 262 of file nodeNestloop.c.

263 {
264  NestLoopState *nlstate;
265 
266  /* check for unsupported flags */
267  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
268 
269  NL1_printf("ExecInitNestLoop: %s\n",
270  "initializing node");
271 
272  /*
273  * create state structure
274  */
275  nlstate = makeNode(NestLoopState);
276  nlstate->js.ps.plan = (Plan *) node;
277  nlstate->js.ps.state = estate;
278  nlstate->js.ps.ExecProcNode = ExecNestLoop;
279 
280  /*
281  * Miscellaneous initialization
282  *
283  * create expression context for node
284  */
285  ExecAssignExprContext(estate, &nlstate->js.ps);
286 
287  /*
288  * initialize child nodes
289  *
290  * If we have no parameters to pass into the inner rel from the outer,
291  * tell the inner child that cheap rescans would be good. If we do have
292  * such parameters, then there is no point in REWIND support at all in the
293  * inner child, because it will always be rescanned with fresh parameter
294  * values.
295  */
296  outerPlanState(nlstate) = ExecInitNode(outerPlan(node), estate, eflags);
297  if (node->nestParams == NIL)
298  eflags |= EXEC_FLAG_REWIND;
299  else
300  eflags &= ~EXEC_FLAG_REWIND;
301  innerPlanState(nlstate) = ExecInitNode(innerPlan(node), estate, eflags);
302 
303  /*
304  * Initialize result slot, type and projection.
305  */
307  ExecAssignProjectionInfo(&nlstate->js.ps, NULL);
308 
309  /*
310  * initialize child expressions
311  */
312  nlstate->js.ps.qual =
313  ExecInitQual(node->join.plan.qual, (PlanState *) nlstate);
314  nlstate->js.jointype = node->join.jointype;
315  nlstate->js.joinqual =
316  ExecInitQual(node->join.joinqual, (PlanState *) nlstate);
317 
318  /*
319  * detect whether we need only consider the first matching inner tuple
320  */
321  nlstate->js.single_match = (node->join.inner_unique ||
322  node->join.jointype == JOIN_SEMI);
323 
324  /* set up null tuples for outer joins, if needed */
325  switch (node->join.jointype)
326  {
327  case JOIN_INNER:
328  case JOIN_SEMI:
329  break;
330  case JOIN_LEFT:
331  case JOIN_ANTI:
332  nlstate->nl_NullInnerTupleSlot =
333  ExecInitNullTupleSlot(estate,
335  &TTSOpsVirtual);
336  break;
337  default:
338  elog(ERROR, "unrecognized join type: %d",
339  (int) node->join.jointype);
340  }
341 
342  /*
343  * finally, wipe the current outer tuple clean.
344  */
345  nlstate->nl_NeedNewOuter = true;
346  nlstate->nl_MatchedOuter = false;
347 
348  NL1_printf("ExecInitNestLoop: %s\n",
349  "node initialized");
350 
351  return nlstate;
352 }
#define Assert(condition)
Definition: c.h:858
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:220
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1934
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1886
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:493
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:538
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_REWIND
Definition: executor.h:67
#define EXEC_FLAG_MARK
Definition: executor.h:69
static TupleTableSlot * ExecNestLoop(PlanState *pstate)
Definition: nodeNestloop.c:60
#define makeNode(_type_)
Definition: nodes.h:155
@ JOIN_SEMI
Definition: nodes.h:307
@ JOIN_INNER
Definition: nodes.h:293
@ JOIN_LEFT
Definition: nodes.h:294
@ JOIN_ANTI
Definition: nodes.h:308
#define NIL
Definition: pg_list.h:68
#define innerPlan(node)
Definition: plannodes.h:181
#define outerPlan(node)
Definition: plannodes.h:182
JoinType jointype
Definition: execnodes.h:2083
PlanState ps
Definition: execnodes.h:2082
ExprState * joinqual
Definition: execnodes.h:2086
bool single_match
Definition: execnodes.h:2084
List * joinqual
Definition: plannodes.h:793
JoinType jointype
Definition: plannodes.h:791
bool inner_unique
Definition: plannodes.h:792
TupleTableSlot * nl_NullInnerTupleSlot
Definition: execnodes.h:2102
bool nl_NeedNewOuter
Definition: execnodes.h:2100
JoinState js
Definition: execnodes.h:2099
bool nl_MatchedOuter
Definition: execnodes.h:2101
List * nestParams
Definition: plannodes.h:810
Join join
Definition: plannodes.h:809
ExprState * qual
Definition: execnodes.h:1138
Plan * plan
Definition: execnodes.h:1117
EState * state
Definition: execnodes.h:1119
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1123

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, JoinState::joinqual, Join::joinqual, JoinState::jointype, Join::jointype, NestLoopState::js, makeNode, NestLoop::nestParams, NIL, NL1_printf, NestLoopState::nl_MatchedOuter, NestLoopState::nl_NeedNewOuter, NestLoopState::nl_NullInnerTupleSlot, outerPlan, outerPlanState, PlanState::plan, JoinState::ps, PlanState::qual, JoinState::single_match, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanNestLoop()

void ExecReScanNestLoop ( NestLoopState node)

Definition at line 381 of file nodeNestloop.c.

382 {
384 
385  /*
386  * If outerPlan->chgParam is not null then plan will be automatically
387  * re-scanned by first ExecProcNode.
388  */
389  if (outerPlan->chgParam == NULL)
391 
392  /*
393  * innerPlan is re-scanned for each new outer tuple and MUST NOT be
394  * re-scanned from here or you'll get troubles from inner index scans when
395  * outer Vars are used as run-time keys...
396  */
397 
398  node->nl_NeedNewOuter = true;
399  node->nl_MatchedOuter = false;
400 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76

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

Referenced by ExecReScan().