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 ExecReScanValuesScan (ValuesScanState *node)
 

Function Documentation

◆ ExecInitValuesScan()

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

Definition at line 210 of file nodeValuesscan.c.

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

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

Referenced by ExecInitNode().

◆ ExecReScanValuesScan()

void ExecReScanValuesScan ( ValuesScanState node)

Definition at line 328 of file nodeValuesscan.c.

329 {
330  if (node->ss.ps.ps_ResultTupleSlot)
332 
333  ExecScanReScan(&node->ss);
334 
335  node->curr_idx = -1;
336 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:297
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1154
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

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

Referenced by ExecReScan().