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 "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, Index 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, Index 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)
 

Function Documentation

◆ CreateExecutorState()

EState* CreateExecutorState ( void  )

Definition at line 89 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CurrentMemoryContext, EState::es_auxmodifytables, EState::es_crosscheck_snapshot, EState::es_direction, EState::es_exprcontexts, EState::es_finished, EState::es_instrument, EState::es_jit, EState::es_jit_flags, EState::es_junkFilter, EState::es_opened_result_relations, EState::es_output_cid, EState::es_param_exec_vals, EState::es_param_list_info, EState::es_per_tuple_exprcontext, EState::es_plannedstmt, EState::es_processed, EState::es_query_cxt, EState::es_queryEnv, EState::es_range_table, EState::es_range_table_size, EState::es_relations, EState::es_result_relations, EState::es_rowmarks, EState::es_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_index_stats(), CopyFrom(), 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(), operator_predicate_proof(), plpgsql_create_econtext(), plpgsql_inline_handler(), standard_ExecutorStart(), StoreAttrDefault(), tuplesort_begin_cluster(), unique_key_recheck(), and validateDomainConstraint().

90 {
91  EState *estate;
92  MemoryContext qcontext;
93  MemoryContext oldcontext;
94 
95  /*
96  * Create the per-query context for this Executor run.
97  */
99  "ExecutorState",
101 
102  /*
103  * Make the EState node within the per-query context. This way, we don't
104  * need a separate pfree() operation for it at shutdown.
105  */
106  oldcontext = MemoryContextSwitchTo(qcontext);
107 
108  estate = makeNode(EState);
109 
110  /*
111  * Initialize all fields of the Executor State structure
112  */
114  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
115  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
116  estate->es_range_table = NIL;
117  estate->es_range_table_size = 0;
118  estate->es_relations = NULL;
119  estate->es_rowmarks = NULL;
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 
131  estate->es_param_list_info = NULL;
132  estate->es_param_exec_vals = NULL;
133 
134  estate->es_queryEnv = NULL;
135 
136  estate->es_query_cxt = qcontext;
137 
138  estate->es_tupleTable = NIL;
139 
140  estate->es_processed = 0;
141 
142  estate->es_top_eflags = 0;
143  estate->es_instrument = 0;
144  estate->es_finished = false;
145 
146  estate->es_exprcontexts = NIL;
147 
148  estate->es_subplanstates = NIL;
149 
150  estate->es_auxmodifytables = NIL;
151 
152  estate->es_per_tuple_exprcontext = NULL;
153 
154  estate->es_sourceText = NULL;
155 
156  estate->es_use_parallel_mode = false;
157 
158  estate->es_jit_flags = 0;
159  estate->es_jit = NULL;
160 
161  /*
162  * Return the executor state structure
163  */
164  MemoryContextSwitchTo(oldcontext);
165 
166  return estate;
167 }
#define NIL
Definition: pg_list.h:65
uint32 CommandId
Definition: c.h:535
JunkFilter * es_junkFilter
Definition: execnodes.h:528
#define AllocSetContextCreate
Definition: memutils.h:170
CommandId es_output_cid
Definition: execnodes.h:531
struct JitContext * es_jit
Definition: execnodes.h:605
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
PlannedStmt * es_plannedstmt
Definition: execnodes.h:525
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:518
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:580
Snapshot es_snapshot
Definition: execnodes.h:517
List * es_range_table
Definition: execnodes.h:519
ScanDirection es_direction
Definition: execnodes.h:516
bool es_use_parallel_mode
Definition: execnodes.h:590
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:523
const char * es_sourceText
Definition: execnodes.h:526
ParamExecData * es_param_exec_vals
Definition: execnodes.h:554
MemoryContext es_query_cxt
Definition: execnodes.h:559
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
int es_jit_flags
Definition: execnodes.h:604
List * es_opened_result_relations
Definition: execnodes.h:537
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
int es_instrument
Definition: execnodes.h:566
ResultRelInfo ** es_result_relations
Definition: execnodes.h:534
QueryEnvironment * es_queryEnv
Definition: execnodes.h:556
#define InvalidSnapshot
Definition: snapshot.h:123
List * es_trig_target_relations
Definition: execnodes.h:550
List * es_tupleTable
Definition: execnodes.h:561
List * es_auxmodifytables
Definition: execnodes.h:573
List * es_tuple_routing_result_relations
Definition: execnodes.h:547
bool es_finished
Definition: execnodes.h:567
#define makeNode(_type_)
Definition: nodes.h:576
Relation * es_relations
Definition: execnodes.h:521
uint64 es_processed
Definition: execnodes.h:563
Index es_range_table_size
Definition: execnodes.h:520
List * es_subplanstates
Definition: execnodes.h:571
int es_top_eflags
Definition: execnodes.h:565
ParamListInfo es_param_list_info
Definition: execnodes.h:553
List * es_exprcontexts
Definition: execnodes.h:569

