PostgreSQL Source Code  git master
execUtils.c File Reference
#include "postgres.h"
#include "access/parallel.h"
#include "access/table.h"
#include "access/tableam.h"
#include "executor/executor.h"
#include "executor/nodeModifyTable.h"
#include "jit/jit.h"
#include "mb/pg_wchar.h"
#include "miscadmin.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 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 88 of file execUtils.c.

89 {
90  EState *estate;
91  MemoryContext qcontext;
92  MemoryContext oldcontext;
93 
94  /*
95  * Create the per-query context for this Executor run.
96  */
98  "ExecutorState",
100 
101  /*
102  * Make the EState node within the per-query context. This way, we don't
103  * need a separate pfree() operation for it at shutdown.
104  */
105  oldcontext = MemoryContextSwitchTo(qcontext);
106 
107  estate = makeNode(EState);
108 
109  /*
110  * Initialize all fields of the Executor State structure
111  */
113  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
114  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
115  estate->es_range_table = NIL;
116  estate->es_range_table_size = 0;
117  estate->es_relations = NULL;
118  estate->es_rowmarks = NULL;
119  estate->es_rteperminfos = NIL;
120  estate->es_plannedstmt = NULL;
121 
122  estate->es_junkFilter = NULL;
123 
124  estate->es_output_cid = (CommandId) 0;
125 
126  estate->es_result_relations = NULL;
129  estate->es_trig_target_relations = NIL;
130 
133 
134  estate->es_param_list_info = NULL;
135  estate->es_param_exec_vals = NULL;
136 
137  estate->es_queryEnv = NULL;
138 
139  estate->es_query_cxt = qcontext;
140 
141  estate->es_tupleTable = NIL;
142 
143  estate->es_processed = 0;
144  estate->es_total_processed = 0;
145 
146  estate->es_top_eflags = 0;
147  estate->es_instrument = 0;
148  estate->es_finished = false;
149 
150  estate->es_exprcontexts = NIL;
151 
152  estate->es_subplanstates = NIL;
153 
154  estate->es_auxmodifytables = NIL;
155 
156  estate->es_per_tuple_exprcontext = NULL;
157 
158  estate->es_sourceText = NULL;
159 
160  estate->es_use_parallel_mode = false;
161  estate->es_parallel_workers_to_launch = 0;
162  estate->es_parallel_workers_launched = 0;
163 
164  estate->es_jit_flags = 0;
165  estate->es_jit = NULL;
166 
167  /*
168  * Return the executor state structure
169  */
170  MemoryContextSwitchTo(oldcontext);
171 
172  return estate;
173 }
uint32 CommandId
Definition: c.h:657
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define makeNode(_type_)
Definition: nodes.h:155
#define NIL
Definition: pg_list.h:68
MemoryContextSwitchTo(old_ctx)
@ ForwardScanDirection
Definition: sdir.h:28
#define InvalidSnapshot
Definition: snapshot.h:123
uint64 es_processed
Definition: execnodes.h:679
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:638
int es_parallel_workers_to_launch
Definition: execnodes.h:711
List * es_tuple_routing_result_relations
Definition: execnodes.h:663
int es_top_eflags
Definition: execnodes.h:684
struct JitContext * es_jit
Definition: execnodes.h:729
int es_instrument
Definition: execnodes.h:685
PlannedStmt * es_plannedstmt
Definition: execnodes.h:641
QueryEnvironment * es_queryEnv
Definition: execnodes.h:672
ResultRelInfo ** es_result_relations
Definition: execnodes.h:650
ParamExecData * es_param_exec_vals
Definition: execnodes.h:670
uint64 es_total_processed
Definition: execnodes.h:681
List * es_range_table
Definition: execnodes.h:634
List * es_rteperminfos
Definition: execnodes.h:640
List * es_exprcontexts
Definition: execnodes.h:688
ParamListInfo es_param_list_info
Definition: execnodes.h:669
bool es_finished
Definition: execnodes.h:686
List * es_insert_pending_result_relations
Definition: execnodes.h:736
MemoryContext es_query_cxt
Definition: execnodes.h:675
List * es_tupleTable
Definition: execnodes.h:677
ScanDirection es_direction
Definition: execnodes.h:631
List * es_trig_target_relations
Definition: execnodes.h:666
int es_jit_flags
Definition: execnodes.h:728
List * es_opened_result_relations
Definition: execnodes.h:653
bool es_use_parallel_mode
Definition: execnodes.h:709
Relation * es_relations
Definition: execnodes.h:636
List * es_subplanstates
Definition: execnodes.h:690
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:699
int es_parallel_workers_launched
Definition: execnodes.h:713
CommandId es_output_cid
Definition: execnodes.h:647
Index es_range_table_size
Definition: execnodes.h:635
List * es_insert_pending_modifytables
Definition: execnodes.h:737
const char * es_sourceText
Definition: execnodes.h:642
Snapshot es_snapshot
Definition: execnodes.h:632
List * es_auxmodifytables
Definition: execnodes.h:692
JunkFilter * es_junkFilter
Definition: execnodes.h:644
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:633

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_parallel_workers_launched, EState::es_parallel_workers_to_launch, 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 validateDomainCheckConstraint().

