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 "jit/jit.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parsetree.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)
 
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)
 
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)
 

Function Documentation

◆ CreateExecutorState()

EState* CreateExecutorState ( void  )

Definition at line 90 of file execUtils.c.

91 {
92  EState *estate;
93  MemoryContext qcontext;
94  MemoryContext oldcontext;
95 
96  /*
97  * Create the per-query context for this Executor run.
98  */
100  "ExecutorState",
102 
103  /*
104  * Make the EState node within the per-query context. This way, we don't
105  * need a separate pfree() operation for it at shutdown.
106  */
107  oldcontext = MemoryContextSwitchTo(qcontext);
108 
109  estate = makeNode(EState);
110 
111  /*
112  * Initialize all fields of the Executor State structure
113  */
115  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
116  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
117  estate->es_range_table = NIL;
118  estate->es_range_table_size = 0;
119  estate->es_relations = NULL;
120  estate->es_rowmarks = NULL;
121  estate->es_plannedstmt = NULL;
122  estate->es_part_prune_infos = NIL;
123 
124  estate->es_junkFilter = NULL;
125 
126  estate->es_output_cid = (CommandId) 0;
127 
128  estate->es_result_relations = NULL;
132  estate->es_trig_target_relations = NIL;
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 
145  estate->es_top_eflags = 0;
146  estate->es_instrument = 0;
147  estate->es_finished = false;
148 
149  estate->es_exprcontexts = NIL;
150 
151  estate->es_subplanstates = NIL;
152 
153  estate->es_auxmodifytables = NIL;
154 
155  estate->es_per_tuple_exprcontext = NULL;
156 
157  estate->es_sourceText = NULL;
158 
159  estate->es_use_parallel_mode = false;
160 
161  estate->es_jit_flags = 0;
162  estate->es_jit = NULL;
163 
164  /*
165  * Return the executor state structure
166  */
167  MemoryContextSwitchTo(oldcontext);
168 
169  return estate;
170 }
uint32 CommandId
Definition: c.h:602
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
#define makeNode(_type_)
Definition: nodes.h:165
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
#define NIL
Definition: pg_list.h:66
@ ForwardScanDirection
Definition: sdir.h:26
#define InvalidSnapshot
Definition: snapshot.h:123
uint64 es_processed
Definition: execnodes.h:659
List * es_part_prune_infos
Definition: execnodes.h:621
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:618
List * es_tuple_routing_result_relations
Definition: execnodes.h:643
int es_top_eflags
Definition: execnodes.h:661
struct JitContext * es_jit
Definition: execnodes.h:701
int es_instrument
Definition: execnodes.h:662
PlannedStmt * es_plannedstmt
Definition: execnodes.h:620
QueryEnvironment * es_queryEnv
Definition: execnodes.h:652
ResultRelInfo ** es_result_relations
Definition: execnodes.h:630
ParamExecData * es_param_exec_vals
Definition: execnodes.h:650
List * es_range_table
Definition: execnodes.h:614
List * es_exprcontexts
Definition: execnodes.h:665
ParamListInfo es_param_list_info
Definition: execnodes.h:649
bool es_finished
Definition: execnodes.h:663
List * es_insert_pending_result_relations
Definition: execnodes.h:708
MemoryContext es_query_cxt
Definition: execnodes.h:655
List * es_tupleTable
Definition: execnodes.h:657
ScanDirection es_direction
Definition: execnodes.h:611
List * es_trig_target_relations
Definition: execnodes.h:646
int es_jit_flags
Definition: execnodes.h:700
List * es_opened_result_relations
Definition: execnodes.h:633
bool es_use_parallel_mode
Definition: execnodes.h:686
Relation * es_relations
Definition: execnodes.h:616
List * es_subplanstates
Definition: execnodes.h:667
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:676
CommandId es_output_cid
Definition: execnodes.h:627
Index es_range_table_size
Definition: execnodes.h:615
const char * es_sourceText
Definition: execnodes.h:622
Snapshot es_snapshot
Definition: execnodes.h:612
List * es_auxmodifytables
Definition: execnodes.h:669
JunkFilter * es_junkFilter
Definition: execnodes.h:624
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:613

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_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_part_prune_infos, 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_snapshot, EState::es_sourceText, EState::es_subplanstates, EState::es_top_eflags, 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(), 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 303 of file execUtils.c.