◆ CreateExprContext()

ExprContext* CreateExprContext ( EState estate)

Definition at line 300 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, and CreateExprContextInternal().

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

301 {
303 }
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:230
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192

◆ CreateExprContextInternal()

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

Definition at line 230 of file execUtils.c.

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

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

◆ CreateStandaloneExprContext()

ExprContext* CreateStandaloneExprContext ( void  )

Definition at line 351 of file execUtils.c.

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

352 {
353  ExprContext *econtext;
354 
355  /* Create the ExprContext node within the caller's memory context */
356  econtext = makeNode(ExprContext);
357 
358  /* Initialize fields of ExprContext */
359  econtext->ecxt_scantuple = NULL;
360  econtext->ecxt_innertuple = NULL;
361  econtext->ecxt_outertuple = NULL;
362 
364 
365  /*
366  * Create working memory for expression evaluation in this context.
367  */
368  econtext->ecxt_per_tuple_memory =
370  "ExprContext",
372 
373  econtext->ecxt_param_exec_vals = NULL;
374  econtext->ecxt_param_list_info = NULL;
375 
376  econtext->ecxt_aggvalues = NULL;
377  econtext->ecxt_aggnulls = NULL;
378 
379  econtext->caseValue_datum = (Datum) 0;
380  econtext->caseValue_isNull = true;
381 
382  econtext->domainValue_datum = (Datum) 0;
383  econtext->domainValue_isNull = true;
384 
385  econtext->ecxt_estate = NULL;
386 
387  econtext->ecxt_callbacks = NULL;
388 
389  return econtext;
390 }
#define AllocSetContextCreate
Definition: memutils.h:170
Datum * ecxt_aggvalues
Definition: execnodes.h:244
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:233
Datum domainValue_datum
Definition: execnodes.h:256
Datum caseValue_datum
Definition: execnodes.h:250
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:264
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:227
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:236
struct EState * ecxt_estate
Definition: execnodes.h:261
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
bool domainValue_isNull
Definition: execnodes.h:258
bool * ecxt_aggnulls
Definition: execnodes.h:246
uintptr_t Datum
Definition: postgres.h:367
#define makeNode(_type_)
Definition: nodes.h:576
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:229
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:225
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:232
bool caseValue_isNull
Definition: execnodes.h:252
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:237

◆ CreateWorkExprContext()

ExprContext* CreateWorkExprContext ( EState estate)

Definition at line 315 of file execUtils.c.

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

Referenced by ExecInitAgg().

316 {
317  Size minContextSize = ALLOCSET_DEFAULT_MINSIZE;
318  Size initBlockSize = ALLOCSET_DEFAULT_INITSIZE;
319  Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
320 
321  /* choose the maxBlockSize to be no larger than 1/16 of work_mem */
322  while (16 * maxBlockSize > work_mem * 1024L)
323  maxBlockSize >>= 1;
324 
325  if (maxBlockSize < ALLOCSET_DEFAULT_INITSIZE)
326  maxBlockSize = ALLOCSET_DEFAULT_INITSIZE;
327 
328  return CreateExprContextInternal(estate, minContextSize,
329  initBlockSize, maxBlockSize);
330 }
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:230
#define ALLOCSET_DEFAULT_MINSIZE
Definition: memutils.h:189
int work_mem
Definition: globals.c:121
size_t Size
Definition: c.h:474
#define ALLOCSET_DEFAULT_INITSIZE
Definition: memutils.h:190
#define ALLOCSET_DEFAULT_MAXSIZE
Definition: memutils.h:191

