PostgreSQL Source Code  git master
execUtils.c File Reference
#include "postgres.h"
#include "access/parallel.h"
#include "access/relscan.h"
#include "access/table.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "executor/executor.h"
#include "executor/execPartition.h"
#include "executor/nodeModifyTable.h"
#include "jit/jit.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parsetree.h"
#include "parser/parse_relation.h"
#include "partitioning/partdesc.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/typcache.h"
Include dependency graph for execUtils.c:

Go to the source code of this file.

Functions

static bool tlist_matches_tupdesc (PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
 
static void ShutdownExprContext (ExprContext *econtext, bool isCommit)
 
static RTEPermissionInfoGetResultRTEPermissionInfo (ResultRelInfo *relinfo, EState *estate)
 
EStateCreateExecutorState (void)
 
void FreeExecutorState (EState *estate)
 
static ExprContextCreateExprContextInternal (EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
 
ExprContextCreateExprContext (EState *estate)
 
ExprContextCreateWorkExprContext (EState *estate)
 
ExprContextCreateStandaloneExprContext (void)
 
void FreeExprContext (ExprContext *econtext, bool isCommit)
 
void ReScanExprContext (ExprContext *econtext)
 
ExprContextMakePerTupleExprContext (EState *estate)
 
void ExecAssignExprContext (EState *estate, PlanState *planstate)
 
TupleDesc ExecGetResultType (PlanState *planstate)
 
const TupleTableSlotOpsExecGetResultSlotOps (PlanState *planstate, bool *isfixed)
 
void ExecAssignProjectionInfo (PlanState *planstate, TupleDesc inputDesc)
 
void ExecConditionalAssignProjectionInfo (PlanState *planstate, TupleDesc inputDesc, int varno)
 
void ExecFreeExprContext (PlanState *planstate)
 
void ExecAssignScanType (ScanState *scanstate, TupleDesc tupDesc)
 
void ExecCreateScanSlotFromOuterPlan (EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
 
bool ExecRelationIsTargetRelation (EState *estate, Index scanrelid)
 
Relation ExecOpenScanRelation (EState *estate, Index scanrelid, int eflags)
 
void ExecInitRangeTable (EState *estate, List *rangeTable, List *permInfos)
 
Relation ExecGetRangeTableRelation (EState *estate, Index rti)
 
void ExecInitResultRelation (EState *estate, ResultRelInfo *resultRelInfo, Index rti)
 
void UpdateChangedParamSet (PlanState *node, Bitmapset *newchg)
 
int executor_errposition (EState *estate, int location)
 
void RegisterExprContextCallback (ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
 
void UnregisterExprContextCallback (ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
 
Datum GetAttributeByName (HeapTupleHeader tuple, const char *attname, bool *isNull)
 
Datum GetAttributeByNum (HeapTupleHeader tuple, AttrNumber attrno, bool *isNull)
 
int ExecTargetListLength (List *targetlist)
 
int ExecCleanTargetListLength (List *targetlist)
 
TupleTableSlotExecGetTriggerOldSlot (EState *estate, ResultRelInfo *relInfo)
 
TupleTableSlotExecGetTriggerNewSlot (EState *estate, ResultRelInfo *relInfo)
 
TupleTableSlotExecGetReturningSlot (EState *estate, ResultRelInfo *relInfo)
 
TupleConversionMapExecGetChildToRootMap (ResultRelInfo *resultRelInfo)
 
TupleConversionMapExecGetRootToChildMap (ResultRelInfo *resultRelInfo, EState *estate)
 
BitmapsetExecGetInsertedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetExtraUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetAllUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
Oid ExecGetResultRelCheckAsUser (ResultRelInfo *relInfo, EState *estate)
 

Function Documentation

◆ CreateExecutorState()

EState* CreateExecutorState ( void  )

Definition at line 93 of file execUtils.c.

94 {
95  EState *estate;
96  MemoryContext qcontext;
97  MemoryContext oldcontext;
98 
99  /*
100  * Create the per-query context for this Executor run.
101  */
103  "ExecutorState",
105 
106  /*
107  * Make the EState node within the per-query context. This way, we don't
108  * need a separate pfree() operation for it at shutdown.
109  */
110  oldcontext = MemoryContextSwitchTo(qcontext);
111 
112  estate = makeNode(EState);
113 
114  /*
115  * Initialize all fields of the Executor State structure
116  */
118  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
119  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
120  estate->es_range_table = NIL;
121  estate->es_range_table_size = 0;
122  estate->es_relations = NULL;
123  estate->es_rowmarks = NULL;
124  estate->es_rteperminfos = NIL;
125  estate->es_plannedstmt = NULL;
126 
127  estate->es_junkFilter = NULL;
128 
129  estate->es_output_cid = (CommandId) 0;
130 
131  estate->es_result_relations = NULL;
134  estate->es_trig_target_relations = NIL;
135 
138 
139  estate->es_param_list_info = NULL;
140  estate->es_param_exec_vals = NULL;
141 
142  estate->es_queryEnv = NULL;
143 
144  estate->es_query_cxt = qcontext;
145 
146  estate->es_tupleTable = NIL;
147 
148  estate->es_processed = 0;
149  estate->es_total_processed = 0;
150 
151  estate->es_top_eflags = 0;
152  estate->es_instrument = 0;
153  estate->es_finished = false;
154 
155  estate->es_exprcontexts = NIL;
156 
157  estate->es_subplanstates = NIL;
158 
159  estate->es_auxmodifytables = NIL;
160 
161  estate->es_per_tuple_exprcontext = NULL;
162 
163  estate->es_sourceText = NULL;
164 
165  estate->es_use_parallel_mode = false;
166 
167  estate->es_jit_flags = 0;
168  estate->es_jit = NULL;
169 
170  /*
171  * Return the executor state structure
172  */
173  MemoryContextSwitchTo(oldcontext);
174 
175  return estate;
176 }
uint32 CommandId
Definition: c.h:650
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
#define makeNode(_type_)
Definition: nodes.h:176
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define NIL
Definition: pg_list.h:68
@ ForwardScanDirection
Definition: sdir.h:28
#define InvalidSnapshot
Definition: snapshot.h:123
uint64 es_processed
Definition: execnodes.h:663
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:622
List * es_tuple_routing_result_relations
Definition: execnodes.h:647
int es_top_eflags
Definition: execnodes.h:668
struct JitContext * es_jit
Definition: execnodes.h:708
int es_instrument
Definition: execnodes.h:669
PlannedStmt * es_plannedstmt
Definition: execnodes.h:625
QueryEnvironment * es_queryEnv
Definition: execnodes.h:656
ResultRelInfo ** es_result_relations
Definition: execnodes.h:634
ParamExecData * es_param_exec_vals
Definition: execnodes.h:654
uint64 es_total_processed
Definition: execnodes.h:665
List * es_range_table
Definition: execnodes.h:618
List * es_rteperminfos
Definition: execnodes.h:624
List * es_exprcontexts
Definition: execnodes.h:672
ParamListInfo es_param_list_info
Definition: execnodes.h:653
bool es_finished
Definition: execnodes.h:670
List * es_insert_pending_result_relations
Definition: execnodes.h:715
MemoryContext es_query_cxt
Definition: execnodes.h:659
List * es_tupleTable
Definition: execnodes.h:661
ScanDirection es_direction
Definition: execnodes.h:615
List * es_trig_target_relations
Definition: execnodes.h:650
int es_jit_flags
Definition: execnodes.h:707
List * es_opened_result_relations
Definition: execnodes.h:637
bool es_use_parallel_mode
Definition: execnodes.h:693
Relation * es_relations
Definition: execnodes.h:620
List * es_subplanstates
Definition: execnodes.h:674
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:683
CommandId es_output_cid
Definition: execnodes.h:631
Index es_range_table_size
Definition: execnodes.h:619
List * es_insert_pending_modifytables
Definition: execnodes.h:716
const char * es_sourceText
Definition: execnodes.h:626
Snapshot es_snapshot
Definition: execnodes.h:616
List * es_auxmodifytables
Definition: execnodes.h:676
JunkFilter * es_junkFilter
Definition: execnodes.h:628
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:617

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CurrentMemoryContext, EState::es_auxmodifytables, EState::es_crosscheck_snapshot, EState::es_direction, EState::es_exprcontexts, EState::es_finished, EState::es_insert_pending_modifytables, EState::es_insert_pending_result_relations, EState::es_instrument, EState::es_jit, EState::es_jit_flags, EState::es_junkFilter, EState::es_opened_result_relations, EState::es_output_cid, EState::es_param_exec_vals, EState::es_param_list_info, EState::es_per_tuple_exprcontext, EState::es_plannedstmt, EState::es_processed, EState::es_query_cxt, EState::es_queryEnv, EState::es_range_table, EState::es_range_table_size, EState::es_relations, EState::es_result_relations, EState::es_rowmarks, EState::es_rteperminfos, EState::es_snapshot, EState::es_sourceText, EState::es_subplanstates, EState::es_top_eflags, EState::es_total_processed, EState::es_trig_target_relations, EState::es_tuple_routing_result_relations, EState::es_tupleTable, EState::es_use_parallel_mode, ForwardScanDirection, InvalidSnapshot, makeNode, MemoryContextSwitchTo(), and NIL.

Referenced by afterTriggerInvokeEvents(), ATRewriteTable(), check_default_partition_contents(), compute_expr_stats(), compute_index_stats(), CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), EvalPlanQualStart(), evaluate_expr(), ExecuteCallStmt(), ExecuteQuery(), ExecuteTruncateGuts(), ExplainExecuteQuery(), fileIterateForeignScan(), get_qual_for_range(), heapam_index_build_range_scan(), heapam_index_validate_scan(), IndexCheckExclusion(), make_build_data(), operator_predicate_proof(), plpgsql_create_econtext(), plpgsql_inline_handler(), standard_ExecutorStart(), StoreAttrDefault(), tuplesort_begin_cluster(), and validateDomainConstraint().

◆ CreateExprContext()

ExprContext* CreateExprContext ( EState estate)

Definition at line 309 of file execUtils.c.

310 {
312 }
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:239

References ALLOCSET_DEFAULT_SIZES, and CreateExprContextInternal().

Referenced by ExecAssignExprContext(), ExecInitMergeJoin(), ExecInitSubPlan(), ExecuteCallStmt(), MakePerTupleExprContext(), and plpgsql_create_econtext().

◆ CreateExprContextInternal()

static ExprContext* CreateExprContextInternal ( EState estate,
Size  minContextSize,
Size  initBlockSize,
Size  maxBlockSize 
)
static

Definition at line 239 of file execUtils.c.

241 {
242  ExprContext *econtext;
243  MemoryContext oldcontext;
244 
245  /* Create the ExprContext node within the per-query memory context */
246  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
247 
248  econtext = makeNode(ExprContext);
249 
250  /* Initialize fields of ExprContext */
251  econtext->ecxt_scantuple = NULL;
252  econtext->ecxt_innertuple = NULL;
253  econtext->ecxt_outertuple = NULL;
254 
255  econtext->ecxt_per_query_memory = estate->es_query_cxt;
256 
257  /*
258  * Create working memory for expression evaluation in this context.
259  */
260  econtext->ecxt_per_tuple_memory =
262  "ExprContext",
263  minContextSize,
264  initBlockSize,
265  maxBlockSize);
266 
267  econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
268  econtext->ecxt_param_list_info = estate->es_param_list_info;
269 
270  econtext->ecxt_aggvalues = NULL;
271  econtext->ecxt_aggnulls = NULL;
272 
273  econtext->caseValue_datum = (Datum) 0;
274  econtext->caseValue_isNull = true;
275 
276  econtext->domainValue_datum = (Datum) 0;
277  econtext->domainValue_isNull = true;
278 
279  econtext->ecxt_estate = estate;
280 
281  econtext->ecxt_callbacks = NULL;
282 
283  /*
284  * Link the ExprContext into the EState to ensure it is shut down when the
285  * EState is freed. Because we use lcons(), shutdowns will occur in
286  * reverse order of creation, which may not be essential but can't hurt.
287  */
288  estate->es_exprcontexts = lcons(econtext, estate->es_exprcontexts);
289 
290  MemoryContextSwitchTo(oldcontext);
291 
292  return econtext;
293 }
List * lcons(void *datum, List *list)
Definition: list.c:494
uintptr_t Datum
Definition: postgres.h:64
Datum domainValue_datum
Definition: execnodes.h:280
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:261
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:257
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:251
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:260
Datum * ecxt_aggvalues
Definition: execnodes.h:268
bool caseValue_isNull
Definition: execnodes.h:276
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:249
Datum caseValue_datum
Definition: execnodes.h:274
bool * ecxt_aggnulls
Definition: execnodes.h:270
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:256
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:288
bool domainValue_isNull
Definition: execnodes.h:282
struct EState * ecxt_estate
Definition: execnodes.h:285
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:253

References AllocSetContextCreate, ExprContext::caseValue_datum, ExprContext::caseValue_isNull, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_callbacks, ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_param_exec_vals, ExprContext::ecxt_param_list_info, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, EState::es_exprcontexts, EState::es_param_exec_vals, EState::es_param_list_info, EState::es_query_cxt, lcons(), makeNode, and MemoryContextSwitchTo().

Referenced by CreateExprContext(), and CreateWorkExprContext().

◆ CreateStandaloneExprContext()

ExprContext* CreateStandaloneExprContext ( void  )

Definition at line 360 of file execUtils.c.

361 {
362  ExprContext *econtext;
363 
364  /* Create the ExprContext node within the caller's memory context */
365  econtext = makeNode(ExprContext);
366 
367  /* Initialize fields of ExprContext */
368  econtext->ecxt_scantuple = NULL;
369  econtext->ecxt_innertuple = NULL;
370  econtext->ecxt_outertuple = NULL;
371 
373 
374  /*
375  * Create working memory for expression evaluation in this context.
376  */
377  econtext->ecxt_per_tuple_memory =
379  "ExprContext",
381 
382  econtext->ecxt_param_exec_vals = NULL;
383  econtext->ecxt_param_list_info = NULL;
384 
385  econtext->ecxt_aggvalues = NULL;
386  econtext->ecxt_aggnulls = NULL;
387 
388  econtext->caseValue_datum = (Datum) 0;
389  econtext->caseValue_isNull = true;
390 
391  econtext->domainValue_datum = (Datum) 0;
392  econtext->domainValue_isNull = true;
393 
394  econtext->ecxt_estate = NULL;
395 
396  econtext->ecxt_callbacks = NULL;
397 
398  return econtext;
399 }

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ExprContext::caseValue_datum, ExprContext::caseValue_isNull, CurrentMemoryContext, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_callbacks, ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_param_exec_vals, ExprContext::ecxt_param_list_info, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, and makeNode.

Referenced by BuildTupleHashTableExt(), domain_check_input(), and hypothetical_dense_rank_final().

◆ CreateWorkExprContext()

ExprContext* CreateWorkExprContext ( EState estate)

Definition at line 324 of file execUtils.c.

325 {
326  Size minContextSize = ALLOCSET_DEFAULT_MINSIZE;
327  Size initBlockSize = ALLOCSET_DEFAULT_INITSIZE;
328  Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
329 
330  /* choose the maxBlockSize to be no larger than 1/16 of work_mem */
331  while (16 * maxBlockSize > work_mem * 1024L)
332  maxBlockSize >>= 1;
333 
334  if (maxBlockSize < ALLOCSET_DEFAULT_INITSIZE)
335  maxBlockSize = ALLOCSET_DEFAULT_INITSIZE;
336 
337  return CreateExprContextInternal(estate, minContextSize,
338  initBlockSize, maxBlockSize);
339 }
size_t Size
Definition: c.h:589
int work_mem
Definition: globals.c:125
#define ALLOCSET_DEFAULT_MAXSIZE
Definition: memutils.h:152
#define ALLOCSET_DEFAULT_MINSIZE
Definition: memutils.h:150
#define ALLOCSET_DEFAULT_INITSIZE
Definition: memutils.h:151

References ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE, ALLOCSET_DEFAULT_MINSIZE, CreateExprContextInternal(), and work_mem.

Referenced by ExecInitAgg().

◆ ExecAssignExprContext()

◆ ExecAssignProjectionInfo()

void ExecAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc 
)

Definition at line 543 of file execUtils.c.

545 {
546  planstate->ps_ProjInfo =
548  planstate->ps_ExprContext,
549  planstate->ps_ResultTupleSlot,
550  planstate,
551  inputDesc);
552 }
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:357
Plan * plan
Definition: execnodes.h:1037
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1075
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1077
List * targetlist
Definition: plannodes.h:153

References ExecBuildProjectionInfo(), PlanState::plan, PlanState::ps_ExprContext, PlanState::ps_ProjInfo, PlanState::ps_ResultTupleSlot, and Plan::targetlist.

Referenced by ExecConditionalAssignProjectionInfo(), ExecInitAgg(), ExecInitGroup(), ExecInitHashJoin(), ExecInitMergeJoin(), ExecInitNestLoop(), ExecInitResult(), and ExecInitWindowAgg().

◆ ExecAssignScanType()

void ExecAssignScanType ( ScanState scanstate,
TupleDesc  tupDesc 
)

Definition at line 678 of file execUtils.c.

679 {
680  TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
681 
682  ExecSetSlotDescriptor(slot, tupDesc);
683 }
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1290
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1477

References ExecSetSlotDescriptor(), and ScanState::ss_ScanTupleSlot.

Referenced by ExecWorkTableScan().

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1150 of file execUtils.c.

1151 {
1152  int len = 0;
1153  ListCell *tl;
1154 
1155  foreach(tl, targetlist)
1156  {
1157  TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1158 
1159  if (!curTle->resjunk)
1160  len++;
1161  }
1162  return len;
1163 }
const void size_t len
#define lfirst_node(type, lc)
Definition: pg_list.h:176

References len, and lfirst_node.

Referenced by ApplyRetrieveRule(), check_sql_fn_retval(), and ExecTypeFromTLInternal().

◆ ExecConditionalAssignProjectionInfo()

void ExecConditionalAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc,
int  varno 
)

