PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeValuesscan.c File Reference
Include dependency graph for nodeValuesscan.c:

Go to the source code of this file.

Functions

static TupleTableSlotValuesNext (ValuesScanState *node)
 
static bool ValuesRecheck (ValuesScanState *node, TupleTableSlot *slot)
 
TupleTableSlotExecValuesScan (ValuesScanState *node)
 
ValuesScanStateExecInitValuesScan (ValuesScan *node, EState *estate, int eflags)
 
void ExecEndValuesScan (ValuesScanState *node)
 
void ExecReScanValuesScan (ValuesScanState *node)
 

Function Documentation

void ExecEndValuesScan ( ValuesScanState node)

Definition at line 286 of file nodeValuesscan.c.

References ExecClearTuple(), ExecFreeExprContext(), ScanState::ps, PlanState::ps_ExprContext, PlanState::ps_ResultTupleSlot, ValuesScanState::rowcontext, ValuesScanState::ss, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

287 {
288  /*
289  * Free both exprcontexts
290  */
291  ExecFreeExprContext(&node->ss.ps);
292  node->ss.ps.ps_ExprContext = node->rowcontext;
293  ExecFreeExprContext(&node->ss.ps);
294 
295  /*
296  * clean out the tuple table
297  */
300 }
ExprContext * ps_ExprContext
Definition: execnodes.h:833
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1050
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:516
ScanState ss
Definition: execnodes.h:1396
PlanState ps
Definition: execnodes.h:1047
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:832
ExprContext * rowcontext
Definition: execnodes.h:1397
ValuesScanState* ExecInitValuesScan ( ValuesScan node,
EState estate,
int  eflags 
)

Definition at line 201 of file nodeValuesscan.c.

References ValuesScanState::array_len, Assert, ValuesScanState::curr_idx, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecAssignScanType(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecTypeFromExprList(), ValuesScanState::exprlists, i, innerPlan, lfirst, linitial, list_length(), makeNode, NULL, outerPlan, palloc(), Scan::plan, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::qual, ValuesScanState::rowcontext, ValuesScan::scan, ValuesScanState::ss, PlanState::state, and ValuesScan::values_lists.

Referenced by ExecInitNode().

202 {
203  ValuesScanState *scanstate;
204  TupleDesc tupdesc;
205  ListCell *vtl;
206  int i;
207  PlanState *planstate;
208 
209  /*
210  * ValuesScan should not have any children.
211  */
212  Assert(outerPlan(node) == NULL);
213  Assert(innerPlan(node) == NULL);
214 
215  /*
216  * create new ScanState for node
217  */
218  scanstate = makeNode(ValuesScanState);
219  scanstate->ss.ps.plan = (Plan *) node;
220  scanstate->ss.ps.state = estate;
221 
222  /*
223  * Miscellaneous initialization
224  */
225  planstate = &scanstate->ss.ps;
226 
227  /*
228  * Create expression contexts. We need two, one for per-sublist
229  * processing and one for execScan.c to use for quals and projections. We
230  * cheat a little by using ExecAssignExprContext() to build both.
231  */
232  ExecAssignExprContext(estate, planstate);
233  scanstate->rowcontext = planstate->ps_ExprContext;
234  ExecAssignExprContext(estate, planstate);
235 
236  /*
237  * tuple table initialization
238  */
239  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
240  ExecInitScanTupleSlot(estate, &scanstate->ss);
241 
242  /*
243  * initialize child expressions
244  */
245  scanstate->ss.ps.qual =
246  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
247 
248  /*
249  * get info about values list
250  */
251  tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists));
252 
253  ExecAssignScanType(&scanstate->ss, tupdesc);
254 
255  /*
256  * Other node-specific setup
257  */
258  scanstate->curr_idx = -1;
259  scanstate->array_len = list_length(node->values_lists);
260 
261  /* convert list of sublists into array of sublists for easy addressing */
262  scanstate->exprlists = (List **)
263  palloc(scanstate->array_len * sizeof(List *));
264  i = 0;
265  foreach(vtl, node->values_lists)
266  {
267  scanstate->exprlists[i++] = (List *) lfirst(vtl);
268  }
269 
270  /*
271  * Initialize result tuple type and projection info.
272  */
273  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
274  ExecAssignScanProjectionInfo(&scanstate->ss);
275 
276  return scanstate;
277 }
List * qual
Definition: plannodes.h:135
Plan plan
Definition: plannodes.h:317
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
ExprContext * ps_ExprContext
Definition: execnodes.h:833
List * values_lists
Definition: plannodes.h:508
EState * state
Definition: execnodes.h:805
Scan scan
Definition: plannodes.h:507
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:440
ScanState ss
Definition: execnodes.h:1396
PlanState ps
Definition: execnodes.h:1047
#define linitial(l)
Definition: pg_list.h:111
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define innerPlan(node)
Definition: plannodes.h:163
#define outerPlan(node)
Definition: plannodes.h:164
ExprContext * rowcontext
Definition: execnodes.h:1397
Plan * plan
Definition: execnodes.h:803
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:418
static int list_length(const List *l)
Definition: pg_list.h:89
ExprState * qual
Definition: execnodes.h:817
TupleDesc ExecTypeFromExprList(List *exprList)
Definition: execTuples.c:947
void * palloc(Size size)
Definition: mcxt.c:849
int i
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:540
List ** exprlists
Definition: execnodes.h:1398
Definition: pg_list.h:45
void ExecReScanValuesScan ( ValuesScanState node)