◆ ExecAssignExprContext()

◆ ExecAssignProjectionInfo()

void ExecAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc 
)

Definition at line 534 of file execUtils.c.

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

536 {
537  planstate->ps_ProjInfo =
539  planstate->ps_ExprContext,
540  planstate->ps_ResultTupleSlot,
541  planstate,
542  inputDesc);
543 }
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:979
ExprContext * ps_ExprContext
Definition: execnodes.h:978
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
Plan * plan
Definition: execnodes.h:939
List * targetlist
Definition: plannodes.h:136
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:353

◆ ExecAssignScanType()

void ExecAssignScanType ( ScanState scanstate,
TupleDesc  tupDesc 
)

Definition at line 669 of file execUtils.c.

References ExecSetSlotDescriptor(), and ScanState::ss_ScanTupleSlot.

Referenced by ExecWorkTableScan().

670 {
671  TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
672 
673  ExecSetSlotDescriptor(slot, tupDesc);
674 }
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1331
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1259

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1146 of file execUtils.c.

References lfirst_node, and TargetEntry::resjunk.

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

1147 {
1148  int len = 0;
1149  ListCell *tl;
1150 
1151  foreach(tl, targetlist)
1152  {
1153  TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1154 
1155  if (!curTle->resjunk)
1156  len++;
1157  }
1158  return len;
1159 }
bool resjunk
Definition: primnodes.h:1417
#define lfirst_node(type, lc)
Definition: pg_list.h:172

◆ ExecConditionalAssignProjectionInfo()

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

Definition at line 554 of file execUtils.c.

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

556 {
557  if (tlist_matches_tupdesc(planstate,
558  planstate->plan->targetlist,
559  varno,
560  inputDesc))
561  {
562  planstate->ps_ProjInfo = NULL;
563  planstate->resultopsset = planstate->scanopsset;
564  planstate->resultopsfixed = planstate->scanopsfixed;
565  planstate->resultops = planstate->scanops;
566  }
567  else
568  {
569  if (!planstate->ps_ResultTupleSlot)
570  {
571  ExecInitResultSlot(planstate, &TTSOpsVirtual);
572  planstate->resultops = &TTSOpsVirtual;
573  planstate->resultopsfixed = true;
574  planstate->resultopsset = true;
575  }
576  ExecAssignProjectionInfo(planstate, inputDesc);
577  }
578 }
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:979
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
const TupleTableSlotOps * resultops
Definition: execnodes.h:1014
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
const TupleTableSlotOps * scanops
Definition: execnodes.h:1011
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:534
bool resultopsset
Definition: execnodes.h:1022
Plan * plan
Definition: execnodes.h:939
bool scanopsfixed
Definition: execnodes.h:1015
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1749
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc)
Definition: execUtils.c:581
bool scanopsset
Definition: execnodes.h:1019
List * targetlist
Definition: plannodes.h:136
bool resultopsfixed
Definition: execnodes.h:1018

◆ ExecCreateScanSlotFromOuterPlan()

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

Definition at line 681 of file execUtils.c.

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

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

684 {
686  TupleDesc tupDesc;
687 
688  outerPlan = outerPlanState(scanstate);
689  tupDesc = ExecGetResultType(outerPlan);
690 
691  ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
692 }
#define outerPlanState(node)
Definition: execnodes.h:1033
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1781
#define outerPlan(node)
Definition: plannodes.h:166
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:489

◆ ExecFreeExprContext()

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti 
)