304 {
306 }
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:233

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

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

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

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

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

319 {
320  Size minContextSize = ALLOCSET_DEFAULT_MINSIZE;
321  Size initBlockSize = ALLOCSET_DEFAULT_INITSIZE;
322  Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
323 
324  /* choose the maxBlockSize to be no larger than 1/16 of work_mem */
325  while (16 * maxBlockSize > work_mem * 1024L)
326  maxBlockSize >>= 1;
327 
328  if (maxBlockSize < ALLOCSET_DEFAULT_INITSIZE)
329  maxBlockSize = ALLOCSET_DEFAULT_INITSIZE;
330 
331  return CreateExprContextInternal(estate, minContextSize,
332  initBlockSize, maxBlockSize);
333 }
size_t Size
Definition: c.h:541
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 537 of file execUtils.c.

539 {
540  planstate->ps_ProjInfo =
542  planstate->ps_ExprContext,
543  planstate->ps_ResultTupleSlot,
544  planstate,
545  inputDesc);
546 }
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:354
Plan * plan
Definition: execnodes.h:1029
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1067
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1069
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 672 of file execUtils.c.

673 {
674  TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
675 
676  ExecSetSlotDescriptor(slot, tupDesc);
677 }
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1289
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1457

References ExecSetSlotDescriptor(), and ScanState::ss_ScanTupleSlot.

Referenced by ExecWorkTableScan().

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1149 of file execUtils.c.

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

References len, lfirst_node, and TargetEntry::resjunk.

Referenced by check_sql_fn_retval(), and ExecTypeFromTLInternal().

◆ ExecConditionalAssignProjectionInfo()

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

Definition at line 557 of file execUtils.c.

559 {
560  if (tlist_matches_tupdesc(planstate,
561  planstate->plan->targetlist,
562  varno,
563  inputDesc))
564  {
565  planstate->ps_ProjInfo = NULL;
566  planstate->resultopsset = planstate->scanopsset;
567  planstate->resultopsfixed = planstate->scanopsfixed;
568  planstate->resultops = planstate->scanops;
569  }
570  else
571  {
572  if (!planstate->ps_ResultTupleSlot)
573  {
574  ExecInitResultSlot(planstate, &TTSOpsVirtual);
575  planstate->resultops = &TTSOpsVirtual;
576  planstate->resultopsfixed = true;
577  planstate->resultopsset = true;
578  }
579  ExecAssignProjectionInfo(planstate, inputDesc);
580  }
581 }
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1779
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
Definition: execUtils.c:584
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:537
const TupleTableSlotOps * resultops
Definition: execnodes.h:1106
bool resultopsset
Definition: execnodes.h:1114
const TupleTableSlotOps * scanops
Definition: execnodes.h:1103
bool scanopsset
Definition: execnodes.h:1111
bool scanopsfixed
Definition: execnodes.h:1107
bool resultopsfixed
Definition: execnodes.h:1110

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

687 {
689  TupleDesc tupDesc;
690 
691  outerPlan = outerPlanState(scanstate);
692  tupDesc = ExecGetResultType(outerPlan);
693 
694  ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
695 }
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1811
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:492
#define outerPlanState(node)
Definition: execnodes.h:1125
#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 1388 of file execUtils.c.

1389 {
1390  return bms_union(ExecGetUpdatedCols(relinfo, estate),
1391  ExecGetExtraUpdatedCols(relinfo, estate));
1392 }
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:226
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1336
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1362

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

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

◆ ExecGetChildToRootMap()