◆ CreateExprContext()

ExprContext* CreateExprContext ( EState estate)

Definition at line 306 of file execUtils.c.

307 {
309 }
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:236

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 236 of file execUtils.c.

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

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 357 of file execUtils.c.

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

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 321 of file execUtils.c.

322 {
323  Size minContextSize = ALLOCSET_DEFAULT_MINSIZE;
324  Size initBlockSize = ALLOCSET_DEFAULT_INITSIZE;
325  Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
326 
327  /* choose the maxBlockSize to be no larger than 1/16 of work_mem */
328  while (16 * maxBlockSize > work_mem * 1024L)
329  maxBlockSize >>= 1;
330 
331  if (maxBlockSize < ALLOCSET_DEFAULT_INITSIZE)
332  maxBlockSize = ALLOCSET_DEFAULT_INITSIZE;
333 
334  return CreateExprContextInternal(estate, minContextSize,
335  initBlockSize, maxBlockSize);
336 }
size_t Size
Definition: c.h:596
int work_mem
Definition: globals.c:130
#define ALLOCSET_DEFAULT_MAXSIZE
Definition: memutils.h:159
#define ALLOCSET_DEFAULT_MINSIZE
Definition: memutils.h:157
#define ALLOCSET_DEFAULT_INITSIZE
Definition: memutils.h:158

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 540 of file execUtils.c.

542 {
543  planstate->ps_ProjInfo =
545  planstate->ps_ExprContext,
546  planstate->ps_ResultTupleSlot,
547  planstate,
548  inputDesc);
549 }
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:365
Plan * plan
Definition: execnodes.h:1128
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1166
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1168
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 649 of file execUtils.c.

650 {
651  TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
652 
653  ExecSetSlotDescriptor(slot, tupDesc);
654 }
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1376
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1578

References ExecSetSlotDescriptor(), and ScanState::ss_ScanTupleSlot.

Referenced by ExecWorkTableScan().

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1121 of file execUtils.c.

1122 {
1123  int len = 0;
1124  ListCell *tl;
1125 
1126  foreach(tl, targetlist)
1127  {
1128  TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1129 
1130  if (!curTle->resjunk)
1131  len++;
1132  }
1133  return len;
1134 }
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 560 of file execUtils.c.

