PostgreSQL Source Code  git master
nodeValuesscan.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeValuesscan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ValuesScanStateExecInitValuesScan (ValuesScan *node, EState *estate, int eflags)
 
void ExecEndValuesScan (ValuesScanState *node)
 
void ExecReScanValuesScan (ValuesScanState *node)
 

Function Documentation

◆ ExecEndValuesScan()

void ExecEndValuesScan ( ValuesScanState node)

Definition at line 329 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().

330 {
331  /*
332  * Free both exprcontexts
333  */
334  ExecFreeExprContext(&node->ss.ps);
335  node->ss.ps.ps_ExprContext = node->rowcontext;
336  ExecFreeExprContext(&node->ss.ps);
337 
338  /*
339  * clean out the tuple table
340  */
341  if (node->ss.ps.ps_ResultTupleSlot)
344 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
ExprContext * ps_ExprContext
Definition: execnodes.h:984
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1335
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:655
ScanState ss
Definition: execnodes.h:1698
PlanState ps
Definition: execnodes.h:1332
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
ExprContext * rowcontext
Definition: execnodes.h:1699

◆ ExecInitValuesScan()

ValuesScanState* ExecInitValuesScan ( ValuesScan node,
EState estate,
int  eflags 
)

Definition at line 211 of file nodeValuesscan.c.

References Assert, castNode, contain_subplans(), EState::es_jit_flags, EState::es_subplanstates, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitExprList(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), PlanState::ExecProcNode, ExecTypeFromExprList(), ExecValuesScan(), i, innerPlan, lfirst, linitial, list_length(), makeNode, outerPlan, palloc(), palloc0(), PGJIT_NONE, Scan::plan, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::qual, ValuesScanState::rowcontext, ValuesScan::scan, ValuesScanState::ss, PlanState::state, TTSOpsVirtual, and ValuesScan::values_lists.

Referenced by ExecInitNode().

212 {
213  ValuesScanState *scanstate;
214  TupleDesc tupdesc;
215  ListCell *vtl;
216  int i;
217  PlanState *planstate;
218 
219  /*
220  * ValuesScan should not have any children.
221  */
222  Assert(outerPlan(node) == NULL);
223  Assert(innerPlan(node) == NULL);
224 
225  /*
226  * create new ScanState for node
227  */
228  scanstate = makeNode(ValuesScanState);
229  scanstate->ss.ps.plan = (Plan *) node;
230  scanstate->ss.ps.state = estate;
231  scanstate->ss.ps.ExecProcNode = ExecValuesScan;
232 
233  /*
234  * Miscellaneous initialization
235  */
236  planstate = &scanstate->ss.ps;
237 
238  /*
239  * Create expression contexts. We need two, one for per-sublist
240  * processing and one for execScan.c to use for quals and projections. We
241  * cheat a little by using ExecAssignExprContext() to build both.
242  */
243  ExecAssignExprContext(estate, planstate);
244  scanstate->rowcontext = planstate->ps_ExprContext;
245  ExecAssignExprContext(estate, planstate);
246 
247  /*
248  * Get info about values list, initialize scan slot with it.
249  */
250  tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists));
251  ExecInitScanTupleSlot(estate, &scanstate->ss, tupdesc, &TTSOpsVirtual);
252 
253  /*
254  * Initialize result type and projection.
255  */
256  ExecInitResultTypeTL(&scanstate->ss.ps);
257  ExecAssignScanProjectionInfo(&scanstate->ss);
258 
259  /*
260  * initialize child expressions
261  */
262  scanstate->ss.ps.qual =
263  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
264 
265  /*
266  * Other node-specific setup
267  */
268  scanstate->curr_idx = -1;
269  scanstate->array_len = list_length(node->values_lists);
270 
271  /*
272  * Convert the list of expression sublists into an array for easier
273  * addressing at runtime. Also, detect whether any sublists contain
274  * SubPlans; for just those sublists, go ahead and do expression
275  * initialization. (This avoids problems with SubPlans wanting to connect
276  * themselves up to the outer plan tree. Notably, EXPLAIN won't see the
277  * subplans otherwise; also we will have troubles with dangling pointers
278  * and/or leaked resources if we try to handle SubPlans the same as
279  * simpler expressions.)
280  */
281  scanstate->exprlists = (List **)
282  palloc(scanstate->array_len * sizeof(List *));
283  scanstate->exprstatelists = (List **)
284  palloc0(scanstate->array_len * sizeof(List *));
285  i = 0;
286  foreach(vtl, node->values_lists)
287  {
288  List *exprs = castNode(List, lfirst(vtl));
289 
290  scanstate->exprlists[i] = exprs;
291 
292  /*
293  * We can avoid the cost of a contain_subplans() scan in the simple
294  * case where there are no SubPlans anywhere.
295  */
296  if (estate->es_subplanstates &&
297  contain_subplans((Node *) exprs))
298  {
299  int saved_jit_flags;
300 
301  /*
302  * As these expressions are only used once, disable JIT for them.
303  * This is worthwhile because it's common to insert significant
304  * amounts of data via VALUES(). Note that this doesn't prevent
305  * use of JIT *within* a subplan, since that's initialized
306  * separately; this just affects the upper-level subexpressions.
307  */
308  saved_jit_flags = estate->es_jit_flags;
309  estate->es_jit_flags = PGJIT_NONE;
310 
311  scanstate->exprstatelists[i] = ExecInitExprList(exprs,
312  &scanstate->ss.ps);
313 
314  estate->es_jit_flags = saved_jit_flags;
315  }
316  i++;
317  }
318 
319  return scanstate;
320 }
List * qual
Definition: plannodes.h:143
Plan plan
Definition: plannodes.h:344
static TupleTableSlot * ExecValuesScan(PlanState *pstate)
#define PGJIT_NONE
Definition: jit.h:19
List ** exprstatelists
Definition: execnodes.h:1701
#define castNode(_type_, nodeptr)
Definition: nodes.h:598
ExprContext * ps_ExprContext
Definition: execnodes.h:984
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
Definition: nodes.h:529
List * values_lists
Definition: plannodes.h:536
EState * state
Definition: execnodes.h:947
Scan scan
Definition: plannodes.h:535
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:209
ScanState ss
Definition: execnodes.h:1698
bool contain_subplans(Node *clause)
Definition: clauses.c:612
PlanState ps
Definition: execnodes.h:1332
#define linitial(l)
Definition: pg_list.h:195
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:272
#define innerPlan(node)
Definition: plannodes.h:171
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1781
int es_jit_flags
Definition: execnodes.h:600
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1725
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:318
#define outerPlan(node)
Definition: plannodes.h:172
void * palloc0(Size size)
Definition: mcxt.c:980
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
ExprContext * rowcontext
Definition: execnodes.h:1699
Plan * plan
Definition: execnodes.h:945
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
static int list_length(const List *l)
Definition: pg_list.h:169
List * es_subplanstates
Definition: execnodes.h:567
ExprState * qual
Definition: execnodes.h:966
TupleDesc ExecTypeFromExprList(List *exprList)
Definition: execTuples.c:1967
void * palloc(Size size)
Definition: mcxt.c:949
int i
List ** exprlists
Definition: execnodes.h:1700
Definition: pg_list.h:50

◆ ExecReScanValuesScan()

void ExecReScanValuesScan ( ValuesScanState node)

Definition at line 353 of file nodeValuesscan.c.

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

Referenced by ExecReScan().

354 {
355  if (node->ss.ps.ps_ResultTupleSlot)
357 
358  ExecScanReScan(&node->ss);
359 
360  node->curr_idx = -1;
361 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
ScanState ss
Definition: execnodes.h:1698
PlanState ps
Definition: execnodes.h:1332
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299