TupleConversionMap* ExecGetChildToRootMap ( ResultRelInfo resultRelInfo)

Definition at line 1236 of file execUtils.c.

1237 {
1238  /* If we didn't already do so, compute the map for this child. */
1239  if (!resultRelInfo->ri_ChildToRootMapValid)
1240  {
1241  ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1242 
1243  if (rootRelInfo)
1244  resultRelInfo->ri_ChildToRootMap =
1246  RelationGetDescr(rootRelInfo->ri_RelationDesc));
1247  else /* this isn't a child result rel */
1248  resultRelInfo->ri_ChildToRootMap = NULL;
1249 
1250  resultRelInfo->ri_ChildToRootMapValid = true;
1251  }
1252 
1253  return resultRelInfo->ri_ChildToRootMap;
1254 }
#define RelationGetDescr(relation)
Definition: rel.h:527
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:567
Relation ri_RelationDesc
Definition: execnodes.h:448
TupleConversionMap * ri_ChildToRootMap
Definition: execnodes.h:547
bool ri_ChildToRootMapValid
Definition: execnodes.h:548
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 1362 of file execUtils.c.

1363 {
1364  /* see ExecGetInsertedCols() */
1365  if (relinfo->ri_RangeTableIndex != 0)
1366  {
1367  RangeTblEntry *rte = exec_rt_fetch(relinfo->ri_RangeTableIndex, estate);
1368 
1369  return rte->extraUpdatedCols;
1370  }
1371  else if (relinfo->ri_RootResultRelInfo)
1372  {
1373  ResultRelInfo *rootRelInfo = relinfo->ri_RootResultRelInfo;
1374  RangeTblEntry *rte = exec_rt_fetch(rootRelInfo->ri_RangeTableIndex, estate);
1375  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1376 
1377  if (map != NULL)
1378  return execute_attr_map_cols(map->attrMap, rte->extraUpdatedCols);
1379  else
1380  return rte->extraUpdatedCols;
1381  }
1382  else
1383  return NULL;
1384 }
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition: execUtils.c:1262
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:573
Bitmapset * extraUpdatedCols
Definition: parsenodes.h:1185
Index ri_RangeTableIndex
Definition: execnodes.h:445
AttrMap * attrMap
Definition: tupconvert.h:28
Bitmapset * execute_attr_map_cols(AttrMap *attrMap, Bitmapset *in_cols)
Definition: tupconvert.c:252

References TupleConversionMap::attrMap, exec_rt_fetch(), ExecGetRootToChildMap(), execute_attr_map_cols(), RangeTblEntry::extraUpdatedCols, ResultRelInfo::ri_RangeTableIndex, and ResultRelInfo::ri_RootResultRelInfo.

Referenced by ExecComputeStoredGenerated(), ExecGetAllUpdatedCols(), and index_unchanged_by_update().

◆ ExecGetInsertedCols()

Bitmapset* ExecGetInsertedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1297 of file execUtils.c.

1298 {
1299  /*
1300  * The columns are stored in the range table entry. If this ResultRelInfo
1301  * represents a partition routing target, and doesn't have an entry of its
1302  * own in the range table, fetch the parent's RTE and map the columns to
1303  * the order they are in the partition.
1304  */
1305  if (relinfo->ri_RangeTableIndex != 0)
1306  {
1307  RangeTblEntry *rte = exec_rt_fetch(relinfo->ri_RangeTableIndex, estate);
1308 
1309  return rte->insertedCols;
1310  }
1311  else if (relinfo->ri_RootResultRelInfo)
1312  {
1313  ResultRelInfo *rootRelInfo = relinfo->ri_RootResultRelInfo;
1314  RangeTblEntry *rte = exec_rt_fetch(rootRelInfo->ri_RangeTableIndex, estate);
1315  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1316 
1317  if (map != NULL)
1318  return execute_attr_map_cols(map->attrMap, rte->insertedCols);
1319  else
1320  return rte->insertedCols;
1321  }
1322  else
1323  {
1324  /*
1325  * The relation isn't in the range table and it isn't a partition
1326  * routing target. This ResultRelInfo must've been created only for
1327  * firing triggers and the relation is not being inserted into. (See
1328  * ExecGetTriggerResultRel.)
1329  */
1330  return NULL;
1331  }
1332 }
Bitmapset * insertedCols
Definition: parsenodes.h:1183