Definition at line 563 of file execUtils.c.

565 {
566  if (tlist_matches_tupdesc(planstate,
567  planstate->plan->targetlist,
568  varno,
569  inputDesc))
570  {
571  planstate->ps_ProjInfo = NULL;
572  planstate->resultopsset = planstate->scanopsset;
573  planstate->resultopsfixed = planstate->scanopsfixed;
574  planstate->resultops = planstate->scanops;
575  }
576  else
577  {
578  if (!planstate->ps_ResultTupleSlot)
579  {
580  ExecInitResultSlot(planstate, &TTSOpsVirtual);
581  planstate->resultops = &TTSOpsVirtual;
582  planstate->resultopsfixed = true;
583  planstate->resultopsset = true;
584  }
585  ExecAssignProjectionInfo(planstate, inputDesc);
586  }
587 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1780
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
Definition: execUtils.c:590
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:543
const TupleTableSlotOps * resultops
Definition: execnodes.h:1114
bool resultopsset
Definition: execnodes.h:1122
const TupleTableSlotOps * scanops
Definition: execnodes.h:1111
bool scanopsset
Definition: execnodes.h:1119
bool scanopsfixed
Definition: execnodes.h:1115
bool resultopsfixed
Definition: execnodes.h:1118

References ExecAssignProjectionInfo(), ExecInitResultSlot(), PlanState::plan, PlanState::ps_ProjInfo, PlanState::ps_ResultTupleSlot, PlanState::resultops, PlanState::resultopsfixed, PlanState::resultopsset, PlanState::scanops, PlanState::scanopsfixed, PlanState::scanopsset, Plan::targetlist, tlist_matches_tupdesc(), and TTSOpsVirtual.

Referenced by ExecAssignScanProjectionInfo(), ExecAssignScanProjectionInfoWithVarno(), ExecInitGather(), and ExecInitGatherMerge().

◆ ExecCreateScanSlotFromOuterPlan()

void ExecCreateScanSlotFromOuterPlan ( EState estate,
ScanState scanstate,
const TupleTableSlotOps tts_ops 
)

Definition at line 690 of file execUtils.c.

693 {
695  TupleDesc tupDesc;
696 
697  outerPlan = outerPlanState(scanstate);
698  tupDesc = ExecGetResultType(outerPlan);
699 
700  ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
701 }
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1812
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:498
#define outerPlanState(node)
Definition: execnodes.h:1133
#define outerPlan(node)
Definition: plannodes.h:183

References ExecGetResultType(), ExecInitScanTupleSlot(), outerPlan, and outerPlanState.

Referenced by ExecInitAgg(), ExecInitGroup(), ExecInitIncrementalSort(), ExecInitMaterial(), ExecInitMemoize(), ExecInitSort(), and ExecInitWindowAgg().

◆ ExecFreeExprContext()

◆ ExecGetAllUpdatedCols()

Bitmapset* ExecGetAllUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1350 of file execUtils.c.

1351 {
1352  return bms_union(ExecGetUpdatedCols(relinfo, estate),
1353  ExecGetExtraUpdatedCols(relinfo, estate));
1354 }
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:226
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1319
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1340

References bms_union(), ExecGetExtraUpdatedCols(), and ExecGetUpdatedCols().

Referenced by ExecARUpdateTriggers(), ExecASUpdateTriggers(), ExecBRUpdateTriggers(), ExecBSUpdateTriggers(), and ExecUpdateLockMode().

◆ ExecGetChildToRootMap()

TupleConversionMap* ExecGetChildToRootMap ( ResultRelInfo resultRelInfo)

Definition at line 1237 of file execUtils.c.

1238 {
1239  /* If we didn't already do so, compute the map for this child. */
1240  if (!resultRelInfo->ri_ChildToRootMapValid)
1241  {
1242  ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1243 
1244  if (rootRelInfo)
1245  resultRelInfo->ri_ChildToRootMap =
1247  RelationGetDescr(rootRelInfo->ri_RelationDesc));
1248  else /* this isn't a child result rel */
1249  resultRelInfo->ri_ChildToRootMap = NULL;
1250 
1251  resultRelInfo->ri_ChildToRootMapValid = true;
1252  }
1253 
1254  return resultRelInfo->ri_ChildToRootMap;
1255 }
#define RelationGetDescr(relation)
Definition: rel.h:530
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:574
Relation ri_RelationDesc
Definition: execnodes.h:450
TupleConversionMap * ri_ChildToRootMap
Definition: execnodes.h:554
bool ri_ChildToRootMapValid
Definition: execnodes.h:555
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102