562 {
563  if (tlist_matches_tupdesc(planstate,
564  planstate->plan->targetlist,
565  varno,
566  inputDesc))
567  {
568  planstate->ps_ProjInfo = NULL;
569  planstate->resultopsset = planstate->scanopsset;
570  planstate->resultopsfixed = planstate->scanopsfixed;
571  planstate->resultops = planstate->scanops;
572  }
573  else
574  {
575  if (!planstate->ps_ResultTupleSlot)
576  {
577  ExecInitResultSlot(planstate, &TTSOpsVirtual);
578  planstate->resultops = &TTSOpsVirtual;
579  planstate->resultopsfixed = true;
580  planstate->resultopsset = true;
581  }
582  ExecAssignProjectionInfo(planstate, inputDesc);
583  }
584 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1866
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
Definition: execUtils.c:587
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:540
const TupleTableSlotOps * resultops
Definition: execnodes.h:1205
bool resultopsset
Definition: execnodes.h:1213
const TupleTableSlotOps * scanops
Definition: execnodes.h:1202
bool scanopsset
Definition: execnodes.h:1210
bool scanopsfixed
Definition: execnodes.h:1206
bool resultopsfixed
Definition: execnodes.h:1209

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 661 of file execUtils.c.

664 {
666  TupleDesc tupDesc;
667 
668  outerPlan = outerPlanState(scanstate);
669  tupDesc = ExecGetResultType(outerPlan);
670 
671  ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
672 }
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1898
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:495
#define outerPlanState(node)
Definition: execnodes.h:1224
#define outerPlan(node)
Definition: plannodes.h:183

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

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

◆ ExecGetAllUpdatedCols()

Bitmapset* ExecGetAllUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1326 of file execUtils.c.

1327 {
1328  Bitmapset *ret;
1329  MemoryContext oldcxt;
1330 
1332 
1333  ret = bms_union(ExecGetUpdatedCols(relinfo, estate),
1334  ExecGetExtraUpdatedCols(relinfo, estate));
1335 
1336  MemoryContextSwitchTo(oldcxt);
1337 
1338  return ret;
1339 }
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:251
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1290
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1311
#define GetPerTupleMemoryContext(estate)
Definition: executor.h:566

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

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

◆ ExecGetChildToRootMap()

TupleConversionMap* ExecGetChildToRootMap ( ResultRelInfo resultRelInfo)

Definition at line 1208 of file execUtils.c.

1209 {
1210  /* If we didn't already do so, compute the map for this child. */
1211  if (!resultRelInfo->ri_ChildToRootMapValid)
1212  {
1213  ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1214 
1215  if (rootRelInfo)
1216  resultRelInfo->ri_ChildToRootMap =
1218  RelationGetDescr(rootRelInfo->ri_RelationDesc));
1219  else /* this isn't a child result rel */
1220  resultRelInfo->ri_ChildToRootMap = NULL;
1221 
1222  resultRelInfo->ri_ChildToRootMapValid = true;
1223  }
1224 
1225  return resultRelInfo->ri_ChildToRootMap;
1226 }
#define RelationGetDescr(relation)
Definition: rel.h:531
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:590
Relation ri_RelationDesc
Definition: execnodes.h:459
TupleConversionMap * ri_ChildToRootMap
Definition: execnodes.h:570
bool ri_ChildToRootMapValid
Definition: execnodes.h:571
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 1311 of file execUtils.c.