References TupleConversionMap::attrMap, exec_rt_fetch(), ExecGetRootToChildMap(), execute_attr_map_cols(), RangeTblEntry::insertedCols, ResultRelInfo::ri_RangeTableIndex, and ResultRelInfo::ri_RootResultRelInfo.

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

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti 
)

Definition at line 784 of file execUtils.c.

785 {
786  Relation rel;
787 
788  Assert(rti > 0 && rti <= estate->es_range_table_size);
789 
790  rel = estate->es_relations[rti - 1];
791  if (rel == NULL)
792  {
793  /* First time through, so open the relation */
794  RangeTblEntry *rte = exec_rt_fetch(rti, estate);
795 
796  Assert(rte->rtekind == RTE_RELATION);
797 
798  if (!IsParallelWorker())
799  {
800  /*
801  * In a normal query, we should already have the appropriate lock,
802  * but verify that through an Assert. Since there's already an
803  * Assert inside table_open that insists on holding some lock, it
804  * seems sufficient to check this only when rellockmode is higher
805  * than the minimum.
806  */
807  rel = table_open(rte->relid, NoLock);
809  CheckRelationLockedByMe(rel, rte->rellockmode, false));
810  }
811  else
812  {
813  /*
814  * If we are a parallel worker, we need to obtain our own local
815  * lock on the relation. This ensures sane behavior in case the
816  * parent process exits before we do.
817  */
818  rel = table_open(rte->relid, rte->rellockmode);
819  }
820 
821  estate->es_relations[rti - 1] = rel;
822  }
823 
824  return rel;
825 }
#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:1011
RTEKind rtekind
Definition: parsenodes.h:1030
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().

◆ ExecGetResultSlotOps()

const TupleTableSlotOps* ExecGetResultSlotOps ( PlanState planstate,
bool isfixed 
)

Definition at line 501 of file execUtils.c.

502 {
503  if (planstate->resultopsset && planstate->resultops)
504  {
505  if (isfixed)
506  *isfixed = planstate->resultopsfixed;
507  return planstate->resultops;
508  }
509 
510  if (isfixed)
511  {
512  if (planstate->resultopsset)
513  *isfixed = planstate->resultopsfixed;
514  else if (planstate->ps_ResultTupleSlot)
515  *isfixed = TTS_FIXED(planstate->ps_ResultTupleSlot);
516  else
517  *isfixed = false;
518  }
519 
520  if (!planstate->ps_ResultTupleSlot)
521  return &TTSOpsVirtual;
522 
523  return planstate->ps_ResultTupleSlot->tts_ops;
524 }
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 1212 of file execUtils.c.

1213 {
1214  if (relInfo->ri_ReturningSlot == NULL)
1215  {
1216  Relation rel = relInfo->ri_RelationDesc;
1217  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1218 
1219  relInfo->ri_ReturningSlot =
1220  ExecInitExtraTupleSlot(estate,
1221  RelationGetDescr(rel),
1222  table_slot_callbacks(rel));
1223 
1224  MemoryContextSwitchTo(oldcontext);
1225  }
1226 
1227  return relInfo->ri_ReturningSlot;
1228 }
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1831
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:487
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 1262 of file execUtils.c.

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

◆ ExecGetTriggerNewSlot()

TupleTableSlot* ExecGetTriggerNewSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1190 of file execUtils.c.

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

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