References convert_tuples_by_name(), RelationGetDescr, ResultRelInfo::ri_ChildToRootMap, ResultRelInfo::ri_ChildToRootMapValid, ResultRelInfo::ri_RelationDesc, and ResultRelInfo::ri_RootResultRelInfo.

Referenced by adjust_partition_colnos(), AfterTriggerExecute(), AfterTriggerSaveEvent(), ExecCrossPartitionUpdate(), and TransitionTableAddTuple().

◆ ExecGetExtraUpdatedCols()

Bitmapset* ExecGetExtraUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1340 of file execUtils.c.

1341 {
1342  /* Compute the info if we didn't already */
1343  if (relinfo->ri_GeneratedExprsU == NULL)
1344  ExecInitStoredGenerated(relinfo, estate, CMD_UPDATE);
1345  return relinfo->ri_extraUpdatedCols;
1346 }
void ExecInitStoredGenerated(ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
@ CMD_UPDATE
Definition: nodes.h:277
Bitmapset * ri_extraUpdatedCols
Definition: execnodes.h:468
ExprState ** ri_GeneratedExprsU
Definition: execnodes.h:523

References CMD_UPDATE, ExecInitStoredGenerated(), ResultRelInfo::ri_extraUpdatedCols, and ResultRelInfo::ri_GeneratedExprsU.

Referenced by ExecGetAllUpdatedCols(), and index_unchanged_by_update().

◆ ExecGetInsertedCols()

Bitmapset* ExecGetInsertedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1298 of file execUtils.c.

1299 {
1300  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1301 
1302  if (perminfo == NULL)
1303  return NULL;
1304 
1305  /* Map the columns to child's attribute numbers if needed. */
1306  if (relinfo->ri_RootResultRelInfo)
1307  {
1308  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1309 
1310  if (map)
1311  return execute_attr_map_cols(map->attrMap, perminfo->insertedCols);
1312  }
1313 
1314  return perminfo->insertedCols;
1315 }
static RTEPermissionInfo * GetResultRTEPermissionInfo(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1361
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition: execUtils.c:1263
Bitmapset * insertedCols
Definition: parsenodes.h:1249
AttrMap * attrMap
Definition: tupconvert.h:28
Bitmapset * execute_attr_map_cols(AttrMap *attrMap, Bitmapset *in_cols)
Definition: tupconvert.c:252

References TupleConversionMap::attrMap, ExecGetRootToChildMap(), execute_attr_map_cols(), GetResultRTEPermissionInfo(), RTEPermissionInfo::insertedCols, and ResultRelInfo::ri_RootResultRelInfo.

Referenced by ExecConstraints(), ExecPartitionCheckEmitError(), and ExecWithCheckOptions().

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti 
)

Definition at line 793 of file execUtils.c.

794 {
795  Relation rel;
796 
797  Assert(rti > 0 && rti <= estate->es_range_table_size);
798 
799  rel = estate->es_relations[rti - 1];
800  if (rel == NULL)
801  {
802  /* First time through, so open the relation */
803  RangeTblEntry *rte = exec_rt_fetch(rti, estate);
804 
805  Assert(rte->rtekind == RTE_RELATION);
806 
807  if (!IsParallelWorker())
808  {
809  /*
810  * In a normal query, we should already have the appropriate lock,
811  * but verify that through an Assert. Since there's already an
812  * Assert inside table_open that insists on holding some lock, it
813  * seems sufficient to check this only when rellockmode is higher
814  * than the minimum.
815  */
816  rel = table_open(rte->relid, NoLock);
818  CheckRelationLockedByMe(rel, rte->rellockmode, false));
819  }
820  else
821  {
822  /*
823  * If we are a parallel worker, we need to obtain our own local
824  * lock on the relation. This ensures sane behavior in case the
825  * parent process exits before we do.
826  */
827  rel = table_open(rte->relid, rte->rellockmode);
828  }
829 
830  estate->es_relations[rti - 1] = rel;
831  }
832 
833  return rel;
834 }
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:587
#define IsParallelWorker()
Definition: parallel.h:61
Assert(fmt[strlen(fmt) - 1] !='\n')
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:331
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
@ RTE_RELATION
Definition: parsenodes.h:1014
RTEKind rtekind
Definition: parsenodes.h:1033
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References AccessShareLock, Assert(), CheckRelationLockedByMe(), EState::es_relations, exec_rt_fetch(), IsParallelWorker, NoLock, RangeTblEntry::relid, RangeTblEntry::rellockmode, RTE_RELATION, RangeTblEntry::rtekind, and table_open().