Definition at line 781 of file execUtils.c.

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 exec_rt_fetch(), ExecCreatePartitionPruneState(), ExecInitResultRelation(), ExecOpenScanRelation(), and InitPlan().

782 {
783  Relation rel;
784 
785  Assert(rti > 0 && rti <= estate->es_range_table_size);
786 
787  rel = estate->es_relations[rti - 1];
788  if (rel == NULL)
789  {
790  /* First time through, so open the relation */
791  RangeTblEntry *rte = exec_rt_fetch(rti, estate);
792 
793  Assert(rte->rtekind == RTE_RELATION);
794 
795  if (!IsParallelWorker())
796  {
797  /*
798  * In a normal query, we should already have the appropriate lock,
799  * but verify that through an Assert. Since there's already an
800  * Assert inside table_open that insists on holding some lock, it
801  * seems sufficient to check this only when rellockmode is higher
802  * than the minimum.
803  */
804  rel = table_open(rte->relid, NoLock);
806  CheckRelationLockedByMe(rel, rte->rellockmode, false));
807  }
808  else
809  {
810  /*
811  * If we are a parallel worker, we need to obtain our own local
812  * lock on the relation. This ensures sane behavior in case the
813  * parent process exits before we do.
814  */
815  rel = table_open(rte->relid, rte->rellockmode);
816  }
817 
818  estate->es_relations[rti - 1] = rel;
819  }
820 
821  return rel;
822 }
#define AccessShareLock
Definition: lockdefs.h:36
#define NoLock
Definition: lockdefs.h:34
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:544
#define IsParallelWorker()
Definition: parallel.h:61
#define Assert(condition)
Definition: c.h:746
Relation * es_relations
Definition: execnodes.h:521
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:302
RTEKind rtekind
Definition: parsenodes.h:977
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ ExecGetResultSlotOps()

const TupleTableSlotOps* ExecGetResultSlotOps ( PlanState planstate,
bool isfixed 
)

Definition at line 498 of file execUtils.c.

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