1337 {
1338  /* see ExecGetInsertedCols() */
1339  if (relinfo->ri_RangeTableIndex != 0)
1340  {
1341  RangeTblEntry *rte = exec_rt_fetch(relinfo->ri_RangeTableIndex, estate);
1342 
1343  return rte->updatedCols;
1344  }
1345  else if (relinfo->ri_RootResultRelInfo)
1346  {
1347  ResultRelInfo *rootRelInfo = relinfo->ri_RootResultRelInfo;
1348  RangeTblEntry *rte = exec_rt_fetch(rootRelInfo->ri_RangeTableIndex, estate);
1349  TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1350 
1351  if (map != NULL)
1352  return execute_attr_map_cols(map->attrMap, rte->updatedCols);
1353  else
1354  return rte->updatedCols;
1355  }
1356  else
1357  return NULL;
1358 }
Bitmapset * updatedCols
Definition: parsenodes.h:1184

References TupleConversionMap::attrMap, exec_rt_fetch(), ExecGetRootToChildMap(), execute_attr_map_cols(), ResultRelInfo::ri_RangeTableIndex, ResultRelInfo::ri_RootResultRelInfo, and RangeTblEntry::updatedCols.

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

◆ ExecInitRangeTable()

void ExecInitRangeTable ( EState estate,
List rangeTable 
)

Definition at line 753 of file execUtils.c.

754 {
755  /* Remember the range table List as-is */
756  estate->es_range_table = rangeTable;
757 
758  /* Set size of associated arrays */
759  estate->es_range_table_size = list_length(rangeTable);
760 
761  /*
762  * Allocate an array to store an open Relation corresponding to each
763  * rangetable entry, and initialize entries to NULL. Relations are opened
764  * and stored here as needed.
765  */
766  estate->es_relations = (Relation *)
767  palloc0(estate->es_range_table_size * sizeof(Relation));
768 
769  /*
770  * es_result_relations and es_rowmarks are also parallel to
771  * es_range_table, but are allocated only if needed.
772  */
773  estate->es_result_relations = NULL;
774  estate->es_rowmarks = NULL;
775 }
void * palloc0(Size size)
Definition: mcxt.c:1230
static int list_length(const List *l)
Definition: pg_list.h:150

References EState::es_range_table, EState::es_range_table_size, EState::es_relations, EState::es_result_relations, EState::es_rowmarks, 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 836 of file execUtils.c.

838 {
839  Relation resultRelationDesc;
840 
841  resultRelationDesc = ExecGetRangeTableRelation(estate, rti);
842  InitResultRelInfo(resultRelInfo,
843  resultRelationDesc,
844  rti,
845  NULL,
846  estate->es_instrument);
847 
848  if (estate->es_result_relations == NULL)
849  estate->es_result_relations = (ResultRelInfo **)
850  palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
851  estate->es_result_relations[rti - 1] = resultRelInfo;
852 
853  /*
854  * Saving in the list allows to avoid needlessly traversing the whole
855  * array when only a few of its entries are possibly non-NULL.
856  */
858  lappend(estate->es_opened_result_relations, resultRelInfo);
859 }
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Definition: execMain.c:1196
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:784
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 722 of file execUtils.c.

723 {
724  Relation rel;
725 
726  /* Open the relation. */
727  rel = ExecGetRangeTableRelation(estate, scanrelid);
728 
729  /*
730  * Complain if we're attempting a scan of an unscannable relation, except
731  * when the query won't actually be run. This is a slightly klugy place
732  * to do this, perhaps, but there is no better place.
733  */
734  if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
735  !RelationIsScannable(rel))
736  ereport(ERROR,
737  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
738  errmsg("materialized view \"%s\" has not been populated",
740  errhint("Use the REFRESH MATERIALIZED VIEW command.")));
741 
742  return rel;
743 }
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
#define EXEC_FLAG_WITH_NO_DATA
Definition: executor.h:61
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:56
#define RelationIsScannable(relation)
Definition: rel.h:667
#define RelationGetRelationName(relation)
Definition: rel.h:535

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

710 {
711  return list_member_int(estate->es_plannedstmt->resultRelations, scanrelid);
712 }
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 1139 of file execUtils.c.

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