Referenced by CreatePartitionPruneState(), ExecInitResultRelation(), ExecOpenScanRelation(), and InitPlan().

◆ ExecGetResultRelCheckAsUser()

Oid ExecGetResultRelCheckAsUser ( ResultRelInfo relInfo,
EState estate 
)

Definition at line 1412 of file execUtils.c.

1413 {
1414  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relInfo, estate);
1415 
1416  /* XXX - maybe ok to return GetUserId() in this case? */
1417  if (perminfo == NULL)
1418  elog(ERROR, "no RTEPermissionInfo found for result relation with OID %u",
1419  RelationGetRelid(relInfo->ri_RelationDesc));
1420 
1421  return perminfo->checkAsUser ? perminfo->checkAsUser : GetUserId();
1422 }
#define ERROR
Definition: elog.h:39
Oid GetUserId(void)
Definition: miscinit.c:510
#define RelationGetRelid(relation)
Definition: rel.h:504

References RTEPermissionInfo::checkAsUser, elog(), ERROR, GetResultRTEPermissionInfo(), GetUserId(), RelationGetRelid, and ResultRelInfo::ri_RelationDesc.

Referenced by create_foreign_modify().

◆ ExecGetResultSlotOps()

const TupleTableSlotOps* ExecGetResultSlotOps ( PlanState planstate,
bool isfixed 
)

Definition at line 507 of file execUtils.c.

508 {
509  if (planstate->resultopsset && planstate->resultops)
510  {
511  if (isfixed)
512  *isfixed = planstate->resultopsfixed;
513  return planstate->resultops;
514  }
515 
516  if (isfixed)
517  {
518  if (planstate->resultopsset)
519  *isfixed = planstate->resultopsfixed;
520  else if (planstate->ps_ResultTupleSlot)
521  *isfixed = TTS_FIXED(planstate->ps_ResultTupleSlot);
522  else
523  *isfixed = false;
524  }
525 
526  if (!planstate->ps_ResultTupleSlot)
527  return &TTSOpsVirtual;
528 
529  return planstate->ps_ResultTupleSlot->tts_ops;
530 }
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
#define TTS_FIXED(slot)
Definition: tuptable.h:109

