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 "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)
 
ExprContextCreateExprContext (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 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 88 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_num_result_relations, EState::es_num_root_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_relation_info, EState::es_result_relations, EState::es_root_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(), validateCheckConstraint(), and validateDomainConstraint().

89 {
90  EState *estate;
91  MemoryContext qcontext;
92  MemoryContext oldcontext;
93 
94  /*
95  * Create the per-query context for this Executor run.
96  */
98  "ExecutorState",
100 
101  /*
102  * Make the EState node within the per-query context. This way, we don't
103  * need a separate pfree() operation for it at shutdown.
104  */
105  oldcontext = MemoryContextSwitchTo(qcontext);
106 
107  estate = makeNode(EState);
108 
109  /*
110  * Initialize all fields of the Executor State structure
111  */
113  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
114  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
115  estate->es_range_table = NIL;
116  estate->es_range_table_size = 0;
117  estate->es_relations = NULL;
118  estate->es_rowmarks = NULL;
119  estate->es_plannedstmt = NULL;
120 
121  estate->es_junkFilter = NULL;
122 
123  estate->es_output_cid = (CommandId) 0;
124 
125  estate->es_result_relations = NULL;
126  estate->es_num_result_relations = 0;
127  estate->es_result_relation_info = NULL;
128 
129  estate->es_root_result_relations = NULL;
130  estate->es_num_root_result_relations = 0;
131 
133 
134  estate->es_trig_target_relations = NIL;
135 
136  estate->es_param_list_info = NULL;
137  estate->es_param_exec_vals = NULL;
138 
139  estate->es_queryEnv = NULL;
140 
141  estate->es_query_cxt = qcontext;
142 
143  estate->es_tupleTable = NIL;
144 
145  estate->es_processed = 0;
146 
147  estate->es_top_eflags = 0;
148  estate->es_instrument = 0;
149  estate->es_finished = false;
150 
151  estate->es_exprcontexts = NIL;
152 
153  estate->es_subplanstates = NIL;
154 
155  estate->es_auxmodifytables = NIL;
156 
157  estate->es_per_tuple_exprcontext = NULL;
158 
159  estate->es_sourceText = NULL;
160 
161  estate->es_use_parallel_mode = false;
162 
163  estate->es_jit_flags = 0;
164  estate->es_jit = NULL;
165 
166  /*
167  * Return the executor state structure
168  */
169  MemoryContextSwitchTo(oldcontext);
170 
171  return estate;
172 }
#define NIL
Definition: pg_list.h:65
uint32 CommandId
Definition: c.h:521
JunkFilter * es_junkFilter
Definition: execnodes.h:514
#define AllocSetContextCreate
Definition: memutils.h:169
CommandId es_output_cid
Definition: execnodes.h:517
struct JitContext * es_jit
Definition: execnodes.h:596
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
PlannedStmt * es_plannedstmt
Definition: execnodes.h:511
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:504
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:571
Snapshot es_snapshot
Definition: execnodes.h:503
List * es_range_table
Definition: execnodes.h:505
ScanDirection es_direction
Definition: execnodes.h:502
bool es_use_parallel_mode
Definition: execnodes.h:581
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:509
const char * es_sourceText
Definition: execnodes.h:512
ParamExecData * es_param_exec_vals
Definition: execnodes.h:545
MemoryContext es_query_cxt
Definition: execnodes.h:550
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:191
int es_jit_flags
Definition: execnodes.h:595
ResultRelInfo * es_result_relations
Definition: execnodes.h:520
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
int es_instrument
Definition: execnodes.h:557
QueryEnvironment * es_queryEnv
Definition: execnodes.h:547
int es_num_root_result_relations
Definition: execnodes.h:531
#define InvalidSnapshot
Definition: snapshot.h:123
List * es_trig_target_relations
Definition: execnodes.h:541
List * es_tupleTable
Definition: execnodes.h:552
List * es_auxmodifytables
Definition: execnodes.h:564
int es_num_result_relations
Definition: execnodes.h:521
List * es_tuple_routing_result_relations
Definition: execnodes.h:538
bool es_finished
Definition: execnodes.h:558
#define makeNode(_type_)
Definition: nodes.h:573
Relation * es_relations
Definition: execnodes.h:507
uint64 es_processed
Definition: execnodes.h:554
Index es_range_table_size
Definition: execnodes.h:506
List * es_subplanstates
Definition: execnodes.h:562
int es_top_eflags
Definition: execnodes.h:556
ResultRelInfo * es_root_result_relations
Definition: execnodes.h:530
ParamListInfo es_param_list_info
Definition: execnodes.h:544
List * es_exprcontexts
Definition: execnodes.h:560
ResultRelInfo * es_result_relation_info
Definition: execnodes.h:522

◆ CreateExprContext()

ExprContext* CreateExprContext ( EState estate)

Definition at line 244 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, 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 ExecAssignExprContext(), ExecInitMergeJoin(), ExecInitSubPlan(), ExecuteCallStmt(), MakePerTupleExprContext(), and plpgsql_create_econtext().

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

◆ CreateStandaloneExprContext()

ExprContext* CreateStandaloneExprContext ( void  )

Definition at line 316 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().

317 {
318  ExprContext *econtext;
319 
320  /* Create the ExprContext node within the caller's memory context */
321  econtext = makeNode(ExprContext);
322 
323  /* Initialize fields of ExprContext */
324  econtext->ecxt_scantuple = NULL;
325  econtext->ecxt_innertuple = NULL;
326  econtext->ecxt_outertuple = NULL;
327 
329 
330  /*
331  * Create working memory for expression evaluation in this context.
332  */
333  econtext->ecxt_per_tuple_memory =
335  "ExprContext",
337 
338  econtext->ecxt_param_exec_vals = NULL;
339  econtext->ecxt_param_list_info = NULL;
340 
341  econtext->ecxt_aggvalues = NULL;
342  econtext->ecxt_aggnulls = NULL;
343 
344  econtext->caseValue_datum = (Datum) 0;
345  econtext->caseValue_isNull = true;
346 
347  econtext->domainValue_datum = (Datum) 0;
348  econtext->domainValue_isNull = true;
349 
350  econtext->ecxt_estate = NULL;
351 
352  econtext->ecxt_callbacks = NULL;
353 
354  return econtext;
355 }
#define AllocSetContextCreate
Definition: memutils.h:169
Datum * ecxt_aggvalues
Definition: execnodes.h:243
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
Datum domainValue_datum
Definition: execnodes.h:255
Datum caseValue_datum
Definition: execnodes.h:249
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:263
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:191
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:226
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:235
struct EState * ecxt_estate
Definition: execnodes.h:260
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
bool domainValue_isNull
Definition: execnodes.h:257
bool * ecxt_aggnulls
Definition: execnodes.h:245
uintptr_t Datum
Definition: postgres.h:367
#define makeNode(_type_)
Definition: nodes.h:573
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:228
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:224
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
bool caseValue_isNull
Definition: execnodes.h:251
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:236

◆ ExecAssignExprContext()

◆ ExecAssignProjectionInfo()

void ExecAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc 
)