499 {
500  if (planstate->resultopsset && planstate->resultops)
501  {
502  if (isfixed)
503  *isfixed = planstate->resultopsfixed;
504  return planstate->resultops;
505  }
506 
507  if (isfixed)
508  {
509  if (planstate->resultopsset)
510  *isfixed = planstate->resultopsfixed;
511  else if (planstate->ps_ResultTupleSlot)
512  *isfixed = TTS_FIXED(planstate->ps_ResultTupleSlot);
513  else
514  *isfixed = false;
515  }
516 
517  if (!planstate->ps_ResultTupleSlot)
518  return &TTSOpsVirtual;
519 
520  return planstate->ps_ResultTupleSlot->tts_ops;
521 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
const TupleTableSlotOps * resultops
Definition: execnodes.h:1014
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
bool resultopsset
Definition: execnodes.h:1022
bool resultopsfixed
Definition: execnodes.h:1018

◆ ExecGetResultType()

◆ ExecGetReturningSlot()

TupleTableSlot* ExecGetReturningSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1209 of file execUtils.c.

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

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

1210 {
1211  if (relInfo->ri_ReturningSlot == NULL)
1212  {
1213  Relation rel = relInfo->ri_RelationDesc;
1214  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1215 
1216  relInfo->ri_ReturningSlot =
1217  ExecInitExtraTupleSlot(estate,
1218  RelationGetDescr(rel),
1219  table_slot_callbacks(rel));
1220 
1221  MemoryContextSwitchTo(oldcontext);
1222  }
1223 
1224  return relInfo->ri_ReturningSlot;
1225 }
Relation ri_RelationDesc
Definition: execnodes.h:412
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
#define RelationGetDescr(relation)
Definition: rel.h:482
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext es_query_cxt
Definition: execnodes.h:559
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:436

◆ ExecGetTriggerNewSlot()

TupleTableSlot* ExecGetTriggerNewSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1187 of file execUtils.c.

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

Referenced by AfterTriggerExecute(), and exec_rt_fetch().

1188 {
1189  if (relInfo->ri_TrigNewSlot == NULL)
1190  {
1191  Relation rel = relInfo->ri_RelationDesc;
1192  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1193 
1194  relInfo->ri_TrigNewSlot =
1195  ExecInitExtraTupleSlot(estate,
1196  RelationGetDescr(rel),
1197  table_slot_callbacks(rel));
1198 
1199  MemoryContextSwitchTo(oldcontext);
1200  }
1201 
1202  return relInfo->ri_TrigNewSlot;
1203 }
Relation ri_RelationDesc
Definition: execnodes.h:412
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
#define RelationGetDescr(relation)
Definition: rel.h:482
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:438
MemoryContext es_query_cxt
Definition: execnodes.h:559

◆ ExecGetTriggerOldSlot()

TupleTableSlot* ExecGetTriggerOldSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1165 of file execUtils.c.

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

Referenced by AfterTriggerExecute(), exec_rt_fetch(), ExecARDeleteTriggers(), ExecARUpdateTriggers(), ExecBRDeleteTriggers(), ExecBRUpdateTriggers(), ExecIRDeleteTriggers(), and ExecIRUpdateTriggers().

1166 {
1167  if (relInfo->ri_TrigOldSlot == NULL)
1168  {
1169  Relation rel = relInfo->ri_RelationDesc;
1170  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1171 
1172  relInfo->ri_TrigOldSlot =
1173  ExecInitExtraTupleSlot(estate,
1174  RelationGetDescr(rel),
1175  table_slot_callbacks(rel));
1176 
1177  MemoryContextSwitchTo(oldcontext);
1178  }
1179 
1180  return relInfo->ri_TrigOldSlot;
1181 }
Relation ri_RelationDesc
Definition: execnodes.h:412
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
#define RelationGetDescr(relation)
Definition: rel.h:482
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext es_query_cxt
Definition: execnodes.h:559
TupleTableSlot * ri_TrigOldSlot
Definition: execnodes.h:437

◆ ExecInitRangeTable()

void ExecInitRangeTable ( EState estate,
List rangeTable 
)

Definition at line 750 of file execUtils.c.

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_estate_for_relation(), and InitPlan().

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

◆ ExecInitResultRelation()

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

Definition at line 833 of file execUtils.c.

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(), exec_rt_fetch(), and ExecInitModifyTable().

835 {
836  Relation resultRelationDesc;
837 
838  resultRelationDesc = ExecGetRangeTableRelation(estate, rti);
839  InitResultRelInfo(resultRelInfo,
840  resultRelationDesc,
841  rti,
842  NULL,
843  estate->es_instrument);
844 
845  if (estate->es_result_relations == NULL)
846  estate->es_result_relations = (ResultRelInfo **)
847  palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
848  estate->es_result_relations[rti - 1] = resultRelInfo;
849 
850  /*
851  * Saving in the list allows to avoid needlessly traversing the whole
852  * array when only a few of its entries are possibly non-NULL.
853  */
855  lappend(estate->es_opened_result_relations, resultRelInfo);
856 }
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, Relation partition_root, int instrument_options)
Definition: execMain.c:1196
List * es_opened_result_relations
Definition: execnodes.h:537
int es_instrument
Definition: execnodes.h:566
ResultRelInfo ** es_result_relations
Definition: execnodes.h:534
List * lappend(List *list, void *datum)
Definition: list.c:321
void * palloc0(Size size)
Definition: mcxt.c:981
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:781
Index es_range_table_size
Definition: execnodes.h:520

◆ ExecOpenScanRelation()

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

Definition at line 719 of file execUtils.c.

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(), ExecInitTidScan(), and postgresBeginDirectModify().

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

◆ ExecRelationIsTargetRelation()

bool ExecRelationIsTargetRelation ( EState estate,
Index  scanrelid 
)

Definition at line 706 of file execUtils.c.

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