References PlanState::ps_ResultTupleSlot, PlanState::resultops, PlanState::resultopsfixed, PlanState::resultopsset, TTS_FIXED, TupleTableSlot::tts_ops, and TTSOpsVirtual.

Referenced by ExecComputeSlotInfo(), ExecInitAgg(), ExecInitGroup(), ExecInitHashJoin(), ExecInitLimit(), ExecInitLockRows(), ExecInitMergeJoin(), and ExecInitSubqueryScan().

◆ ExecGetResultType()

◆ ExecGetReturningSlot()

TupleTableSlot* ExecGetReturningSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1213 of file execUtils.c.

1214 {
1215  if (relInfo->ri_ReturningSlot == NULL)
1216  {
1217  Relation rel = relInfo->ri_RelationDesc;
1218  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1219 
1220  relInfo->ri_ReturningSlot =
1221  ExecInitExtraTupleSlot(estate,
1222  RelationGetDescr(rel),
1223  table_slot_callbacks(rel));
1224 
1225  MemoryContextSwitchTo(oldcontext);
1226  }
1227 
1228  return relInfo->ri_ReturningSlot;
1229 }
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1832
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:492
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58

References EState::es_query_cxt, ExecInitExtraTupleSlot(), MemoryContextSwitchTo(), RelationGetDescr, ResultRelInfo::ri_RelationDesc, ResultRelInfo::ri_ReturningSlot, and table_slot_callbacks().

Referenced by apply_returning_filter(), ExecDelete(), and ExecInsert().

◆ ExecGetRootToChildMap()

TupleConversionMap* ExecGetRootToChildMap ( ResultRelInfo resultRelInfo,
EState estate 
)

Definition at line 1263 of file execUtils.c.

1264 {
1265  /* Mustn't get called for a non-child result relation. */
1266  Assert(resultRelInfo->ri_RootResultRelInfo);
1267 
1268  /* If we didn't already do so, compute the map for this child. */
1269  if (!resultRelInfo->ri_RootToChildMapValid)
1270  {
1271  ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1272  TupleDesc indesc = RelationGetDescr(rootRelInfo->ri_RelationDesc);
1273  TupleDesc outdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
1274  Relation childrel = resultRelInfo->ri_RelationDesc;
1275  AttrMap *attrMap;
1276  MemoryContext oldcontext;
1277 
1278  /*
1279  * When this child table is not a partition (!relispartition), it may
1280  * have columns that are not present in the root table, which we ask
1281  * to ignore by passing true for missing_ok.
1282  */
1283  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1284  attrMap = build_attrmap_by_name_if_req(indesc, outdesc,
1285  !childrel->rd_rel->relispartition);
1286  if (attrMap)
1287  resultRelInfo->ri_RootToChildMap =
1288  convert_tuples_by_name_attrmap(indesc, outdesc, attrMap);
1289  MemoryContextSwitchTo(oldcontext);
1290  resultRelInfo->ri_RootToChildMapValid = true;
1291  }
1292 
1293  return resultRelInfo->ri_RootToChildMap;
1294 }
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
Definition: attmap.c:264
Definition: attmap.h:35
Form_pg_class rd_rel
Definition: rel.h:111
TupleConversionMap * ri_RootToChildMap
Definition: execnodes.h:560
bool ri_RootToChildMapValid
Definition: execnodes.h:561
TupleConversionMap * convert_tuples_by_name_attrmap(TupleDesc indesc, TupleDesc outdesc, AttrMap *attrMap)
Definition: tupconvert.c:124

References Assert(), build_attrmap_by_name_if_req(), convert_tuples_by_name_attrmap(), EState::es_query_cxt, MemoryContextSwitchTo(), RelationData::rd_rel, RelationGetDescr, ResultRelInfo::ri_RelationDesc, ResultRelInfo::ri_RootResultRelInfo, ResultRelInfo::ri_RootToChildMap, and ResultRelInfo::ri_RootToChildMapValid.

Referenced by apply_handle_tuple_routing(), CopyFrom(), ExecFindPartition(), ExecGetInsertedCols(), ExecGetUpdatedCols(), ExecInitPartitionInfo(), ExecInitRoutingInfo(), and ExecPrepareTupleRouting().

◆ ExecGetTriggerNewSlot()

TupleTableSlot* ExecGetTriggerNewSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1191 of file execUtils.c.

1192 {
1193  if (relInfo->ri_TrigNewSlot == NULL)
1194  {
1195  Relation rel = relInfo->ri_RelationDesc;
1196  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1197 
1198  relInfo->ri_TrigNewSlot =
1199  ExecInitExtraTupleSlot(estate,
1200  RelationGetDescr(rel),
1201  table_slot_callbacks(rel));
1202 
1203  MemoryContextSwitchTo(oldcontext);
1204  }
1205 
1206  return relInfo->ri_TrigNewSlot;
1207 }
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:494

References EState::es_query_cxt, ExecInitExtraTupleSlot(), MemoryContextSwitchTo(), RelationGetDescr, ResultRelInfo::ri_RelationDesc, ResultRelInfo::ri_TrigNewSlot, and table_slot_callbacks().

Referenced by AfterTriggerExecute(), and AfterTriggerSaveEvent().

◆ ExecGetTriggerOldSlot()

TupleTableSlot* ExecGetTriggerOldSlot ( EState estate,
ResultRelInfo relInfo 
)

◆ ExecGetUpdatedCols()

Bitmapset* ExecGetUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1319 of file execUtils.c.

1320 {
1321  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1322 
1323  if (perminfo == NULL)
1324  return NULL;
1325 
1326  /* Map the columns to child's attribute numbers if needed. */
1327  if (relinfo->ri_RootResultRelInfo)
1328  {
1329  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1330 
1331  if (map)
1332  return execute_attr_map_cols(map->attrMap, perminfo->updatedCols);
1333  }
1334 
1335  return perminfo->updatedCols;
1336 }
Bitmapset * updatedCols
Definition: parsenodes.h:1250

References TupleConversionMap::attrMap, ExecGetRootToChildMap(), execute_attr_map_cols(), GetResultRTEPermissionInfo(), ResultRelInfo::ri_RootResultRelInfo, and RTEPermissionInfo::updatedCols.

Referenced by ExecConstraints(), ExecGetAllUpdatedCols(), ExecInitStoredGenerated(), ExecPartitionCheckEmitError(), ExecWithCheckOptions(), and index_unchanged_by_update().

◆ ExecInitRangeTable()

void ExecInitRangeTable ( EState estate,
List rangeTable,
List permInfos 
)

Definition at line 759 of file execUtils.c.

760 {
761  /* Remember the range table List as-is */
762  estate->es_range_table = rangeTable;
763 
764  /* ... and the RTEPermissionInfo List too */
765  estate->es_rteperminfos = permInfos;
766 
767  /* Set size of associated arrays */
768  estate->es_range_table_size = list_length(rangeTable);
769 
770  /*
771  * Allocate an array to store an open Relation corresponding to each
772  * rangetable entry, and initialize entries to NULL. Relations are opened
773  * and stored here as needed.
774  */
775  estate->es_relations = (Relation *)
776  palloc0(estate->es_range_table_size * sizeof(Relation));
777 
778  /*
779  * es_result_relations and es_rowmarks are also parallel to
780  * es_range_table, but are allocated only if needed.
781  */
782  estate->es_result_relations = NULL;
783  estate->es_rowmarks = NULL;
784 }
void * palloc0(Size size)
Definition: mcxt.c:1257
static int list_length(const List *l)
Definition: pg_list.h:152