Definition at line 499 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().

501 {
502  planstate->ps_ProjInfo =
504  planstate->ps_ExprContext,
505  planstate->ps_ResultTupleSlot,
506  planstate,
507  inputDesc);
508 }
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:980
ExprContext * ps_ExprContext
Definition: execnodes.h:979
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
Plan * plan
Definition: execnodes.h:940
List * targetlist
Definition: plannodes.h:140
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:351

◆ ExecAssignScanType()

void ExecAssignScanType ( ScanState scanstate,
TupleDesc  tupDesc 
)

Definition at line 634 of file execUtils.c.

References ExecSetSlotDescriptor(), and ScanState::ss_ScanTupleSlot.

Referenced by ExecWorkTableScan().

635 {
636  TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
637 
638  ExecSetSlotDescriptor(slot, tupDesc);
639 }
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1254

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1085 of file execUtils.c.

References lfirst_node, and TargetEntry::resjunk.

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

1086 {
1087  int len = 0;
1088  ListCell *tl;
1089 
1090  foreach(tl, targetlist)
1091  {
1092  TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1093 
1094  if (!curTle->resjunk)
1095  len++;
1096  }
1097  return len;
1098 }
bool resjunk
Definition: primnodes.h:1400
#define lfirst_node(type, lc)
Definition: pg_list.h:193

◆ ExecConditionalAssignProjectionInfo()

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

Definition at line 519 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().