707 {
708  return list_member_int(estate->es_plannedstmt->resultRelations, scanrelid);
709 }
PlannedStmt * es_plannedstmt
Definition: execnodes.h:525
bool list_member_int(const List *list, int datum)
Definition: list.c:654
List * resultRelations
Definition: plannodes.h:69

◆ ExecTargetListLength()

int ExecTargetListLength ( List targetlist)

Definition at line 1136 of file execUtils.c.

References list_length().

Referenced by exec_rt_fetch(), and ExecTypeFromTLInternal().

1137 {
1138  /* This used to be more complex, but fjoins are dead */
1139  return list_length(targetlist);
1140 }
static int list_length(const List *l)
Definition: pg_list.h:149

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 897 of file execUtils.c.

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

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

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

◆ FreeExecutorState()

void FreeExecutorState ( EState estate)

Definition at line 185 of file execUtils.c.

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(), apply_handle_delete(), apply_handle_insert(), apply_handle_update(), ATRewriteTable(), check_default_partition_contents(), compute_index_stats(), CopyFrom(), EvalPlanQualEnd(), evaluate_expr(), ExecuteCallStmt(), ExecuteQuery(), ExecuteTruncateGuts(), ExplainExecuteQuery(), get_qual_for_range(), heapam_index_build_range_scan(), heapam_index_validate_scan(), IndexCheckExclusion(), operator_predicate_proof(), plpgsql_inline_handler(), plpgsql_xact_cb(), standard_ExecutorEnd(), StoreAttrDefault(), tuplesort_free(), unique_key_recheck(), and validateDomainConstraint().

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

◆ FreeExprContext()

void FreeExprContext ( ExprContext econtext,
bool  isCommit 
)

Definition at line 410 of file execUtils.c.

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

411 {
412  EState *estate;
413 
414  /* Call any registered callbacks */
415  ShutdownExprContext(econtext, isCommit);
416  /* And clean up the memory used */
418  /* Unlink self from owning EState, if any */
419  estate = econtext->ecxt_estate;
420  if (estate)
422  econtext);
423  /* And delete the ExprContext node */
424  pfree(econtext);
425 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:212
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:233
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:796
void pfree(void *pointer)
Definition: mcxt.c:1057
struct EState * ecxt_estate
Definition: execnodes.h:261
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:981
List * es_exprcontexts
Definition: execnodes.h:569

◆ GetAttributeByName()

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

Definition at line 1022 of file execUtils.c.

References 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(), exec_rt_fetch(), and overpaid().

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

◆ GetAttributeByNum()

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

Definition at line 1085 of file execUtils.c.

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.

Referenced by exec_rt_fetch().

1088 {
1089  Datum result;
1090  Oid tupType;
1091  int32 tupTypmod;
1092  TupleDesc tupDesc;
1093  HeapTupleData tmptup;
1094 
1095  if (!AttributeNumberIsValid(attrno))
1096  elog(ERROR, "invalid attribute number %d", attrno);
1097 
1098  if (isNull == NULL)
1099  elog(ERROR, "a NULL isNull pointer was passed");
1100 
1101  if (tuple == NULL)
1102  {
1103  /* Kinda bogus but compatible with old behavior... */
1104  *isNull = true;
1105  return (Datum) 0;
1106  }
1107 
1108  tupType = HeapTupleHeaderGetTypeId(tuple);
1109  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1110  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1111 
1112  /*
1113  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1114  * the fields in the struct just in case user tries to inspect system
1115  * columns.
1116  */
1117  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1118  ItemPointerSetInvalid(&(tmptup.t_self));
1119  tmptup.t_tableOid = InvalidOid;
1120  tmptup.t_data = tuple;
1121 
1122  result = heap_getattr(&tmptup,
1123  attrno,
1124  tupDesc,
1125  isNull);
1126 
1127  ReleaseTupleDesc(tupDesc);
1128 
1129  return result;
1130 }
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1710
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:363
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
Oid t_tableOid
Definition: htup.h:66
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
uintptr_t Datum
Definition: postgres.h:367
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
#define InvalidOid
Definition: postgres_ext.h:36
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define elog(elevel,...)
Definition: elog.h:214
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ MakePerTupleExprContext()