References EState::es_range_table, EState::es_range_table_size, EState::es_relations, EState::es_result_relations, EState::es_rowmarks, EState::es_rteperminfos, list_length(), and palloc0().

Referenced by CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), and InitPlan().

◆ ExecInitResultRelation()

void ExecInitResultRelation ( EState estate,
ResultRelInfo resultRelInfo,
Index  rti 
)

Definition at line 845 of file execUtils.c.

847 {
848  Relation resultRelationDesc;
849 
850  resultRelationDesc = ExecGetRangeTableRelation(estate, rti);
851  InitResultRelInfo(resultRelInfo,
852  resultRelationDesc,
853  rti,
854  NULL,
855  estate->es_instrument);
856 
857  if (estate->es_result_relations == NULL)
858  estate->es_result_relations = (ResultRelInfo **)
859  palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
860  estate->es_result_relations[rti - 1] = resultRelInfo;
861 
862  /*
863  * Saving in the list allows to avoid needlessly traversing the whole
864  * array when only a few of its entries are possibly non-NULL.
865  */
867  lappend(estate->es_opened_result_relations, resultRelInfo);
868 }
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Definition: execMain.c:1216
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:793
List * lappend(List *list, void *datum)
Definition: list.c:338

References EState::es_instrument, EState::es_opened_result_relations, EState::es_range_table_size, EState::es_result_relations, ExecGetRangeTableRelation(), InitResultRelInfo(), lappend(), and palloc0().

Referenced by CopyFrom(), and ExecInitModifyTable().

◆ ExecOpenScanRelation()

Relation ExecOpenScanRelation ( EState estate,
Index  scanrelid,
int  eflags 
)

Definition at line 728 of file execUtils.c.

729 {
730  Relation rel;
731 
732  /* Open the relation. */
733  rel = ExecGetRangeTableRelation(estate, scanrelid);
734 
735  /*
736  * Complain if we're attempting a scan of an unscannable relation, except
737  * when the query won't actually be run. This is a slightly klugy place
738  * to do this, perhaps, but there is no better place.
739  */
740  if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
741  !RelationIsScannable(rel))
742  ereport(ERROR,
743  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
744  errmsg("materialized view \"%s\" has not been populated",
746  errhint("Use the REFRESH MATERIALIZED VIEW command.")));
747 
748  return rel;
749 }
int errhint(const char *fmt,...)
Definition: elog.c:1316
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
#define EXEC_FLAG_WITH_NO_DATA
Definition: executor.h:71
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:65
#define RelationIsScannable(relation)
Definition: rel.h:670
#define RelationGetRelationName(relation)
Definition: rel.h:538

References ereport, errcode(), errhint(), errmsg(), ERROR, EXEC_FLAG_EXPLAIN_ONLY, EXEC_FLAG_WITH_NO_DATA, ExecGetRangeTableRelation(), RelationGetRelationName, and RelationIsScannable.

Referenced by ExecInitBitmapHeapScan(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitTidRangeScan(), ExecInitTidScan(), and postgresBeginDirectModify().

◆ ExecRelationIsTargetRelation()

bool ExecRelationIsTargetRelation ( EState estate,
Index  scanrelid 
)

Definition at line 715 of file execUtils.c.

716 {
717  return list_member_int(estate->es_plannedstmt->resultRelations, scanrelid);
718 }
bool list_member_int(const List *list, int datum)
Definition: list.c:701
List * resultRelations
Definition: plannodes.h:79

References EState::es_plannedstmt, list_member_int(), and PlannedStmt::resultRelations.

◆ ExecTargetListLength()

int ExecTargetListLength ( List targetlist)

Definition at line 1140 of file execUtils.c.

1141 {
1142  /* This used to be more complex, but fjoins are dead */
1143  return list_length(targetlist);
1144 }

References list_length().

Referenced by ExecTypeFromTLInternal().

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 901 of file execUtils.c.

902 {
903  int pos;
904 
905  /* No-op if location was not provided */
906  if (location < 0)
907  return 0;
908  /* Can't do anything if source text is not available */
909  if (estate == NULL || estate->es_sourceText == NULL)
910  return 0;
911  /* Convert offset to character number */
912  pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
913  /* And pass it to the ereport mechanism */
914  return errposition(pos);
915 }
int errposition(int cursorpos)
Definition: elog.c:1445
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1058

References errposition(), EState::es_sourceText, and pg_mbstrlen_with_len().

Referenced by ExecInitFunc(), ExecInitSubscriptingRef(), and init_sexpr().

◆ FreeExecutorState()

void FreeExecutorState ( EState estate)

Definition at line 194 of file execUtils.c.

195 {
196  /*
197  * Shut down and free any remaining ExprContexts. We do this explicitly
198  * to ensure that any remaining shutdown callbacks get called (since they
199  * might need to release resources that aren't simply memory within the
200  * per-query memory context).
201  */
202  while (estate->es_exprcontexts)
203  {
204  /*
205  * XXX: seems there ought to be a faster way to implement this than
206  * repeated list_delete(), no?
207  */
209  true);
210  /* FreeExprContext removed the list link for us */
211  }
212 
213  /* release JIT context, if allocated */
214  if (estate->es_jit)
215  {
216  jit_release_context(estate->es_jit);
217  estate->es_jit = NULL;
218  }
219 
220  /* release partition directory, if allocated */
221  if (estate->es_partition_directory)
222  {
224  estate->es_partition_directory = NULL;
225  }
226 
227  /*
228  * Free the per-query memory context, thereby releasing all working
229  * memory, including the EState node itself.
230  */
232 }
void FreeExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:419
void jit_release_context(JitContext *context)
Definition: jit.c:138
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
void DestroyPartitionDirectory(PartitionDirectory pdir)
Definition: partdesc.c:444
#define linitial(l)
Definition: pg_list.h:178
PartitionDirectory es_partition_directory
Definition: execnodes.h:641

References DestroyPartitionDirectory(), EState::es_exprcontexts, EState::es_jit, EState::es_partition_directory, EState::es_query_cxt, FreeExprContext(), jit_release_context(), linitial, and MemoryContextDelete().

Referenced by afterTriggerInvokeEvents(), ATRewriteTable(), check_default_partition_contents(), compute_expr_stats(), compute_index_stats(), CopyFrom(), EvalPlanQualEnd(), evaluate_expr(), ExecuteCallStmt(), ExecuteQuery(), ExecuteTruncateGuts(), ExplainExecuteQuery(), finish_edata(), freestate_cluster(), get_qual_for_range(), heapam_index_build_range_scan(), heapam_index_validate_scan(), IndexCheckExclusion(), make_build_data(), operator_predicate_proof(), plpgsql_inline_handler(), plpgsql_xact_cb(), standard_ExecutorEnd(), StoreAttrDefault(), and validateDomainConstraint().

◆ FreeExprContext()

void FreeExprContext ( ExprContext econtext,
bool  isCommit 
)

Definition at line 419 of file execUtils.c.