521 {
522  if (tlist_matches_tupdesc(planstate,
523  planstate->plan->targetlist,
524  varno,
525  inputDesc))
526  {
527  planstate->ps_ProjInfo = NULL;
528  planstate->resultopsset = planstate->scanopsset;
529  planstate->resultopsfixed = planstate->scanopsfixed;
530  planstate->resultops = planstate->scanops;
531  }
532  else
533  {
534  if (!planstate->ps_ResultTupleSlot)
535  {
536  ExecInitResultSlot(planstate, &TTSOpsVirtual);
537  planstate->resultops = &TTSOpsVirtual;
538  planstate->resultopsfixed = true;
539  planstate->resultopsset = true;
540  }
541  ExecAssignProjectionInfo(planstate, inputDesc);
542  }
543 }
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:980
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
const TupleTableSlotOps * resultops
Definition: execnodes.h:1015
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
const TupleTableSlotOps * scanops
Definition: execnodes.h:1012
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:499
bool resultopsset
Definition: execnodes.h:1023
Plan * plan
Definition: execnodes.h:940
bool scanopsfixed
Definition: execnodes.h:1016
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1744
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc)
Definition: execUtils.c:546
bool scanopsset
Definition: execnodes.h:1020
List * targetlist
Definition: plannodes.h:140
bool resultopsfixed
Definition: execnodes.h:1019

◆ ExecCreateScanSlotFromOuterPlan()

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

Definition at line 646 of file execUtils.c.

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

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

649 {
651  TupleDesc tupDesc;
652 
653  outerPlan = outerPlanState(scanstate);
654  tupDesc = ExecGetResultType(outerPlan);
655 
656  ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
657 }
#define outerPlanState(node)
Definition: execnodes.h:1034
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1776
#define outerPlan(node)
Definition: plannodes.h:170
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:454

◆ ExecFreeExprContext()

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti 
)

Definition at line 754 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(), ExecOpenScanRelation(), and InitPlan().

755 {
756  Relation rel;
757 
758  Assert(rti > 0 && rti <= estate->es_range_table_size);
759 
760  rel = estate->es_relations[rti - 1];
761  if (rel == NULL)
762  {
763  /* First time through, so open the relation */
764  RangeTblEntry *rte = exec_rt_fetch(rti, estate);
765 
766  Assert(rte->rtekind == RTE_RELATION);
767 
768  if (!IsParallelWorker())
769  {
770  /*
771  * In a normal query, we should already have the appropriate lock,
772  * but verify that through an Assert. Since there's already an
773  * Assert inside table_open that insists on holding some lock, it
774  * seems sufficient to check this only when rellockmode is higher
775  * than the minimum.
776  */
777  rel = table_open(rte->relid, NoLock);
779  CheckRelationLockedByMe(rel, rte->rellockmode, false));
780  }
781  else
782  {
783  /*
784  * If we are a parallel worker, we need to obtain our own local
785  * lock on the relation. This ensures sane behavior in case the
786  * parent process exits before we do.
787  */
788  rel = table_open(rte->relid, rte->rellockmode);
789  }
790 
791  estate->es_relations[rti - 1] = rel;
792  }
793 
794  return rel;
795 }
#define AccessShareLock
Definition: lockdefs.h:36
#define NoLock
Definition: lockdefs.h:34
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:537
#define IsParallelWorker()
Definition: parallel.h:60
#define Assert(condition)
Definition: c.h:732
Relation * es_relations
Definition: execnodes.h:507
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:302
RTEKind rtekind
Definition: parsenodes.h:974
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ ExecGetResultSlotOps()

const TupleTableSlotOps* ExecGetResultSlotOps ( PlanState planstate,
bool isfixed 
)

Definition at line 463 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().