Definition at line 309 of file nodeValuesscan.c.

References ValuesScanState::curr_idx, ExecClearTuple(), ExecScanReScan(), ScanState::ps, PlanState::ps_ResultTupleSlot, and ValuesScanState::ss.

Referenced by ExecReScan().

310 {
312 
313  ExecScanReScan(&node->ss);
314 
315  node->curr_idx = -1;
316 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
ScanState ss
Definition: execnodes.h:1396
PlanState ps
Definition: execnodes.h:1047
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:832
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
TupleTableSlot* ExecValuesScan ( ValuesScanState node)

Definition at line 189 of file nodeValuesscan.c.

References ExecScan(), ValuesScanState::ss, ValuesNext(), and ValuesRecheck().

Referenced by ExecProcNode().

190 {
191  return ExecScan(&node->ss,
194 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
ScanState ss
Definition: execnodes.h:1396
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:388
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:389
static TupleTableSlot * ValuesNext(ValuesScanState *node)
static bool ValuesRecheck(ValuesScanState *node, TupleTableSlot *slot)
static TupleTableSlot * ValuesNext ( ValuesScanState node)
static

Definition at line 46 of file nodeValuesscan.c.

References ValuesScanState::array_len, Assert, tupleDesc::attrs, ValuesScanState::curr_idx, ExprContext::ecxt_per_tuple_memory, EState::es_direction, ExecClearTuple(), ExecEvalExpr(), ExecInitExprList(), ExecStoreVirtualTuple(), ValuesScanState::exprlists, lfirst, list_length(), MakeExpandedObjectReadOnly, MemoryContextSwitchTo(), tupleDesc::natts, NIL, NULL, ScanState::ps, ReScanExprContext(), ValuesScanState::rowcontext, ScanDirectionIsForward, ValuesScanState::ss, ScanState::ss_ScanTupleSlot, PlanState::state, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, and values.

Referenced by ExecValuesScan().

47 {
48  TupleTableSlot *slot;
49  EState *estate;
50  ExprContext *econtext;
51  ScanDirection direction;
52  List *exprlist;
53 
54  /*
55  * get information from the estate and scan state
56  */
57  estate = node->ss.ps.state;
58  direction = estate->es_direction;
59  slot = node->ss.ss_ScanTupleSlot;
60  econtext = node->rowcontext;
61 
62  /*
63  * Get the next tuple. Return NULL if no more tuples.
64  */
65  if (ScanDirectionIsForward(direction))
66  {
67  if (node->curr_idx < node->array_len)
68  node->curr_idx++;
69  if (node->curr_idx < node->array_len)
70  exprlist = node->exprlists[node->curr_idx];
71  else
72  exprlist = NIL;
73  }
74  else
75  {
76  if (node->curr_idx >= 0)
77  node->curr_idx--;
78  if (node->curr_idx >= 0)
79  exprlist = node->exprlists[node->curr_idx];
80  else
81  exprlist = NIL;
82  }
83 
84  /*
85  * Always clear the result slot; this is appropriate if we are at the end
86  * of the data, and if we're not, we still need it as the first step of
87  * the store-virtual-tuple protocol. It seems wise to clear the slot
88  * before we reset the context it might have pointers into.
89  */
90  ExecClearTuple(slot);
91 
92  if (exprlist)
93  {
94  MemoryContext oldContext;
95  List *exprstatelist;
96  Datum *values;
97  bool *isnull;
98  Form_pg_attribute *att;
99  ListCell *lc;
100  int resind;
101 
102  /*
103  * Get rid of any prior cycle's leftovers. We use ReScanExprContext
104  * not just ResetExprContext because we want any registered shutdown
105  * callbacks to be called.
106  */
107  ReScanExprContext(econtext);
108 
109  /*
110  * Build the expression eval state in the econtext's per-tuple memory.
111  * This is a tad unusual, but we want to delete the eval state again
112  * when we move to the next row, to avoid growth of memory
113  * requirements over a long values list.
114  */
115  oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
116 
117  /*
118  * Pass NULL, not my plan node, because we don't want anything in this
119  * transient state linking into permanent state. The only possibility
120  * is a SubPlan, and there shouldn't be any (any subselects in the
121  * VALUES list should be InitPlans).
122  */
123  exprstatelist = ExecInitExprList(exprlist, NULL);
124 
125  /* parser should have checked all sublists are the same length */
126  Assert(list_length(exprstatelist) == slot->tts_tupleDescriptor->natts);
127 
128  /*
129  * Compute the expressions and build a virtual result tuple. We
130  * already did ExecClearTuple(slot).
131  */
132  values = slot->tts_values;
133  isnull = slot->tts_isnull;
134  att = slot->tts_tupleDescriptor->attrs;
135 
136  resind = 0;
137  foreach(lc, exprstatelist)
138  {
139  ExprState *estate = (ExprState *) lfirst(lc);
140 
141  values[resind] = ExecEvalExpr(estate,
142  econtext,
143  &isnull[resind]);
144 
145  /*
146  * We must force any R/W expanded datums to read-only state, in
147  * case they are multiply referenced in the plan node's output
148  * expressions, or in case we skip the output projection and the
149  * output column is multiply referenced in higher plan nodes.
150  */
151  values[resind] = MakeExpandedObjectReadOnly(values[resind],
152  isnull[resind],
153  att[resind]->attlen);
154 
155  resind++;
156  }
157 
158  MemoryContextSwitchTo(oldContext);
159 
160  /*
161  * And return the virtual tuple.
162  */
163  ExecStoreVirtualTuple(slot);
164  }
165 
166  return slot;
167 }
#define NIL
Definition: pg_list.h:69
#define ScanDirectionIsForward(direction)
Definition: sdir.h:55
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:203
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
Form_pg_attribute * attrs
Definition: tupdesc.h:74
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Datum * tts_values
Definition: tuptable.h:125
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1050
EState * state
Definition: execnodes.h:805
int natts
Definition: tupdesc.h:73
ScanDirection es_direction
Definition: execnodes.h:408
ScanState ss
Definition: execnodes.h:1396
PlanState ps
Definition: execnodes.h:1047
bool * tts_isnull
Definition: tuptable.h:126
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:265
ScanDirection
Definition: sdir.h:22
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:266
#define MakeExpandedObjectReadOnly(d, isnull, typlen)
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
ExprContext * rowcontext
Definition: execnodes.h:1397
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
void ReScanExprContext(ExprContext *econtext)
Definition: execUtils.c:376
static Datum values[MAXATTR]
Definition: bootstrap.c:163
List ** exprlists
Definition: execnodes.h:1398
Definition: pg_list.h:45
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:488
static bool ValuesRecheck ( ValuesScanState node,
TupleTableSlot slot 
)
static

Definition at line 173 of file nodeValuesscan.c.

Referenced by ExecValuesScan().

174 {
175  /* nothing to check */
176  return true;
177 }