References list_length().

Referenced by ExecTypeFromTLInternal().

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 900 of file execUtils.c.

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

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

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

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

414 {
415  EState *estate;
416 
417  /* Call any registered callbacks */
418  ShutdownExprContext(econtext, isCommit);
419  /* And clean up the memory used */
421  /* Unlink self from owning EState, if any */
422  estate = econtext->ecxt_estate;
423  if (estate)
425  econtext);
426  /* And delete the ExprContext node */
427  pfree(econtext);
428 }
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:984
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:871
void pfree(void *pointer)
Definition: mcxt.c:1306

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

1026 {
1027  AttrNumber attrno;
1028  Datum result;
1029  Oid tupType;
1030  int32 tupTypmod;
1031  TupleDesc tupDesc;
1032  HeapTupleData tmptup;
1033  int i;
1034 
1035  if (attname == NULL)
1036  elog(ERROR, "invalid attribute name");
1037 
1038  if (isNull == NULL)
1039  elog(ERROR, "a NULL isNull pointer was passed");
1040 
1041  if (tuple == NULL)
1042  {
1043  /* Kinda bogus but compatible with old behavior... */
1044  *isNull = true;
1045  return (Datum) 0;
1046  }
1047 
1048  tupType = HeapTupleHeaderGetTypeId(tuple);
1049  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1050  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1051 
1052  attrno = InvalidAttrNumber;
1053  for (i = 0; i < tupDesc->natts; i++)
1054  {
1055  Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1056 
1057  if (namestrcmp(&(att->attname), attname) == 0)
1058  {
1059  attrno = att->attnum;
1060  break;
1061  }
1062  }
1063 
1064  if (attrno == InvalidAttrNumber)
1065  elog(ERROR, "attribute \"%s\" does not exist", attname);
1066 
1067  /*
1068  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1069  * the fields in the struct just in case user tries to inspect system
1070  * columns.
1071  */
1072  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1073  ItemPointerSetInvalid(&(tmptup.t_self));
1074  tmptup.t_tableOid = InvalidOid;
1075  tmptup.t_data = tuple;
1076 
1077  result = heap_getattr(&tmptup,
1078  attrno,
1079  tupDesc,
1080  isNull);
1081 
1082  ReleaseTupleDesc(tupDesc);
1083 
1084  return result;
1085 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
signed int int32
Definition: c.h:430
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:788
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:462
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:452
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:446
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:207
#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 1088 of file execUtils.c.

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

◆ MakePerTupleExprContext()

ExprContext* MakePerTupleExprContext ( EState estate)

Definition at line 455 of file execUtils.c.

456 {
457  if (estate->es_per_tuple_exprcontext == NULL)
459 
460  return estate->es_per_tuple_exprcontext;
461 }

References CreateExprContext(), and EState::es_per_tuple_exprcontext.

◆ RegisterExprContextCallback()

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

Definition at line 927 of file execUtils.c.

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

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

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

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

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

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

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

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

Referenced by ExecConditionalAssignProjectionInfo().

◆ UnregisterExprContextCallback()

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

Definition at line 953 of file execUtils.c.

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

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

867 {
868  Bitmapset *parmset;
869 
870  /*
871  * The plan node only depends on params listed in its allParam set. Don't
872  * include anything else into its chgParam set.
873  */
874  parmset = bms_intersect(node->plan->allParam, newchg);
875 
876  /*
877  * Keep node->chgParam == NULL if there's not actually any members; this
878  * allows the simplest possible tests in executor node files.
879  */
880  if (!bms_is_empty(parmset))
881  node->chgParam = bms_join(node->chgParam, parmset);
882  else
883  bms_free(parmset);
884 }
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:953
void bms_free(Bitmapset *a)
Definition: bitmapset.c:209
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:260
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:704
Bitmapset * chgParam
Definition: execnodes.h:1061
Bitmapset * allParam
Definition: plannodes.h:172

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

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