464 {
465  if (planstate->resultopsset && planstate->resultops)
466  {
467  if (isfixed)
468  *isfixed = planstate->resultopsfixed;
469  return planstate->resultops;
470  }
471 
472  if (isfixed)
473  {
474  if (planstate->resultopsset)
475  *isfixed = planstate->resultopsfixed;
476  else if (planstate->ps_ResultTupleSlot)
477  *isfixed = TTS_FIXED(planstate->ps_ResultTupleSlot);
478  else
479  *isfixed = false;
480  }
481 
482  if (!planstate->ps_ResultTupleSlot)
483  return &TTSOpsVirtual;
484 
485  return planstate->ps_ResultTupleSlot->tts_ops;
486 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
const TupleTableSlotOps * resultops
Definition: execnodes.h:1015
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
bool resultopsset
Definition: execnodes.h:1023
bool resultopsfixed
Definition: execnodes.h:1019

◆ ExecGetResultType()

◆ ExecGetReturningSlot()

TupleTableSlot* ExecGetReturningSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1148 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().

1149 {
1150  if (relInfo->ri_ReturningSlot == NULL)
1151  {
1152  Relation rel = relInfo->ri_RelationDesc;
1153  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1154 
1155  relInfo->ri_ReturningSlot =
1156  ExecInitExtraTupleSlot(estate,
1157  RelationGetDescr(rel),
1158  table_slot_callbacks(rel));
1159 
1160  MemoryContextSwitchTo(oldcontext);
1161  }
1162 
1163  return relInfo->ri_ReturningSlot;
1164 }
Relation ri_RelationDesc
Definition: execnodes.h:411
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1796
#define RelationGetDescr(relation)
Definition: rel.h:442
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:44
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext es_query_cxt
Definition: execnodes.h:550
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:435

◆ ExecGetTriggerNewSlot()

TupleTableSlot* ExecGetTriggerNewSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1126 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().

1127 {
1128  if (relInfo->ri_TrigNewSlot == NULL)
1129  {
1130  Relation rel = relInfo->ri_RelationDesc;
1131  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1132 
1133  relInfo->ri_TrigNewSlot =
1134  ExecInitExtraTupleSlot(estate,
1135  RelationGetDescr(rel),
1136  table_slot_callbacks(rel));
1137 
1138  MemoryContextSwitchTo(oldcontext);
1139  }
1140 
1141  return relInfo->ri_TrigNewSlot;
1142 }
Relation ri_RelationDesc
Definition: execnodes.h:411
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1796
#define RelationGetDescr(relation)
Definition: rel.h:442
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:44
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:437
MemoryContext es_query_cxt
Definition: execnodes.h:550

◆ ExecGetTriggerOldSlot()

TupleTableSlot* ExecGetTriggerOldSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1104 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().

1105 {
1106  if (relInfo->ri_TrigOldSlot == NULL)
1107  {
1108  Relation rel = relInfo->ri_RelationDesc;
1109  MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1110 
1111  relInfo->ri_TrigOldSlot =
1112  ExecInitExtraTupleSlot(estate,
1113  RelationGetDescr(rel),
1114  table_slot_callbacks(rel));
1115 
1116  MemoryContextSwitchTo(oldcontext);
1117  }
1118 
1119  return relInfo->ri_TrigOldSlot;
1120 }
Relation ri_RelationDesc
Definition: execnodes.h:411
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1796
#define RelationGetDescr(relation)
Definition: rel.h:442
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:44
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext es_query_cxt
Definition: execnodes.h:550
TupleTableSlot * ri_TrigOldSlot
Definition: execnodes.h:436

◆ ExecInitRangeTable()

void ExecInitRangeTable ( EState estate,
List rangeTable 
)

Definition at line 724 of file execUtils.c.

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

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

725 {
726  /* Remember the range table List as-is */
727  estate->es_range_table = rangeTable;
728 
729  /* Set size of associated arrays */
730  estate->es_range_table_size = list_length(rangeTable);
731 
732  /*
733  * Allocate an array to store an open Relation corresponding to each
734  * rangetable entry, and initialize entries to NULL. Relations are opened
735  * and stored here as needed.
736  */
737  estate->es_relations = (Relation *)
738  palloc0(estate->es_range_table_size * sizeof(Relation));
739 
740  /*
741  * es_rowmarks is also parallel to the es_range_table, but it's allocated
742  * only if needed.
743  */
744  estate->es_rowmarks = NULL;
745 }
List * es_range_table
Definition: execnodes.h:505
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:509
void * palloc0(Size size)
Definition: mcxt.c:955
Relation * es_relations
Definition: execnodes.h:507
static int list_length(const List *l)
Definition: pg_list.h:169
Index es_range_table_size
Definition: execnodes.h:506

◆ ExecOpenScanRelation()

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

Definition at line 693 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().

694 {
695  Relation rel;
696 
697  /* Open the relation. */
698  rel = ExecGetRangeTableRelation(estate, scanrelid);
699 
700  /*
701  * Complain if we're attempting a scan of an unscannable relation, except
702  * when the query won't actually be run. This is a slightly klugy place
703  * to do this, perhaps, but there is no better place.
704  */
705  if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
706  !RelationIsScannable(rel))
707  ereport(ERROR,
708  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
709  errmsg("materialized view \"%s\" has not been populated",
711  errhint("Use the REFRESH MATERIALIZED VIEW command.")));
712 
713  return rel;
714 }
int errhint(const char *fmt,...)
Definition: elog.c:974
#define RelationIsScannable(relation)
Definition: rel.h:557
int errcode(int sqlerrcode)
Definition: elog.c:570
#define EXEC_FLAG_WITH_NO_DATA
Definition: executor.h:61
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:450
#define ereport(elevel, rest)
Definition: elog.h:141
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:754
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:56