1312 {
1313  /* Compute the info if we didn't already */
1314  if (relinfo->ri_GeneratedExprsU == NULL)
1315  ExecInitStoredGenerated(relinfo, estate, CMD_UPDATE);
1316  return relinfo->ri_extraUpdatedCols;
1317 }
void ExecInitStoredGenerated(ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
@ CMD_UPDATE
Definition: nodes.h:266
Bitmapset * ri_extraUpdatedCols
Definition: execnodes.h:477
ExprState ** ri_GeneratedExprsU
Definition: execnodes.h:537

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 1269 of file execUtils.c.

1270 {
1271  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1272 
1273  if (perminfo == NULL)
1274  return NULL;
1275 
1276  /* Map the columns to child's attribute numbers if needed. */
1277  if (relinfo->ri_RootResultRelInfo)
1278  {
1279  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1280 
1281  if (map)
1282  return execute_attr_map_cols(map->attrMap, perminfo->insertedCols);
1283  }
1284 
1285  return perminfo->insertedCols;
1286 }
static RTEPermissionInfo * GetResultRTEPermissionInfo(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1346
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition: execUtils.c:1234
Bitmapset * insertedCols
Definition: parsenodes.h:1294
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 build_tuple_value_details(), ExecConstraints(), ExecPartitionCheckEmitError(), and ExecWithCheckOptions().

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti 
)

Definition at line 764 of file execUtils.c.

765 {
766  Relation rel;
767 
768  Assert(rti > 0 && rti <= estate->es_range_table_size);
769 
770  rel = estate->es_relations[rti - 1];
771  if (rel == NULL)
772  {
773  /* First time through, so open the relation */
774  RangeTblEntry *rte = exec_rt_fetch(rti, estate);
775 
776  Assert(rte->rtekind == RTE_RELATION);
777 
778  if (!IsParallelWorker())
779  {
780  /*
781  * In a normal query, we should already have the appropriate lock,
782  * but verify that through an Assert. Since there's already an
783  * Assert inside table_open that insists on holding some lock, it
784  * seems sufficient to check this only when rellockmode is higher
785  * than the minimum.
786  */
787  rel = table_open(rte->relid, NoLock);
788  Assert(rte->rellockmode == AccessShareLock ||
789  CheckRelationLockedByMe(rel, rte->rellockmode, false));
790  }
791  else
792  {
793  /*
794  * If we are a parallel worker, we need to obtain our own local
795  * lock on the relation. This ensures sane behavior in case the
796  * parent process exits before we do.
797  */
798  rel = table_open(rte->relid, rte->rellockmode);
799  }
800 
801  estate->es_relations[rti - 1] = rel;
802  }
803 
804  return rel;
805 }
#define Assert(condition)
Definition: c.h:849
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:598
#define IsParallelWorker()
Definition: parallel.h:60
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:330
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
@ RTE_RELATION
Definition: parsenodes.h:1017
RTEKind rtekind
Definition: parsenodes.h:1047
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, RTE_RELATION, RangeTblEntry::rtekind, and table_open().

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

◆ ExecGetResultRelCheckAsUser()

Oid ExecGetResultRelCheckAsUser ( ResultRelInfo relInfo,
EState estate 
)

Definition at line 1397 of file execUtils.c.

1398 {
1399  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relInfo, estate);
1400 
1401  /* XXX - maybe ok to return GetUserId() in this case? */
1402  if (perminfo == NULL)
1403  elog(ERROR, "no RTEPermissionInfo found for result relation with OID %u",
1404  RelationGetRelid(relInfo->ri_RelationDesc));
1405 
1406  return perminfo->checkAsUser ? perminfo->checkAsUser : GetUserId();
1407 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
Oid GetUserId(void)
Definition: miscinit.c:514
#define RelationGetRelid(relation)
Definition: rel.h:505

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 504 of file execUtils.c.

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

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 1184 of file execUtils.c.

1185 {
1186  if (relInfo->ri_ReturningSlot == NULL)
1187  {
1188  Relation rel = relInfo->ri_RelationDesc;
1189  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1190 
1191  relInfo->ri_ReturningSlot =
1192  ExecInitExtraTupleSlot(estate,
1193  RelationGetDescr(rel),
1194  table_slot_callbacks(rel));
1195 
1196  MemoryContextSwitchTo(oldcontext);
1197  }
1198 
1199  return relInfo->ri_ReturningSlot;
1200 }
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1918
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:504
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 1234 of file execUtils.c.

1235 {
1236  /* Mustn't get called for a non-child result relation. */
1237  Assert(resultRelInfo->ri_RootResultRelInfo);
1238 
1239  /* If we didn't already do so, compute the map for this child. */
1240  if (!resultRelInfo->ri_RootToChildMapValid)
1241  {
1242  ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1243  TupleDesc indesc = RelationGetDescr(rootRelInfo->ri_RelationDesc);
1244  TupleDesc outdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
1245  Relation childrel = resultRelInfo->ri_RelationDesc;
1246  AttrMap *attrMap;
1247  MemoryContext oldcontext;
1248 
1249  /*
1250  * When this child table is not a partition (!relispartition), it may
1251  * have columns that are not present in the root table, which we ask
1252  * to ignore by passing true for missing_ok.
1253  */
1254  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1255  attrMap = build_attrmap_by_name_if_req(indesc, outdesc,
1256  !childrel->rd_rel->relispartition);
1257  if (attrMap)
1258  resultRelInfo->ri_RootToChildMap =
1259  convert_tuples_by_name_attrmap(indesc, outdesc, attrMap);
1260  MemoryContextSwitchTo(oldcontext);
1261  resultRelInfo->ri_RootToChildMapValid = true;
1262  }
1263 
1264  return resultRelInfo->ri_RootToChildMap;
1265 }
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
Definition: attmap.c:263
Definition: attmap.h:35
Form_pg_class rd_rel
Definition: rel.h:111
TupleConversionMap * ri_RootToChildMap
Definition: execnodes.h:576
bool ri_RootToChildMapValid
Definition: execnodes.h:577
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 1162 of file execUtils.c.

1163 {
1164  if (relInfo->ri_TrigNewSlot == NULL)
1165  {
1166  Relation rel = relInfo->ri_RelationDesc;
1167  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1168 
1169  relInfo->ri_TrigNewSlot =
1170  ExecInitExtraTupleSlot(estate,
1171  RelationGetDescr(rel),
1172  table_slot_callbacks(rel));
1173 
1174  MemoryContextSwitchTo(oldcontext);
1175  }
1176 
1177  return relInfo->ri_TrigNewSlot;
1178 }
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:506

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 1290 of file execUtils.c.

1291 {
1292  RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1293 
1294  if (perminfo == NULL)
1295  return NULL;
1296 
1297  /* Map the columns to child's attribute numbers if needed. */
1298  if (relinfo->ri_RootResultRelInfo)
1299  {
1300  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1301 
1302  if (map)
1303  return execute_attr_map_cols(map->attrMap, perminfo->updatedCols);
1304  }
1305 
1306  return perminfo->updatedCols;
1307 }
Bitmapset * updatedCols
Definition: parsenodes.h:1295

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

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

◆ ExecInitRangeTable()

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

Definition at line 730 of file execUtils.c.

731 {
732  /* Remember the range table List as-is */
733  estate->es_range_table = rangeTable;
734 
735  /* ... and the RTEPermissionInfo List too */
736  estate->es_rteperminfos = permInfos;
737 
738  /* Set size of associated arrays */
739  estate->es_range_table_size = list_length(rangeTable);
740 
741  /*
742  * Allocate an array to store an open Relation corresponding to each
743  * rangetable entry, and initialize entries to NULL. Relations are opened
744  * and stored here as needed.
745  */
746  estate->es_relations = (Relation *)
747  palloc0(estate->es_range_table_size * sizeof(Relation));
748 
749  /*
750  * es_result_relations and es_rowmarks are also parallel to
751  * es_range_table, but are allocated only if needed.
752  */
753  estate->es_result_relations = NULL;
754  estate->es_rowmarks = NULL;
755 }
void * palloc0(Size size)
Definition: mcxt.c:1347
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 816 of file execUtils.c.

818 {
819  Relation resultRelationDesc;
820 
821  resultRelationDesc = ExecGetRangeTableRelation(estate, rti);
822  InitResultRelInfo(resultRelInfo,
823  resultRelationDesc,
824  rti,
825  NULL,
826  estate->es_instrument);
827 
828  if (estate->es_result_relations == NULL)
829  estate->es_result_relations = (ResultRelInfo **)
830  palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
831  estate->es_result_relations[rti - 1] = resultRelInfo;
832 
833  /*
834  * Saving in the list allows to avoid needlessly traversing the whole
835  * array when only a few of its entries are possibly non-NULL.
836  */
838  lappend(estate->es_opened_result_relations, resultRelInfo);
839 }
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Definition: execMain.c:1201
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:764
List * lappend(List *list, void *datum)
Definition: list.c:339

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 699 of file execUtils.c.

700 {
701  Relation rel;
702 
703  /* Open the relation. */
704  rel = ExecGetRangeTableRelation(estate, scanrelid);
705 
706  /*
707  * Complain if we're attempting a scan of an unscannable relation, except
708  * when the query won't actually be run. This is a slightly klugy place
709  * to do this, perhaps, but there is no better place.
710  */
711  if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
712  !RelationIsScannable(rel))
713  ereport(ERROR,
714  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
715  errmsg("materialized view \"%s\" has not been populated",
717  errhint("Use the REFRESH MATERIALIZED VIEW command.")));
718 
719  return rel;
720 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#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:669
#define RelationGetRelationName(relation)
Definition: rel.h:539

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 686 of file execUtils.c.

687 {
688  return list_member_int(estate->es_plannedstmt->resultRelations, scanrelid);
689 }
bool list_member_int(const List *list, int datum)
Definition: list.c:702
List * resultRelations
Definition: plannodes.h:78

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

◆ ExecTargetListLength()

int ExecTargetListLength ( List targetlist)

Definition at line 1111 of file execUtils.c.

1112 {
1113  /* This used to be more complex, but fjoins are dead */
1114  return list_length(targetlist);
1115 }

References list_length().

Referenced by ExecTypeFromTLInternal().

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 872 of file execUtils.c.

873 {
874  int pos;
875 
876  /* No-op if location was not provided */
877  if (location < 0)
878  return 0;
879  /* Can't do anything if source text is not available */
880  if (estate == NULL || estate->es_sourceText == NULL)
881  return 0;
882  /* Convert offset to character number */
883  pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
884  /* And pass it to the ereport mechanism */
885  return errposition(pos);
886 }
int errposition(int cursorpos)
Definition: elog.c:1446
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1057

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 191 of file execUtils.c.

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

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 validateDomainCheckConstraint().

◆ FreeExprContext()

void FreeExprContext ( ExprContext econtext,
bool  isCommit 
)

Definition at line 416 of file execUtils.c.

417 {
418  EState *estate;
419 
420  /* Call any registered callbacks */
421  ShutdownExprContext(econtext, isCommit);
422  /* And clean up the memory used */
424  /* Unlink self from owning EState, if any */
425  estate = econtext->ecxt_estate;
426  if (estate)
428  econtext);
429  /* And delete the ExprContext node */
430  pfree(econtext);
431 }
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:956
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:872
void pfree(void *pointer)
Definition: mcxt.c:1521

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

