PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nodeUnique.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeUnique.h"
#include "miscadmin.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 168 of file nodeUnique.c.

169{
171}
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1255

References ExecEndNode(), and outerPlanState.

Referenced by ExecEndNode().

◆ ExecInitUnique()

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

Definition at line 114 of file nodeUnique.c.

115{
116 UniqueState *uniquestate;
117
118 /* check for unsupported flags */
120
121 /*
122 * create state structure
123 */
124 uniquestate = makeNode(UniqueState);
125 uniquestate->ps.plan = (Plan *) node;
126 uniquestate->ps.state = estate;
127 uniquestate->ps.ExecProcNode = ExecUnique;
128
129 /*
130 * create expression context
131 */
132 ExecAssignExprContext(estate, &uniquestate->ps);
133
134 /*
135 * then initialize outer plan
136 */
137 outerPlanState(uniquestate) = ExecInitNode(outerPlan(node), estate, eflags);
138
139 /*
140 * Initialize result slot and type. Unique nodes do no projections, so
141 * initialize projection info for this node appropriately.
142 */
144 uniquestate->ps.ps_ProjInfo = NULL;
145
146 /*
147 * Precompute fmgr lookup data for inner loop
148 */
149 uniquestate->eqfunction =
151 node->numCols,
152 node->uniqColIdx,
153 node->uniqOperators,
154 node->uniqCollations,
155 &uniquestate->ps);
156
157 return uniquestate;
158}
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:58
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1988
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:496
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
#define EXEC_FLAG_BACKWARD
Definition: executor.h:69
#define EXEC_FLAG_MARK
Definition: executor.h:70
Assert(PointerIsAligned(start, uint64))
static TupleTableSlot * ExecUnique(PlanState *pstate)
Definition: nodeUnique.c:46
#define makeNode(_type_)
Definition: nodes.h:161
#define outerPlan(node)
Definition: plannodes.h:241
Plan * plan
Definition: execnodes.h:1159
EState * state
Definition: execnodes.h:1161
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1199
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1165
PlanState ps
Definition: execnodes.h:2723
ExprState * eqfunction
Definition: execnodes.h:2724
int numCols
Definition: plannodes.h:1262

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 175 of file nodeUnique.c.

176{
178
179 /* must clear result tuple so first input tuple is returned */
181
182 /*
183 * if chgParam of subnode is not null then plan will be re-scanned by
184 * first ExecProcNode.
185 */
186 if (outerPlan->chgParam == NULL)
188}
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1197
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:458

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

Referenced by ExecReScan().

◆ ExecUnique()

static TupleTableSlot * ExecUnique ( PlanState pstate)
static

Definition at line 46 of file nodeUnique.c.

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

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().