◆ ExecRelationIsTargetRelation()

bool ExecRelationIsTargetRelation ( EState estate,
Index  scanrelid 
)

Definition at line 671 of file execUtils.c.

References EState::es_num_result_relations, EState::es_result_relations, and i.

672 {
673  ResultRelInfo *resultRelInfos;
674  int i;
675 
676  resultRelInfos = estate->es_result_relations;
677  for (i = 0; i < estate->es_num_result_relations; i++)
678  {
679  if (resultRelInfos[i].ri_RangeTableIndex == scanrelid)
680  return true;
681  }
682  return false;
683 }
ResultRelInfo * es_result_relations
Definition: execnodes.h:520
int es_num_result_relations
Definition: execnodes.h:521
int i

◆ ExecTargetListLength()

int ExecTargetListLength ( List targetlist)

Definition at line 1075 of file execUtils.c.

References list_length().

Referenced by exec_rt_fetch(), and ExecTypeFromTLInternal().

1076 {
1077  /* This used to be more complex, but fjoins are dead */
1078  return list_length(targetlist);
1079 }
static int list_length(const List *l)
Definition: pg_list.h:169

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 836 of file execUtils.c.

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

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

837 {
838  int pos;
839 
840  /* No-op if location was not provided */
841  if (location < 0)
842  return 0;
843  /* Can't do anything if source text is not available */
844  if (estate == NULL || estate->es_sourceText == NULL)
845  return 0;
846  /* Convert offset to character number */
847  pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
848  /* And pass it to the ereport mechanism */
849  return errposition(pos);
850 }
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:786
const char * es_sourceText
Definition: execnodes.h:512
int errposition(int cursorpos)
Definition: elog.c:1112

◆ FreeExecutorState()

void FreeExecutorState ( EState estate)

Definition at line 190 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_end(), unique_key_recheck(), validateCheckConstraint(), and validateDomainConstraint().

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

◆ FreeExprContext()

void FreeExprContext ( ExprContext econtext,
bool  isCommit 
)

Definition at line 375 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().

376 {
377  EState *estate;
378 
379  /* Call any registered callbacks */
380  ShutdownExprContext(econtext, isCommit);
381  /* And clean up the memory used */
383  /* Unlink self from owning EState, if any */
384  estate = econtext->ecxt_estate;
385  if (estate)
387  econtext);
388  /* And delete the ExprContext node */
389  pfree(econtext);
390 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:793
void pfree(void *pointer)
Definition: mcxt.c:1031
struct EState * ecxt_estate
Definition: execnodes.h:260
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:920
List * es_exprcontexts
Definition: execnodes.h:560

◆ GetAttributeByName()

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

Definition at line 961 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().