Referenced by FreeExecutorState(), plpgsql_destroy_econtext(), and plpgsql_subxact_cb().

◆ GetAttributeByName()

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

Definition at line 997 of file execUtils.c.

998 {
999  AttrNumber attrno;
1000  Datum result;
1001  Oid tupType;
1002  int32 tupTypmod;
1003  TupleDesc tupDesc;
1004  HeapTupleData tmptup;
1005  int i;
1006 
1007  if (attname == NULL)
1008  elog(ERROR, "invalid attribute name");
1009 
1010  if (isNull == NULL)
1011  elog(ERROR, "a NULL isNull pointer was passed");
1012 
1013  if (tuple == NULL)
1014  {
1015  /* Kinda bogus but compatible with old behavior... */
1016  *isNull = true;
1017  return (Datum) 0;
1018  }
1019 
1020  tupType = HeapTupleHeaderGetTypeId(tuple);
1021  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1022  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1023 
1024  attrno = InvalidAttrNumber;
1025  for (i = 0; i < tupDesc->natts; i++)
1026  {
1027  Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1028 
1029  if (namestrcmp(&(att->attname), attname) == 0)
1030  {
1031  attrno = att->attnum;
1032  break;
1033  }
1034  }
1035 
1036  if (attrno == InvalidAttrNumber)
1037  elog(ERROR, "attribute \"%s\" does not exist", attname);
1038 
1039  /*
1040  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1041  * the fields in the struct just in case user tries to inspect system
1042  * columns.
1043  */
1044  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1045  ItemPointerSetInvalid(&(tmptup.t_self));
1046  tmptup.t_tableOid = InvalidOid;
1047  tmptup.t_data = tuple;
1048 
1049  result = heap_getattr(&tmptup,
1050  attrno,
1051  tupDesc,
1052  isNull);
1053 
1054  ReleaseTupleDesc(tupDesc);
1055 
1056  return result;
1057 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
signed int int32
Definition: c.h:496
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:1850

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 1060 of file execUtils.c.

1063 {
1064  Datum result;
1065  Oid tupType;
1066  int32 tupTypmod;
1067  TupleDesc tupDesc;
1068  HeapTupleData tmptup;
1069 
1070  if (!AttributeNumberIsValid(attrno))
1071  elog(ERROR, "invalid attribute number %d", attrno);
1072 
1073  if (isNull == NULL)
1074  elog(ERROR, "a NULL isNull pointer was passed");
1075 
1076  if (tuple == NULL)
1077  {
1078  /* Kinda bogus but compatible with old behavior... */
1079  *isNull = true;
1080  return (Datum) 0;
1081  }
1082 
1083  tupType = HeapTupleHeaderGetTypeId(tuple);
1084  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1085  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1086 
1087  /*
1088  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1089  * the fields in the struct just in case user tries to inspect system
1090  * columns.
1091  */
1092  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1093  ItemPointerSetInvalid(&(tmptup.t_self));
1094  tmptup.t_tableOid = InvalidOid;
1095  tmptup.t_data = tuple;
1096 
1097  result = heap_getattr(&tmptup,
1098  attrno,
1099  tupDesc,
1100  isNull);
1101 
1102  ReleaseTupleDesc(tupDesc);
1103 
1104  return result;
1105 }
#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 1346 of file execUtils.c.

1347 {
1348  Index rti;
1349  RangeTblEntry *rte;
1350  RTEPermissionInfo *perminfo = NULL;
1351 
1352  if (relinfo->ri_RootResultRelInfo)
1353  {
1354  /*
1355  * For inheritance child result relations (a partition routing target
1356  * of an INSERT or a child UPDATE target), this returns the root
1357  * parent's RTE to fetch the RTEPermissionInfo because that's the only
1358  * one that has one assigned.
1359  */
1360  rti = relinfo->ri_RootResultRelInfo->ri_RangeTableIndex;
1361  }
1362  else if (relinfo->ri_RangeTableIndex != 0)
1363  {
1364  /*
1365  * Non-child result relation should have their own RTEPermissionInfo.
1366  */
1367  rti = relinfo->ri_RangeTableIndex;
1368  }
1369  else
1370  {
1371  /*
1372  * The relation isn't in the range table and it isn't a partition
1373  * routing target. This ResultRelInfo must've been created only for
1374  * firing triggers and the relation is not being inserted into. (See
1375  * ExecGetTriggerResultRel.)
1376  */
1377  rti = 0;
1378  }
1379 
1380  if (rti > 0)
1381  {
1382  rte = exec_rt_fetch(rti, estate);
1383  perminfo = getRTEPermissionInfo(estate->es_rteperminfos, rte);
1384  }
1385 
1386  return perminfo;
1387 }
unsigned int Index
Definition: c.h:605
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
Index ri_RangeTableIndex
Definition: execnodes.h:456

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 458 of file execUtils.c.

459 {
460  if (estate->es_per_tuple_exprcontext == NULL)
462 
463  return estate->es_per_tuple_exprcontext;
464 }

References CreateExprContext(), and EState::es_per_tuple_exprcontext.

◆ RegisterExprContextCallback()

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

Definition at line 899 of file execUtils.c.

902 {
903  ExprContext_CB *ecxt_callback;
904 
905  /* Save the info in appropriate memory context */
906  ecxt_callback = (ExprContext_CB *)
908  sizeof(ExprContext_CB));
909 
910  ecxt_callback->function = function;
911  ecxt_callback->arg = arg;
912 
913  /* link to front of list for appropriate execution order */
914  ecxt_callback->next = econtext->ecxt_callbacks;
915  econtext->ecxt_callbacks = ecxt_callback;
916 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void * arg
struct ExprContext_CB * next
Definition: execnodes.h:224
ExprContextCallbackFunction function
Definition: execnodes.h:225

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 443 of file execUtils.c.

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

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 956 of file execUtils.c.

957 {
958  ExprContext_CB *ecxt_callback;
959  MemoryContext oldcontext;
960 
961  /* Fast path in normal case where there's nothing to do. */
962  if (econtext->ecxt_callbacks == NULL)
963  return;
964 
965  /*
966  * Call the callbacks in econtext's per-tuple context. This ensures that
967  * any memory they might leak will get cleaned up.
968  */
969  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
970 
971  /*
972  * Call each callback function in reverse registration order.
973  */
974  while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
975  {
976  econtext->ecxt_callbacks = ecxt_callback->next;
977  if (isCommit)
978  ecxt_callback->function(ecxt_callback->arg);
979  pfree(ecxt_callback);
980  }
981 
982  MemoryContextSwitchTo(oldcontext);
983 }

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 587 of file execUtils.c.

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

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 925 of file execUtils.c.

928 {
929  ExprContext_CB **prev_callback;
930  ExprContext_CB *ecxt_callback;
931 
932  prev_callback = &econtext->ecxt_callbacks;
933 
934  while ((ecxt_callback = *prev_callback) != NULL)
935  {
936  if (ecxt_callback->function == function && ecxt_callback->arg == arg)
937  {
938  *prev_callback = ecxt_callback->next;
939  pfree(ecxt_callback);
940  }
941  else
942  prev_callback = &ecxt_callback->next;
943  }
944 }

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 846 of file execUtils.c.

847 {
848  Bitmapset *parmset;
849 
850  /*
851  * The plan node only depends on params listed in its allParam set. Don't
852  * include anything else into its chgParam set.
853  */
854  parmset = bms_intersect(node->plan->allParam, newchg);
855  node->chgParam = bms_join(node->chgParam, parmset);
856 }
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:1230
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:292
Bitmapset * chgParam
Definition: execnodes.h:1160
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().