420 {
421  EState *estate;
422 
423  /* Call any registered callbacks */
424  ShutdownExprContext(econtext, isCommit);
425  /* And clean up the memory used */
427  /* Unlink self from owning EState, if any */
428  estate = econtext->ecxt_estate;
429  if (estate)
431  econtext);
432  /* And delete the ExprContext node */
433  pfree(econtext);
434 }
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:985
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:871
void pfree(void *pointer)
Definition: mcxt.c:1456

References ExprContext::ecxt_estate, ExprContext::ecxt_per_tuple_memory, EState::es_exprcontexts, list_delete_ptr(), MemoryContextDelete(), pfree(), and ShutdownExprContext().

Referenced by ExecEndBitmapIndexScan(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), FreeExecutorState(), plpgsql_destroy_econtext(), and plpgsql_subxact_cb().

◆ GetAttributeByName()

Datum GetAttributeByName ( HeapTupleHeader  tuple,
const char *  attname,
bool isNull 
)

Definition at line 1026 of file execUtils.c.

1027 {
1028  AttrNumber attrno;
1029  Datum result;
1030  Oid tupType;
1031  int32 tupTypmod;
1032  TupleDesc tupDesc;
1033  HeapTupleData tmptup;
1034  int i;
1035 
1036  if (attname == NULL)
1037  elog(ERROR, "invalid attribute name");
1038 
1039  if (isNull == NULL)
1040  elog(ERROR, "a NULL isNull pointer was passed");
1041 
1042  if (tuple == NULL)
1043  {
1044  /* Kinda bogus but compatible with old behavior... */
1045  *isNull = true;
1046  return (Datum) 0;
1047  }
1048 
1049  tupType = HeapTupleHeaderGetTypeId(tuple);
1050  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1051  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1052 
1053  attrno = InvalidAttrNumber;
1054  for (i = 0; i < tupDesc->natts; i++)
1055  {
1056  Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1057 
1058  if (namestrcmp(&(att->attname), attname) == 0)
1059  {
1060  attrno = att->attnum;
1061  break;
1062  }
1063  }
1064 
1065  if (attrno == InvalidAttrNumber)
1066  elog(ERROR, "attribute \"%s\" does not exist", attname);
1067 
1068  /*
1069  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1070  * the fields in the struct just in case user tries to inspect system
1071  * columns.
1072  */
1073  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1074  ItemPointerSetInvalid(&(tmptup.t_self));
1075  tmptup.t_tableOid = InvalidOid;
1076  tmptup.t_data = tuple;
1077 
1078  result = heap_getattr(&tmptup,
1079  attrno,
1080  tupDesc,
1081  isNull);
1082 
1083  ReleaseTupleDesc(tupDesc);
1084 
1085  return result;
1086 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
signed int int32
Definition: c.h:478
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:466
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:456
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:450
int i
Definition: isn.c:73
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
int namestrcmp(Name name, const char *str)
Definition: name.c:247
NameData attname
Definition: pg_attribute.h:41
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1824

References attname, elog(), ERROR, heap_getattr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, i, InvalidAttrNumber, InvalidOid, ItemPointerSetInvalid(), lookup_rowtype_tupdesc(), namestrcmp(), TupleDescData::natts, ReleaseTupleDesc, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, and TupleDescAttr.

Referenced by c_overpaid(), and overpaid().

◆ GetAttributeByNum()

Datum GetAttributeByNum ( HeapTupleHeader  tuple,
AttrNumber  attrno,
bool isNull 
)

Definition at line 1089 of file execUtils.c.

1092 {
1093  Datum result;
1094  Oid tupType;
1095  int32 tupTypmod;
1096  TupleDesc tupDesc;
1097  HeapTupleData tmptup;
1098 
1099  if (!AttributeNumberIsValid(attrno))
1100  elog(ERROR, "invalid attribute number %d", attrno);
1101 
1102  if (isNull == NULL)
1103  elog(ERROR, "a NULL isNull pointer was passed");
1104 
1105  if (tuple == NULL)
1106  {
1107  /* Kinda bogus but compatible with old behavior... */
1108  *isNull = true;
1109  return (Datum) 0;
1110  }
1111 
1112  tupType = HeapTupleHeaderGetTypeId(tuple);
1113  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1114  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1115 
1116  /*
1117  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1118  * the fields in the struct just in case user tries to inspect system
1119  * columns.
1120  */
1121  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1122  ItemPointerSetInvalid(&(tmptup.t_self));
1123  tmptup.t_tableOid = InvalidOid;
1124  tmptup.t_data = tuple;
1125 
1126  result = heap_getattr(&tmptup,
1127  attrno,
1128  tupDesc,
1129  isNull);
1130 
1131  ReleaseTupleDesc(tupDesc);
1132 
1133  return result;
1134 }
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34

References AttributeNumberIsValid, elog(), ERROR, heap_getattr(), HeapTupleHeaderGetDatumLength, HeapTupleHeaderGetTypeId, HeapTupleHeaderGetTypMod, InvalidOid, ItemPointerSetInvalid(), lookup_rowtype_tupdesc(), ReleaseTupleDesc, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, and HeapTupleData::t_tableOid.

◆ GetResultRTEPermissionInfo()

static RTEPermissionInfo * GetResultRTEPermissionInfo ( ResultRelInfo relinfo,
EState estate 
)
static

Definition at line 1361 of file execUtils.c.

1362 {
1363  Index rti;
1364  RangeTblEntry *rte;
1365  RTEPermissionInfo *perminfo = NULL;
1366 
1367  if (relinfo->ri_RootResultRelInfo)
1368  {
1369  /*
1370  * For inheritance child result relations (a partition routing target
1371  * of an INSERT or a child UPDATE target), this returns the root
1372  * parent's RTE to fetch the RTEPermissionInfo because that's the only
1373  * one that has one assigned.
1374  */
1375  rti = relinfo->ri_RootResultRelInfo->ri_RangeTableIndex;
1376  }
1377  else if (relinfo->ri_RangeTableIndex != 0)
1378  {
1379  /*
1380  * Non-child result relation should have their own RTEPermissionInfo.
1381  */
1382  rti = relinfo->ri_RangeTableIndex;
1383  }
1384  else
1385  {
1386  /*
1387  * The relation isn't in the range table and it isn't a partition
1388  * routing target. This ResultRelInfo must've been created only for
1389  * firing triggers and the relation is not being inserted into. (See
1390  * ExecGetTriggerResultRel.)
1391  */
1392  rti = 0;
1393  }
1394 
1395  if (rti > 0)
1396  {
1397  rte = exec_rt_fetch(rti, estate);
1398  perminfo = getRTEPermissionInfo(estate->es_rteperminfos, rte);
1399  }
1400 
1401  return perminfo;
1402 }
unsigned int Index
Definition: c.h:598
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
Index ri_RangeTableIndex
Definition: execnodes.h:447

References EState::es_rteperminfos, exec_rt_fetch(), getRTEPermissionInfo(), ResultRelInfo::ri_RangeTableIndex, and ResultRelInfo::ri_RootResultRelInfo.

Referenced by ExecGetInsertedCols(), ExecGetResultRelCheckAsUser(), and ExecGetUpdatedCols().

◆ MakePerTupleExprContext()

ExprContext* MakePerTupleExprContext ( EState estate)

Definition at line 461 of file execUtils.c.

462 {
463  if (estate->es_per_tuple_exprcontext == NULL)
465 
466  return estate->es_per_tuple_exprcontext;
467 }

References CreateExprContext(), and EState::es_per_tuple_exprcontext.

◆ RegisterExprContextCallback()

void RegisterExprContextCallback ( ExprContext econtext,
ExprContextCallbackFunction  function,
Datum  arg 
)

Definition at line 928 of file execUtils.c.

931 {
932  ExprContext_CB *ecxt_callback;
933 
934  /* Save the info in appropriate memory context */
935  ecxt_callback = (ExprContext_CB *)
937  sizeof(ExprContext_CB));
938 
939  ecxt_callback->function = function;
940  ecxt_callback->arg = arg;
941 
942  /* link to front of list for appropriate execution order */
943  ecxt_callback->next = econtext->ecxt_callbacks;
944  econtext->ecxt_callbacks = ecxt_callback;
945 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
void * arg
struct ExprContext_CB * next
Definition: execnodes.h:215
ExprContextCallbackFunction function
Definition: execnodes.h:216

References arg, ExprContext_CB::arg, ExprContext::ecxt_callbacks, ExprContext::ecxt_per_query_memory, ExprContext_CB::function, MemoryContextAlloc(), and ExprContext_CB::next.

Referenced by AggRegisterCallback(), ExecMakeFunctionResultSet(), ExecPrepareTuplestoreResult(), fmgr_sql(), and init_MultiFuncCall().

◆ ReScanExprContext()

void ReScanExprContext ( ExprContext econtext)

Definition at line 446 of file execUtils.c.

447 {
448  /* Call any registered callbacks */
449  ShutdownExprContext(econtext, true);
450  /* And clean up the memory used */
452 }
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:330

References ExprContext::ecxt_per_tuple_memory, MemoryContextReset(), and ShutdownExprContext().

Referenced by agg_refill_hash_table(), agg_retrieve_direct(), domain_check_input(), ExecEndAgg(), ExecReScan(), ExecReScanAgg(), and ValuesNext().

◆ ShutdownExprContext()

static void ShutdownExprContext ( ExprContext econtext,
bool  isCommit 
)
static

Definition at line 985 of file execUtils.c.

986 {
987  ExprContext_CB *ecxt_callback;
988  MemoryContext oldcontext;
989 
990  /* Fast path in normal case where there's nothing to do. */
991  if (econtext->ecxt_callbacks == NULL)
992  return;
993 
994  /*
995  * Call the callbacks in econtext's per-tuple context. This ensures that
996  * any memory they might leak will get cleaned up.
997  */
998  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
999 
1000  /*
1001  * Call each callback function in reverse registration order.
1002  */
1003  while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
1004  {
1005  econtext->ecxt_callbacks = ecxt_callback->next;
1006  if (isCommit)
1007  ecxt_callback->function(ecxt_callback->arg);
1008  pfree(ecxt_callback);
1009  }
1010 
1011  MemoryContextSwitchTo(oldcontext);
1012 }

References ExprContext_CB::arg, ExprContext::ecxt_callbacks, ExprContext::ecxt_per_tuple_memory, ExprContext_CB::function, MemoryContextSwitchTo(), ExprContext_CB::next, and pfree().

Referenced by FreeExprContext(), and ReScanExprContext().

◆ tlist_matches_tupdesc()

static bool tlist_matches_tupdesc ( PlanState ps,
List tlist,
int  varno,
TupleDesc  tupdesc 
)
static

Definition at line 590 of file execUtils.c.

591 {
592  int numattrs = tupdesc->natts;
593  int attrno;
594  ListCell *tlist_item = list_head(tlist);
595 
596  /* Check the tlist attributes */
597  for (attrno = 1; attrno <= numattrs; attrno++)
598  {
599  Form_pg_attribute att_tup = TupleDescAttr(tupdesc, attrno - 1);
600  Var *var;
601 
602  if (tlist_item == NULL)
603  return false; /* tlist too short */
604  var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr;
605  if (!var || !IsA(var, Var))
606  return false; /* tlist item not a Var */
607  /* if these Asserts fail, planner messed up */
608  Assert(var->varno == varno);
609  Assert(var->varlevelsup == 0);
610  if (var->varattno != attrno)
611  return false; /* out of order */
612  if (att_tup->attisdropped)
613  return false; /* table contains dropped columns */
614  if (att_tup->atthasmissing)
615  return false; /* table contains cols with missing values */
616 
617  /*
618  * Note: usually the Var's type should match the tupdesc exactly, but
619  * in situations involving unions of columns that have different
620  * typmods, the Var may have come from above the union and hence have
621  * typmod -1. This is a legitimate situation since the Var still
622  * describes the column, just not as exactly as the tupdesc does. We
623  * could change the planner to prevent it, but it'd then insert
624  * projection steps just to convert from specific typmod to typmod -1,
625  * which is pretty silly.
626  */
627  if (var->vartype != att_tup->atttypid ||
628  (var->vartypmod != att_tup->atttypmod &&
629  var->vartypmod != -1))
630  return false; /* type mismatch */
631 
632  tlist_item = lnext(tlist, tlist_item);
633  }
634 
635  if (tlist_item)
636  return false; /* tlist too long */
637 
638  return true;
639 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
#define lfirst(lc)
Definition: pg_list.h:172
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
Definition: primnodes.h:226
AttrNumber varattno
Definition: primnodes.h:238
int varno
Definition: primnodes.h:233
Index varlevelsup
Definition: primnodes.h:258

References Assert(), IsA, lfirst, list_head(), lnext(), TupleDescData::natts, TupleDescAttr, Var::varattno, Var::varlevelsup, and Var::varno.

Referenced by ExecConditionalAssignProjectionInfo().

◆ UnregisterExprContextCallback()

void UnregisterExprContextCallback ( ExprContext econtext,
ExprContextCallbackFunction  function,
Datum  arg 
)

Definition at line 954 of file execUtils.c.

957 {
958  ExprContext_CB **prev_callback;
959  ExprContext_CB *ecxt_callback;
960 
961  prev_callback = &econtext->ecxt_callbacks;
962 
963  while ((ecxt_callback = *prev_callback) != NULL)
964  {
965  if (ecxt_callback->function == function && ecxt_callback->arg == arg)
966  {
967  *prev_callback = ecxt_callback->next;
968  pfree(ecxt_callback);
969  }
970  else
971  prev_callback = &ecxt_callback->next;
972  }
973 }

References arg, ExprContext_CB::arg, ExprContext::ecxt_callbacks, ExprContext_CB::function, ExprContext_CB::next, and pfree().

Referenced by end_MultiFuncCall(), and fmgr_sql().

◆ UpdateChangedParamSet()

void UpdateChangedParamSet ( PlanState node,
Bitmapset newchg 
)

Definition at line 875 of file execUtils.c.

876 {
877  Bitmapset *parmset;
878 
879  /*
880  * The plan node only depends on params listed in its allParam set. Don't
881  * include anything else into its chgParam set.
882  */
883  parmset = bms_intersect(node->plan->allParam, newchg);
884  node->chgParam = bms_join(node->chgParam, parmset);
885 }
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:987
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:260
Bitmapset * chgParam
Definition: execnodes.h:1069
Bitmapset * allParam
Definition: plannodes.h:172

References Plan::allParam, bms_intersect(), bms_join(), PlanState::chgParam, and PlanState::plan.

Referenced by ExecReScan(), ExecReScanAppend(), ExecReScanBitmapAnd(), ExecReScanBitmapOr(), ExecReScanMergeAppend(), and ExecReScanSubqueryScan().