962 {
963  AttrNumber attrno;
964  Datum result;
965  Oid tupType;
966  int32 tupTypmod;
967  TupleDesc tupDesc;
968  HeapTupleData tmptup;
969  int i;
970 
971  if (attname == NULL)
972  elog(ERROR, "invalid attribute name");
973 
974  if (isNull == NULL)
975  elog(ERROR, "a NULL isNull pointer was passed");
976 
977  if (tuple == NULL)
978  {
979  /* Kinda bogus but compatible with old behavior... */
980  *isNull = true;
981  return (Datum) 0;
982  }
983 
984  tupType = HeapTupleHeaderGetTypeId(tuple);
985  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
986  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
987 
988  attrno = InvalidAttrNumber;
989  for (i = 0; i < tupDesc->natts; i++)
990  {
991  Form_pg_attribute att = TupleDescAttr(tupDesc, i);
992 
993  if (namestrcmp(&(att->attname), attname) == 0)
994  {
995  attrno = att->attnum;
996  break;
997  }
998  }
999 
1000  if (attrno == InvalidAttrNumber)
1001  elog(ERROR, "attribute \"%s\" does not exist", attname);
1002 
1003  /*
1004  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1005  * the fields in the struct just in case user tries to inspect system
1006  * columns.
1007  */
1008  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1009  ItemPointerSetInvalid(&(tmptup.t_self));
1010  tmptup.t_tableOid = InvalidOid;
1011  tmptup.t_data = tuple;
1012 
1013  result = heap_getattr(&tmptup,
1014  attrno,
1015  tupDesc,
1016  isNull);
1017 
1018  ReleaseTupleDesc(tupDesc);
1019 
1020  return result;
1021 }
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1652
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
int namestrcmp(Name name, const char *str)
Definition: name.c:287
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:346
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:200
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:226
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 1024 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().

1027 {
1028  Datum result;
1029  Oid tupType;
1030  int32 tupTypmod;
1031  TupleDesc tupDesc;
1032  HeapTupleData tmptup;
1033 
1034  if (!AttributeNumberIsValid(attrno))
1035  elog(ERROR, "invalid attribute number %d", attrno);
1036 
1037  if (isNull == NULL)
1038  elog(ERROR, "a NULL isNull pointer was passed");
1039 
1040  if (tuple == NULL)
1041  {
1042  /* Kinda bogus but compatible with old behavior... */
1043  *isNull = true;
1044  return (Datum) 0;
1045  }
1046 
1047  tupType = HeapTupleHeaderGetTypeId(tuple);
1048  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1049  tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1050 
1051  /*
1052  * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1053  * the fields in the struct just in case user tries to inspect system
1054  * columns.
1055  */
1056  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1057  ItemPointerSetInvalid(&(tmptup.t_self));
1058  tmptup.t_tableOid = InvalidOid;
1059  tmptup.t_data = tuple;
1060 
1061  result = heap_getattr(&tmptup,
1062  attrno,
1063  tupDesc,
1064  isNull);
1065 
1066  ReleaseTupleDesc(tupDesc);
1067 
1068  return result;
1069 }
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1652
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:346
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:226
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452

◆ MakePerTupleExprContext()

ExprContext* MakePerTupleExprContext ( EState estate)

Definition at line 417 of file execUtils.c.

References CreateExprContext(), and EState::es_per_tuple_exprcontext.

418 {
419  if (estate->es_per_tuple_exprcontext == NULL)
421 
422  return estate->es_per_tuple_exprcontext;
423 }
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:571
ExprContext * CreateExprContext(EState *estate)
Definition: execUtils.c:244

◆ RegisterExprContextCallback()

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

Definition at line 863 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().

866 {
867  ExprContext_CB *ecxt_callback;
868 
869  /* Save the info in appropriate memory context */
870  ecxt_callback = (ExprContext_CB *)
872  sizeof(ExprContext_CB));
873 
874  ecxt_callback->function = function;
875  ecxt_callback->arg = arg;
876 
877  /* link to front of list for appropriate execution order */
878  ecxt_callback->next = econtext->ecxt_callbacks;
879  econtext->ecxt_callbacks = ecxt_callback;
880 }
ExprContextCallbackFunction function
Definition: execnodes.h:191
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:263
struct ExprContext_CB * next
Definition: execnodes.h:190
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
void * arg

◆ ReScanExprContext()

void ReScanExprContext ( ExprContext econtext)

Definition at line 402 of file execUtils.c.

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

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

