PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeGroup.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/instrument.h"
#include "executor/nodeGroup.h"
#include "miscadmin.h"
Include dependency graph for nodeGroup.c:

Go to the source code of this file.

Functions

static TupleTableSlotExecGroup (PlanState *pstate)
 
GroupStateExecInitGroup (Group *node, EState *estate, int eflags)
 
void ExecEndGroup (GroupState *node)
 
void ExecReScanGroup (GroupState *node)
 

Function Documentation

◆ ExecEndGroup()

void ExecEndGroup ( GroupState node)

Definition at line 227 of file nodeGroup.c.

228{
230
233}
void ExecEndNode(PlanState *node)
#define outerPlanState(node)
Definition execnodes.h:1273
#define outerPlan(node)
Definition plannodes.h:265

References ExecEndNode(), outerPlan, and outerPlanState.

Referenced by ExecEndNode().

◆ ExecGroup()

static TupleTableSlot * ExecGroup ( PlanState pstate)
static

Definition at line 37 of file nodeGroup.c.

38{
39 GroupState *node = castNode(GroupState, pstate);
40 ExprContext *econtext;
43
45
46 /*
47 * get state info from node
48 */
49 if (node->grp_done)
50 return NULL;
51 econtext = node->ss.ps.ps_ExprContext;
52
53 /*
54 * The ScanTupleSlot holds the (copied) first tuple of each group.
55 */
57
58 /*
59 * We need not call ResetExprContext here because ExecQualAndReset() will
60 * reset the per-tuple memory context once per input tuple.
61 */
62
63 /*
64 * If first time through, acquire first input tuple and determine whether
65 * to return it or not.
66 */
68 {
71 {
72 /* empty input, so return nothing */
73 node->grp_done = true;
74 return NULL;
75 }
76 /* Copy tuple into firsttupleslot */
78
79 /*
80 * Set it up as input for qual test and projection. The expressions
81 * will access the input tuple as varno OUTER.
82 */
84
85 /*
86 * Check the qual (HAVING clause); if the group does not match, ignore
87 * it and fall into scan loop.
88 */
89 if (ExecQual(node->ss.ps.qual, econtext))
90 {
91 /*
92 * Form and return a projection tuple using the first input tuple.
93 */
94 return ExecProject(node->ss.ps.ps_ProjInfo);
95 }
96 else
97 InstrCountFiltered1(node, 1);
98 }
99
100 /*
101 * This loop iterates once per input tuple group. At the head of the
102 * loop, we have finished processing the first tuple of the group and now
103 * need to scan over all the other group members.
104 */
105 for (;;)
106 {
107 /*
108 * Scan over all remaining tuples that belong to this group
109 */
110 for (;;)
111 {
113 if (TupIsNull(outerslot))
114 {
115 /* no more groups, so we're done */
116 node->grp_done = true;
117 return NULL;
118 }
119
120 /*
121 * Compare with first tuple and see if this tuple is of the same
122 * group. If so, ignore it and keep scanning.
123 */
125 econtext->ecxt_outertuple = outerslot;
126 if (!ExecQualAndReset(node->eqfunction, econtext))
127 break;
128 }
129
130 /*
131 * We have the first tuple of the next input group. See if we want to
132 * return it.
133 */
134 /* Copy tuple, set up as input for qual test and projection */
137
138 /*
139 * Check the qual (HAVING clause); if the group does not match, ignore
140 * it and loop back to scan the rest of the group.
141 */
142 if (ExecQual(node->ss.ps.qual, econtext))
143 {
144 /*
145 * Form and return a projection tuple using the first input tuple.
146 */
147 return ExecProject(node->ss.ps.ps_ProjInfo);
148 }
149 else
150 InstrCountFiltered1(node, 1);
151 }
152}
#define InstrCountFiltered1(node, delta)
Definition execnodes.h:1281
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
Definition executor.h:486
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition executor.h:522
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition executor.h:549
static TupleTableSlot * ExecProcNode(PlanState *node)
Definition executor.h:315
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
#define castNode(_type_, nodeptr)
Definition nodes.h:182
static int fb(int x)
TupleTableSlot * ecxt_innertuple
Definition execnodes.h:286
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:288
ExprState * eqfunction
Definition execnodes.h:2379
ScanState ss
Definition execnodes.h:2378
bool grp_done
Definition execnodes.h:2380
ExprState * qual
Definition execnodes.h:1198
ExprContext * ps_ExprContext
Definition execnodes.h:1216
ProjectionInfo * ps_ProjInfo
Definition execnodes.h:1217
TupleTableSlot * ss_ScanTupleSlot
Definition execnodes.h:1636
PlanState ps
Definition execnodes.h:1633
#define TupIsNull(slot)
Definition tuptable.h:325
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition tuptable.h:543

