PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeSort.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeSort.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SortStateExecInitSort (Sort *node, EState *estate, int eflags)
 
void ExecEndSort (SortState *node)
 
void ExecSortMarkPos (SortState *node)
 
void ExecSortRestrPos (SortState *node)
 
void ExecReScanSort (SortState *node)
 

Function Documentation

void ExecEndSort ( SortState node)

Definition at line 228 of file nodeSort.c.

References ExecClearTuple(), ExecEndNode(), NULL, outerPlanState, ScanState::ps, PlanState::ps_ResultTupleSlot, SO1_printf, SortState::ss, ScanState::ss_ScanTupleSlot, tuplesort_end(), and SortState::tuplesortstate.

Referenced by ExecEndNode().

229 {
230  SO1_printf("ExecEndSort: %s\n",
231  "shutting down sort node");
232 
233  /*
234  * clean out the tuple table
235  */
237  /* must drop pointer to sort result tuple */
239 
240  /*
241  * Release tuplesort resources
242  */
243  if (node->tuplesortstate != NULL)
245  node->tuplesortstate = NULL;
246 
247  /*
248  * shut down the subplan
249  */
251 
252  SO1_printf("ExecEndSort: %s\n",
253  "sort node shutdown");
254 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
#define SO1_printf(s, p)
Definition: execdebug.h:92
PlanState ps
Definition: execnodes.h:1098
void * tuplesortstate
Definition: execnodes.h:1746
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
#define outerPlanState(node)
Definition: execnodes.h:893
ScanState ss
Definition: execnodes.h:1739
#define NULL
Definition: c.h:229
void tuplesort_end(Tuplesortstate *state)
Definition: tuplesort.c:1167
SortState* ExecInitSort ( Sort node,
EState estate,
int  eflags 
)

Definition at line 156 of file nodeSort.c.

References SortState::bounded, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignResultTypeFromTL(), ExecAssignScanTypeFromOuterPlan(), ExecInitNode(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), PlanState::ExecProcNode, ExecSort(), makeNode, NULL, outerPlan, outerPlanState, PlanState::plan, ScanState::ps, PlanState::ps_ProjInfo, SortState::randomAccess, SO1_printf, SortState::sort_Done, SortState::ss, PlanState::state, and SortState::tuplesortstate.

Referenced by ExecInitNode().

157 {
158  SortState *sortstate;
159 
160  SO1_printf("ExecInitSort: %s\n",
161  "initializing sort node");
162 
163  /*
164  * create state structure
165  */
166  sortstate = makeNode(SortState);
167  sortstate->ss.ps.plan = (Plan *) node;
168  sortstate->ss.ps.state = estate;
169  sortstate->ss.ps.ExecProcNode = ExecSort;
170 
171  /*
172  * We must have random access to the sort output to do backward scan or
173  * mark/restore. We also prefer to materialize the sort output if we
174  * might be called on to rewind and replay it many times.
175  */
176  sortstate->randomAccess = (eflags & (EXEC_FLAG_REWIND |
178  EXEC_FLAG_MARK)) != 0;
179 
180  sortstate->bounded = false;
181  sortstate->sort_Done = false;
182  sortstate->tuplesortstate = NULL;
183 
184  /*
185  * Miscellaneous initialization
186  *
187  * Sort nodes don't initialize their ExprContexts because they never call
188  * ExecQual or ExecProject.
189  */
190 
191  /*
192  * tuple table initialization
193  *
194  * sort nodes only return scan tuples from their sorted relation.
195  */
196  ExecInitResultTupleSlot(estate, &sortstate->ss.ps);
197  ExecInitScanTupleSlot(estate, &sortstate->ss);
198 
199  /*
200  * initialize child nodes
201  *
202  * We shield the child node from the need to support REWIND, BACKWARD, or
203  * MARK/RESTORE.
204  */
206 
207  outerPlanState(sortstate) = ExecInitNode(outerPlan(node), estate, eflags);
208 
209  /*
210  * initialize tuple type. no need to initialize projection info because
211  * this node doesn't do projections.
212  */
213  ExecAssignResultTypeFromTL(&sortstate->ss.ps);
214  ExecAssignScanTypeFromOuterPlan(&sortstate->ss);
215  sortstate->ss.ps.ps_ProjInfo = NULL;
216 
217  SO1_printf("ExecInitSort: %s\n",
218  "sort node initialized");
219 
220  return sortstate;
221 }
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:882
bool bounded
Definition: execnodes.h:1741
EState * state
Definition: execnodes.h:849
#define SO1_printf(s, p)
Definition: execdebug.h:92
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
PlanState ps
Definition: execnodes.h:1098
void * tuplesortstate
Definition: execnodes.h:1746
static TupleTableSlot * ExecSort(PlanState *pstate)
Definition: nodeSort.c:39
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:893
ScanState ss
Definition: execnodes.h:1739
#define EXEC_FLAG_REWIND
Definition: executor.h:59
#define outerPlan(node)
Definition: plannodes.h:174
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define EXEC_FLAG_MARK
Definition: executor.h:61
bool randomAccess
Definition: execnodes.h:1740
bool sort_Done
Definition: execnodes.h:1743
void ExecAssignScanTypeFromOuterPlan(ScanState *scanstate)
Definition: execUtils.c:557
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
void ExecReScanSort ( SortState node)

Definition at line 296 of file nodeSort.c.

References SortState::bound, SortState::bound_Done, SortState::bounded, SortState::bounded_Done, PlanState::chgParam, ExecClearTuple(), ExecReScan(), NULL, outerPlan, outerPlanState, ScanState::ps, PlanState::ps_ResultTupleSlot, SortState::randomAccess, SortState::sort_Done, SortState::ss, tuplesort_end(), tuplesort_rescan(), and SortState::tuplesortstate.

Referenced by ExecReScan().

297 {
299 
300  /*
301  * If we haven't sorted yet, just return. If outerplan's chgParam is not
302  * NULL then it will be re-scanned by ExecProcNode, else no reason to
303  * re-scan it at all.
304  */
305  if (!node->sort_Done)
306  return;
307 
308  /* must drop pointer to sort result tuple */
310 
311  /*
312  * If subnode is to be rescanned then we forget previous sort results; we
313  * have to re-read the subplan and re-sort. Also must re-sort if the
314  * bounded-sort parameters changed or we didn't select randomAccess.
315  *
316  * Otherwise we can just rewind and rescan the sorted output.
317  */
318  if (outerPlan->chgParam != NULL ||
319  node->bounded != node->bounded_Done ||
320  node->bound != node->bound_Done ||
321  !node->randomAccess)
322  {
323  node->sort_Done = false;
325  node->tuplesortstate = NULL;
326 
327  /*
328  * if chgParam of subnode is not null then plan will be re-scanned by
329  * first ExecProcNode.
330  */
331  if (outerPlan->chgParam == NULL)
332  ExecReScan(outerPlan);
333  }
334  else
336 }
bool bounded_Done
Definition: execnodes.h:1744
bool bounded
Definition: execnodes.h:1741
int64 bound
Definition: execnodes.h:1742
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
PlanState ps
Definition: execnodes.h:1098
void * tuplesortstate
Definition: execnodes.h:1746
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
void tuplesort_rescan(Tuplesortstate *state)
Definition: tuplesort.c:3131
#define outerPlanState(node)
Definition: execnodes.h:893
int64 bound_Done
Definition: execnodes.h:1745
ScanState ss
Definition: execnodes.h:1739
Bitmapset * chgParam
Definition: execnodes.h:875
#define outerPlan(node)
Definition: plannodes.h:174
#define NULL
Definition: c.h:229
bool randomAccess
Definition: execnodes.h:1740
bool sort_Done
Definition: execnodes.h:1743
void tuplesort_end(Tuplesortstate *state)
Definition: tuplesort.c:1167
void ExecSortMarkPos ( SortState node)

Definition at line 263 of file nodeSort.c.

References SortState::sort_Done, tuplesort_markpos(), and SortState::tuplesortstate.

Referenced by ExecMarkPos().

264 {
265  /*
266  * if we haven't sorted yet, just return
267  */
268  if (!node->sort_Done)
269  return;
270 
272 }
void * tuplesortstate
Definition: execnodes.h:1746
bool sort_Done
Definition: execnodes.h:1743
void tuplesort_markpos(Tuplesortstate *state)
Definition: tuplesort.c:3166
void ExecSortRestrPos ( SortState node)

Definition at line 281 of file nodeSort.c.

References SortState::sort_Done, tuplesort_restorepos(), and SortState::tuplesortstate.

Referenced by ExecRestrPos().

282 {
283  /*
284  * if we haven't sorted yet, just return.
285  */
286  if (!node->sort_Done)
287  return;
288 
289  /*
290  * restore the scan to the previously marked position
291  */
293 }
void tuplesort_restorepos(Tuplesortstate *state)
Definition: tuplesort.c:3198
void * tuplesortstate
Definition: execnodes.h:1746
bool sort_Done
Definition: execnodes.h:1743