403 {
404  /* Call any registered callbacks */
405  ShutdownExprContext(econtext, true);
406  /* And clean up the memory used */
408 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:136
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:920

◆ ShutdownExprContext()

static void ShutdownExprContext ( ExprContext econtext,
bool  isCommit 
)
static

Definition at line 920 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().

921 {
922  ExprContext_CB *ecxt_callback;
923  MemoryContext oldcontext;
924 
925  /* Fast path in normal case where there's nothing to do. */
926  if (econtext->ecxt_callbacks == NULL)
927  return;
928 
929  /*
930  * Call the callbacks in econtext's per-tuple context. This ensures that
931  * any memory they might leak will get cleaned up.
932  */
933  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
934 
935  /*
936  * Call each callback function in reverse registration order.
937  */
938  while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
939  {
940  econtext->ecxt_callbacks = ecxt_callback->next;
941  if (isCommit)
942  ecxt_callback->function(ecxt_callback->arg);
943  pfree(ecxt_callback);
944  }
945 
946  MemoryContextSwitchTo(oldcontext);
947 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void pfree(void *pointer)
Definition: mcxt.c:1031
ExprContextCallbackFunction function
Definition: execnodes.h:191
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:263
struct ExprContext_CB * next
Definition: execnodes.h:190

◆ tlist_matches_tupdesc()

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

Definition at line 546 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().

547 {
548  int numattrs = tupdesc->natts;
549  int attrno;
550  ListCell *tlist_item = list_head(tlist);
551 
552  /* Check the tlist attributes */
553  for (attrno = 1; attrno <= numattrs; attrno++)
554  {
555  Form_pg_attribute att_tup = TupleDescAttr(tupdesc, attrno - 1);
556  Var *var;
557 
558  if (tlist_item == NULL)
559  return false; /* tlist too short */
560  var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr;
561  if (!var || !IsA(var, Var))
562  return false; /* tlist item not a Var */
563  /* if these Asserts fail, planner messed up */
564  Assert(var->varno == varno);
565  Assert(var->varlevelsup == 0);
566  if (var->varattno != attrno)
567  return false; /* out of order */
568  if (att_tup->attisdropped)
569  return false; /* table contains dropped columns */
570  if (att_tup->atthasmissing)
571  return false; /* table contains cols with missing values */
572 
573  /*
574  * Note: usually the Var's type should match the tupdesc exactly, but
575  * in situations involving unions of columns that have different
576  * typmods, the Var may have come from above the union and hence have
577  * typmod -1. This is a legitimate situation since the Var still
578  * describes the column, just not as exactly as the tupdesc does. We
579  * could change the planner to prevent it, but it'd then insert
580  * projection steps just to convert from specific typmod to typmod -1,
581  * which is pretty silly.
582  */
583  if (var->vartype != att_tup->atttypid ||
584  (var->vartypmod != att_tup->atttypmod &&
585  var->vartypmod != -1))
586  return false; /* type mismatch */
587 
588  tlist_item = lnext(tlist, tlist_item);
589  }
590 
591  if (tlist_item)
592  return false; /* tlist too long */
593 
594  return true;
595 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Index varlevelsup
Definition: primnodes.h:177
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:321
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
AttrNumber varattno
Definition: primnodes.h:172
Definition: primnodes.h:167
Oid vartype
Definition: primnodes.h:174
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
Index varno
Definition: primnodes.h:170
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
int32 vartypmod
Definition: primnodes.h:175

◆ UnregisterExprContextCallback()

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

Definition at line 889 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().

892 {
893  ExprContext_CB **prev_callback;
894  ExprContext_CB *ecxt_callback;
895 
896  prev_callback = &econtext->ecxt_callbacks;
897 
898  while ((ecxt_callback = *prev_callback) != NULL)
899  {
900  if (ecxt_callback->function == function && ecxt_callback->arg == arg)
901  {
902  *prev_callback = ecxt_callback->next;
903  pfree(ecxt_callback);
904  }
905  else
906  prev_callback = &ecxt_callback->next;
907  }
908 }
void pfree(void *pointer)
Definition: mcxt.c:1031
ExprContextCallbackFunction function
Definition: execnodes.h:191
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:263
struct ExprContext_CB * next
Definition: execnodes.h:190
void * arg

◆ UpdateChangedParamSet()

void UpdateChangedParamSet ( PlanState node,
Bitmapset newchg 
)

Definition at line 802 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().

803 {
804  Bitmapset *parmset;
805 
806  /*
807  * The plan node only depends on params listed in its allParam set. Don't
808  * include anything else into its chgParam set.
809  */
810  parmset = bms_intersect(node->plan->allParam, newchg);
811 
812  /*
813  * Keep node->chgParam == NULL if there's not actually any members; this
814  * allows the simplest possible tests in executor node files.
815  */
816  if (!bms_is_empty(parmset))
817  node->chgParam = bms_join(node->chgParam, parmset);
818  else
819  bms_free(parmset);
820 }
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:949
Bitmapset * allParam
Definition: plannodes.h:159
Bitmapset * chgParam
Definition: execnodes.h:972
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:940
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208