References castNode, CHECK_FOR_INTERRUPTS, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, GroupState::eqfunction, ExecCopySlot(), ExecProcNode(), ExecProject(), ExecQual(), ExecQualAndReset(), fb(), GroupState::grp_done, InstrCountFiltered1, outerPlanState, ScanState::ps, PlanState::ps_ExprContext, PlanState::ps_ProjInfo, PlanState::qual, GroupState::ss, ScanState::ss_ScanTupleSlot, and TupIsNull.

Referenced by ExecInitGroup().

◆ ExecInitGroup()

GroupState * ExecInitGroup ( Group node,
EState estate,
int  eflags 
)

Definition at line 162 of file nodeGroup.c.

163{
165 const TupleTableSlotOps *tts_ops;
166
167 /* check for unsupported flags */
169
170 /*
171 * create state structure
172 */
174 grpstate->ss.ps.plan = (Plan *) node;
175 grpstate->ss.ps.state = estate;
176 grpstate->ss.ps.ExecProcNode = ExecGroup;
177 grpstate->grp_done = false;
178
179 /*
180 * create expression context
181 */
182 ExecAssignExprContext(estate, &grpstate->ss.ps);
183
184 /*
185 * initialize child nodes
186 */
187 outerPlanState(grpstate) = ExecInitNode(outerPlan(node), estate, eflags);
188
189 /*
190 * Initialize scan slot and type.
191 */
193 ExecCreateScanSlotFromOuterPlan(estate, &grpstate->ss, tts_ops);
194
195 /*
196 * Initialize result slot, type and projection.
197 */
200
201 /*
202 * initialize child expressions
203 */
204 grpstate->ss.ps.qual =
206
207 /*
208 * Precompute fmgr lookup data for inner loop
209 */
210 grpstate->eqfunction =
212 node->numCols,
213 node->grpColIdx,
214 node->grpOperators,
215 node->grpCollations,
216 &grpstate->ss.ps);
217
218 return grpstate;
219}
#define Assert(condition)
Definition c.h:945
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition execExpr.c:250
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
TupleDesc ExecGetResultType(PlanState *planstate)
Definition execUtils.c:500
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition execUtils.c:709
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:490
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition execUtils.c:588
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition execUtils.c:509
#define EXEC_FLAG_BACKWARD
Definition executor.h:70
#define EXEC_FLAG_MARK
Definition executor.h:71
static TupleTableSlot * ExecGroup(PlanState *pstate)
Definition nodeGroup.c:37
#define makeNode(_type_)
Definition nodes.h:161
int numCols
Definition plannodes.h:1181
Plan plan
Definition plannodes.h:1178
List * qual
Definition plannodes.h:235

References Assert, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecCreateScanSlotFromOuterPlan(), ExecGetResultSlotOps(), ExecGetResultType(), ExecGroup(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlotTL(), execTuplesMatchPrepare(), fb(), makeNode, Group::numCols, outerPlan, outerPlanState, Group::plan, Plan::qual, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanGroup()

void ExecReScanGroup ( GroupState node)

Definition at line 236 of file nodeGroup.c.

237{
239
240 node->grp_done = false;
241 /* must clear first tuple */
243
244 /*
245 * if chgParam of subnode is not null then plan will be re-scanned by
246 * first ExecProcNode.
247 */
248 if (outerPlan->chgParam == NULL)
250}
void ExecReScan(PlanState *node)
Definition execAmi.c:78
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476

References ExecClearTuple(), ExecReScan(), fb(), GroupState::grp_done, outerPlan, outerPlanState, GroupState::ss, and ScanState::ss_ScanTupleSlot.

Referenced by ExecReScan().