ExprContext* MakePerTupleExprContext ( EState estate)

Definition at line 452 of file execUtils.c.

References CreateExprContext(), and EState::es_per_tuple_exprcontext.

453 {
454  if (estate->es_per_tuple_exprcontext == NULL)
456 
457  return estate->es_per_tuple_exprcontext;
458 }
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:580
ExprContext * CreateExprContext(EState *estate)
Definition: execUtils.c:300

◆ RegisterExprContextCallback()

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

Definition at line 924 of file execUtils.c.

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

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

927 {
928  ExprContext_CB *ecxt_callback;
929 
930  /* Save the info in appropriate memory context */
931  ecxt_callback = (ExprContext_CB *)
933  sizeof(ExprContext_CB));
934 
935  ecxt_callback->function = function;
936  ecxt_callback->arg = arg;
937 
938  /* link to front of list for appropriate execution order */
939  ecxt_callback->next = econtext->ecxt_callbacks;
940  econtext->ecxt_callbacks = ecxt_callback;
941 }
ExprContextCallbackFunction function
Definition: execnodes.h:192
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:264
struct ExprContext_CB * next
Definition: execnodes.h:191
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:232
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:797
void * arg

◆ ReScanExprContext()

void ReScanExprContext ( ExprContext econtext)

Definition at line 437 of file execUtils.c.

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

438 {
439  /* Call any registered callbacks */
440  ShutdownExprContext(econtext, true);
441  /* And clean up the memory used */
443 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:233
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:137
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:981

◆ ShutdownExprContext()

static void ShutdownExprContext ( ExprContext econtext,
bool  isCommit 
)
static

Definition at line 981 of file execUtils.c.

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

982 {
983  ExprContext_CB *ecxt_callback;
984  MemoryContext oldcontext;
985 
986  /* Fast path in normal case where there's nothing to do. */
987  if (econtext->ecxt_callbacks == NULL)
988  return;
989 
990  /*
991  * Call the callbacks in econtext's per-tuple context. This ensures that
992  * any memory they might leak will get cleaned up.
993  */
994  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
995 
996  /*
997  * Call each callback function in reverse registration order.
998  */
999  while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
1000  {
1001  econtext->ecxt_callbacks = ecxt_callback->next;
1002  if (isCommit)
1003  ecxt_callback->function(ecxt_callback->arg);
1004  pfree(ecxt_callback);
1005  }
1006 
1007  MemoryContextSwitchTo(oldcontext);
1008 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:233
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1057
ExprContextCallbackFunction function
Definition: execnodes.h:192
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:264
struct ExprContext_CB * next
Definition: execnodes.h:191

◆ tlist_matches_tupdesc()

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

Definition at line 581 of file execUtils.c.

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

Referenced by ExecConditionalAssignProjectionInfo().

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

◆ UnregisterExprContextCallback()

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

Definition at line 950 of file execUtils.c.

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

Referenced by end_MultiFuncCall(), exec_rt_fetch(), and fmgr_sql().

953 {
954  ExprContext_CB **prev_callback;
955  ExprContext_CB *ecxt_callback;
956 
957  prev_callback = &econtext->ecxt_callbacks;
958 
959  while ((ecxt_callback = *prev_callback) != NULL)
960  {
961  if (ecxt_callback->function == function && ecxt_callback->arg == arg)
962  {
963  *prev_callback = ecxt_callback->next;
964  pfree(ecxt_callback);
965  }
966  else
967  prev_callback = &ecxt_callback->next;
968  }
969 }
void pfree(void *pointer)
Definition: mcxt.c:1057
ExprContextCallbackFunction function
Definition: execnodes.h:192
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:264
struct ExprContext_CB * next
Definition: execnodes.h:191
void * arg

◆ UpdateChangedParamSet()

void UpdateChangedParamSet ( PlanState node,
Bitmapset newchg 
)

Definition at line 863 of file execUtils.c.

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

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