PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeUnique.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeUnique.h"
#include "utils/memutils.h"
Include dependency graph for nodeUnique.c:

Go to the source code of this file.

Functions

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

Function Documentation

void ExecEndUnique ( UniqueState node)

Definition at line 173 of file nodeUnique.c.

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

Referenced by ExecEndNode().

174 {
175  /* clean up tuple table */
177 
179 
181 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:644
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:829
#define outerPlanState(node)
Definition: execnodes.h:842
PlanState ps
Definition: execnodes.h:1828
MemoryContext tempContext
Definition: execnodes.h:1830
UniqueState* ExecInitUnique ( Unique node,
EState estate,
int  eflags 
)

Definition at line 112 of file nodeUnique.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Assert, CurrentMemoryContext, UniqueState::eqfunctions, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignResultTypeFromTL(), ExecInitNode(), ExecInitResultTupleSlot(), execTuplesMatchPrepare(), makeNode, NULL, Unique::numCols, outerPlan, outerPlanState, PlanState::plan, UniqueState::ps, PlanState::ps_ProjInfo, PlanState::state, UniqueState::tempContext, and Unique::uniqOperators.

Referenced by ExecInitNode().

113 {
114  UniqueState *uniquestate;
115 
116  /* check for unsupported flags */
117  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
118 
119  /*
120  * create state structure
121  */
122  uniquestate = makeNode(UniqueState);
123  uniquestate->ps.plan = (Plan *) node;
124  uniquestate->ps.state = estate;
125 
126  /*
127  * Miscellaneous initialization
128  *
129  * Unique nodes have no ExprContext initialization because they never call
130  * ExecQual or ExecProject. But they do need a per-tuple memory context
131  * anyway for calling execTuplesMatch.
132  */
133  uniquestate->tempContext =
135  "Unique",
137 
138  /*
139  * Tuple table initialization
140  */
141  ExecInitResultTupleSlot(estate, &uniquestate->ps);
142 
143  /*
144  * then initialize outer plan
145  */
146  outerPlanState(uniquestate) = ExecInitNode(outerPlan(node), estate, eflags);
147 
148  /*
149  * unique nodes do no projections, so initialize projection info for this
150  * node appropriately
151  */
152  ExecAssignResultTypeFromTL(&uniquestate->ps);
153  uniquestate->ps.ps_ProjInfo = NULL;
154 
155  /*
156  * Precompute fmgr lookup data for inner loop
157  */
158  uniquestate->eqfunctions =
160  node->uniqOperators);
161 
162  return uniquestate;
163 }
int numCols
Definition: plannodes.h:792
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:831
EState * state
Definition: execnodes.h:802
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:435
Oid * uniqOperators
Definition: plannodes.h:794
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:842
PlanState ps
Definition: execnodes.h:1828
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define outerPlan(node)
Definition: plannodes.h:162
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
FmgrInfo * eqfunctions
Definition: execnodes.h:1829
Plan * plan
Definition: execnodes.h:800
MemoryContext tempContext
Definition: execnodes.h:1830
#define makeNode(_type_)
Definition: nodes.h:552
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define EXEC_FLAG_MARK
Definition: executor.h:61
FmgrInfo * execTuplesMatchPrepare(int numCols, Oid *eqOperators)
Definition: execGrouping.c:204
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
void ExecReScanUnique ( UniqueState node)

Definition at line 185 of file nodeUnique.c.

References PlanState::chgParam, ExecClearTuple(), ExecReScan(), PlanState::lefttree, NULL, UniqueState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecReScan().

186 {
187  /* must clear result tuple so first input tuple is returned */
189 
190  /*
191  * if chgParam of subnode is not null then plan will be re-scanned by
192  * first ExecProcNode.
193  */
194  if (node->ps.lefttree->chgParam == NULL)
195  ExecReScan(node->ps.lefttree);
196 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:74
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
struct PlanState * lefttree
Definition: execnodes.h:815
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:829
PlanState ps
Definition: execnodes.h:1828
Bitmapset * chgParam
Definition: execnodes.h:824
#define NULL
Definition: c.h:229
TupleTableSlot* ExecUnique ( UniqueState node)

Definition at line 46 of file nodeUnique.c.

References UniqueState::eqfunctions, ExecClearTuple(), ExecCopySlot(), ExecProcNode(), execTuplesMatch(), NULL, Unique::numCols, outerPlan, outerPlanState, PlanState::plan, UniqueState::ps, PlanState::ps_ResultTupleSlot, UniqueState::tempContext, TupIsNull, and Unique::uniqColIdx.

Referenced by ExecProcNode().

47 {
48  Unique *plannode = (Unique *) node->ps.plan;
49  TupleTableSlot *resultTupleSlot;
50  TupleTableSlot *slot;
52 
53  /*
54  * get information from the node
55  */
56  outerPlan = outerPlanState(node);
57  resultTupleSlot = node->ps.ps_ResultTupleSlot;
58 
59  /*
60  * now loop, returning only non-duplicate tuples. We assume that the
61  * tuples arrive in sorted order so we can detect duplicates easily. The
62  * first tuple of each group is returned.
63  */
64  for (;;)
65  {
66  /*
67  * fetch a tuple from the outer subplan
68  */
69  slot = ExecProcNode(outerPlan);
70  if (TupIsNull(slot))
71  {
72  /* end of subplan, so we're done */
73  ExecClearTuple(resultTupleSlot);
74  return NULL;
75  }
76 
77  /*
78  * Always return the first tuple from the subplan.
79  */
80  if (TupIsNull(resultTupleSlot))
81  break;
82 
83  /*
84  * Else test if the new tuple and the previously returned tuple match.
85  * If so then we loop back and fetch another new tuple from the
86  * subplan.
87  */
88  if (!execTuplesMatch(slot, resultTupleSlot,
89  plannode->numCols, plannode->uniqColIdx,
90  node->eqfunctions,
91  node->tempContext))
92  break;
93  }
94 
95  /*
96  * We have a new tuple different from the previous saved tuple (if any).
97  * Save it and return it. We must copy it because the source subplan
98  * won't guarantee that this source tuple is still accessible after
99  * fetching the next source tuple.
100  */
101  return ExecCopySlot(resultTupleSlot, slot);
102 }
int numCols
Definition: plannodes.h:792
TupleTableSlot * ExecProcNode(PlanState *node)
Definition: execProcnode.c:392
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
bool execTuplesMatch(TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
Definition: execGrouping.c:69
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:829
#define outerPlanState(node)
Definition: execnodes.h:842
PlanState ps
Definition: execnodes.h:1828
#define TupIsNull(slot)
Definition: tuptable.h:138
#define outerPlan(node)
Definition: plannodes.h:162
AttrNumber * uniqColIdx
Definition: plannodes.h:793
FmgrInfo * eqfunctions
Definition: execnodes.h:1829
Plan * plan
Definition: execnodes.h:800
MemoryContext tempContext
Definition: execnodes.h:1830
TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: execTuples.c:795
#define NULL
Definition: c.h:229