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 211 of file nodeValuesscan.c.

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 = lfirst_node(List, 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 }
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
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1334
void * palloc(Size size)
Definition: mcxt.c:1304
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:713
List * es_subplanstates
Definition: execnodes.h:680
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:1556
ScanState ss
Definition: execnodes.h:1936
List ** exprlists
Definition: execnodes.h:1938
List ** exprstatelists
Definition: execnodes.h:1939
ExprContext * rowcontext
Definition: execnodes.h:1937
Scan scan
Definition: plannodes.h:620
List * values_lists
Definition: plannodes.h:621

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 329 of file nodeValuesscan.c.

330 {
331  if (node->ss.ps.ps_ResultTupleSlot)
333 
334  ExecScanReScan(&node->ss);
335 
336  node->curr_idx = -1;
337 }
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().