PostgreSQL Source Code  git master
nodeUnique.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeUnique.h"
#include "miscadmin.h"
#include "utils/memutils.h"
Include dependency graph for nodeUnique.c:

Go to the source code of this file.

Functions

static TupleTableSlotExecUnique (PlanState *pstate)
 
UniqueStateExecInitUnique (Unique *node, EState *estate, int eflags)
 
void ExecEndUnique (UniqueState *node)
 
void ExecReScanUnique (UniqueState *node)
 

Function Documentation

◆ ExecEndUnique()

void ExecEndUnique ( UniqueState node)

Definition at line 169 of file nodeUnique.c.

170 {
171  /* clean up tuple table */
173 
174  ExecFreeExprContext(&node->ps);
175 
177 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:658
#define outerPlanState(node)
Definition: execnodes.h:1133
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1075
PlanState ps
Definition: execnodes.h:2573
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:432

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), outerPlanState, UniqueState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecEndNode().

◆ ExecInitUnique()

UniqueState* ExecInitUnique ( Unique node,
EState estate,
int  eflags 
)

Definition at line 115 of file nodeUnique.c.

116 {
117  UniqueState *uniquestate;
118 
119  /* check for unsupported flags */
120  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
121 
122  /*
123  * create state structure
124  */
125  uniquestate = makeNode(UniqueState);
126  uniquestate->ps.plan = (Plan *) node;
127  uniquestate->ps.state = estate;
128  uniquestate->ps.ExecProcNode = ExecUnique;
129 
130  /*
131  * create expression context
132  */
133  ExecAssignExprContext(estate, &uniquestate->ps);
134 
135  /*
136  * then initialize outer plan
137  */
138  outerPlanState(uniquestate) = ExecInitNode(outerPlan(node), estate, eflags);
139 
140  /*
141  * Initialize result slot and type. Unique nodes do no projections, so
142  * initialize projection info for this node appropriately.
143  */
145  uniquestate->ps.ps_ProjInfo = NULL;
146 
147  /*
148  * Precompute fmgr lookup data for inner loop
149  */
150  uniquestate->eqfunction =
152  node->numCols,
153  node->uniqColIdx,
154  node->uniqOperators,
155  node->uniqCollations,
156  &uniquestate->ps);
157 
158  return uniquestate;
159 }
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:59
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1800
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:498
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecUnique(PlanState *pstate)
Definition: nodeUnique.c:47
#define makeNode(_type_)
Definition: nodes.h:176
#define outerPlan(node)
Definition: plannodes.h:183
Plan * plan
Definition: execnodes.h:1037
EState * state
Definition: execnodes.h:1039
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1077
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043
ExprState * eqfunction
Definition: execnodes.h:2574
int numCols
Definition: plannodes.h:1115

References Assert(), UniqueState::eqfunction, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecGetResultType(), ExecInitNode(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, execTuplesMatchPrepare(), ExecUnique(), makeNode, Unique::numCols, outerPlan, outerPlanState, PlanState::plan, UniqueState::ps, PlanState::ps_ProjInfo, PlanState::state, and TTSOpsMinimalTuple.

Referenced by ExecInitNode().

◆ ExecReScanUnique()

void ExecReScanUnique ( UniqueState node)

Definition at line 181 of file nodeUnique.c.

182 {
184 
185  /* must clear result tuple so first input tuple is returned */
187 
188  /*
189  * if chgParam of subnode is not null then plan will be re-scanned by
190  * first ExecProcNode.
191  */
192  if (outerPlan->chgParam == NULL)
194 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78

References ExecClearTuple(), ExecReScan(), outerPlan, outerPlanState, UniqueState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecReScan().

◆ ExecUnique()

static TupleTableSlot* ExecUnique ( PlanState pstate)
static

Definition at line 47 of file nodeUnique.c.

48 {
49  UniqueState *node = castNode(UniqueState, pstate);
50  ExprContext *econtext = node->ps.ps_ExprContext;
51  TupleTableSlot *resultTupleSlot;
52  TupleTableSlot *slot;
54 
56 
57  /*
58  * get information from the node
59  */
60  outerPlan = outerPlanState(node);
61  resultTupleSlot = node->ps.ps_ResultTupleSlot;
62 
63  /*
64  * now loop, returning only non-duplicate tuples. We assume that the
65  * tuples arrive in sorted order so we can detect duplicates easily. The
66  * first tuple of each group is returned.
67  */
68  for (;;)
69  {
70  /*
71  * fetch a tuple from the outer subplan
72  */
73  slot = ExecProcNode(outerPlan);
74  if (TupIsNull(slot))
75  {
76  /* end of subplan, so we're done */
77  ExecClearTuple(resultTupleSlot);
78  return NULL;
79  }
80 
81  /*
82  * Always return the first tuple from the subplan.
83  */
84  if (TupIsNull(resultTupleSlot))
85  break;
86 
87  /*
88  * Else test if the new tuple and the previously returned tuple match.
89  * If so then we loop back and fetch another new tuple from the
90  * subplan.
91  */
92  econtext->ecxt_innertuple = slot;
93  econtext->ecxt_outertuple = resultTupleSlot;
94  if (!ExecQualAndReset(node->eqfunction, econtext))
95  break;
96  }
97 
98  /*
99  * We have a new tuple different from the previous saved tuple (if any).
100  * Save it and return it. We must copy it because the source subplan
101  * won't guarantee that this source tuple is still accessible after
102  * fetching the next source tuple.
103  */
104  return ExecCopySlot(resultTupleSlot, slot);
105 }
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:439
static TupleTableSlot * ExecProcNode(PlanState *node)
Definition: executor.h:268
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:251
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:253
ExprContext * ps_ExprContext
Definition: execnodes.h:1076
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:482
#define TupIsNull(slot)
Definition: tuptable.h:299

References castNode, CHECK_FOR_INTERRUPTS, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, UniqueState::eqfunction, ExecClearTuple(), ExecCopySlot(), ExecProcNode(), ExecQualAndReset(), outerPlan, outerPlanState, UniqueState::ps, PlanState::ps_ExprContext, PlanState::ps_ResultTupleSlot, and TupIsNull.

Referenced by ExecInitUnique().