PostgreSQL Source Code git master
Loading...
Searching...
No Matches
execUtils.c File Reference
#include "postgres.h"
#include "access/parallel.h"
#include "access/table.h"
#include "access/tableam.h"
#include "access/tupconvert.h"
#include "executor/executor.h"
#include "executor/nodeModifyTable.h"
#include "jit/jit.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "parser/parse_relation.h"
#include "partitioning/partdesc.h"
#include "port/pg_bitutils.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/typcache.h"
Include dependency graph for execUtils.c:

Go to the source code of this file.

Functions

static bool tlist_matches_tupdesc (PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
 
static void ShutdownExprContext (ExprContext *econtext, bool isCommit)
 
static RTEPermissionInfoGetResultRTEPermissionInfo (ResultRelInfo *relinfo, EState *estate)
 
EStateCreateExecutorState (void)
 
void FreeExecutorState (EState *estate)
 
static ExprContextCreateExprContextInternal (EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
 
ExprContextCreateExprContext (EState *estate)
 
ExprContextCreateWorkExprContext (EState *estate)
 
ExprContextCreateStandaloneExprContext (void)
 
void FreeExprContext (ExprContext *econtext, bool isCommit)
 
void ReScanExprContext (ExprContext *econtext)
 
ExprContextMakePerTupleExprContext (EState *estate)
 
void ExecAssignExprContext (EState *estate, PlanState *planstate)
 
TupleDesc ExecGetResultType (PlanState *planstate)
 
const TupleTableSlotOpsExecGetResultSlotOps (PlanState *planstate, bool *isfixed)
 
const TupleTableSlotOpsExecGetCommonSlotOps (PlanState **planstates, int nplans)
 
const TupleTableSlotOpsExecGetCommonChildSlotOps (PlanState *ps)
 
void ExecAssignProjectionInfo (PlanState *planstate, TupleDesc inputDesc)
 
void ExecConditionalAssignProjectionInfo (PlanState *planstate, TupleDesc inputDesc, int varno)
 
void ExecAssignScanType (ScanState *scanstate, TupleDesc tupDesc)
 
void ExecCreateScanSlotFromOuterPlan (EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
 
bool ExecRelationIsTargetRelation (EState *estate, Index scanrelid)
 
bool ScanRelIsReadOnly (ScanState *ss)
 
Relation ExecOpenScanRelation (EState *estate, Index scanrelid, int eflags)
 
void ExecInitRangeTable (EState *estate, List *rangeTable, List *permInfos, Bitmapset *unpruned_relids)
 
Relation ExecGetRangeTableRelation (EState *estate, Index rti, bool isResultRel)
 
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)
 
TupleTableSlotExecGetAllNullSlot (EState *estate, ResultRelInfo *relInfo)
 
TupleConversionMapExecGetChildToRootMap (ResultRelInfo *resultRelInfo)
 
TupleConversionMapExecGetRootToChildMap (ResultRelInfo *resultRelInfo, EState *estate)
 
BitmapsetExecGetInsertedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetExtraUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
BitmapsetExecGetAllUpdatedCols (ResultRelInfo *relinfo, EState *estate)
 
Oid ExecGetResultRelCheckAsUser (ResultRelInfo *relInfo, EState *estate)
 

Function Documentation

◆ CreateExecutorState()

EState * CreateExecutorState ( void  )

Definition at line 90 of file execUtils.c.

91{
92 EState *estate;
93 MemoryContext qcontext;
94 MemoryContext oldcontext;
95
96 /*
97 * Create the per-query context for this Executor run.
98 */
100 "ExecutorState",
102
103 /*
104 * Make the EState node within the per-query context. This way, we don't
105 * need a separate pfree() operation for it at shutdown.
106 */
107 oldcontext = MemoryContextSwitchTo(qcontext);
108
109 estate = makeNode(EState);
110
111 /*
112 * Initialize all fields of the Executor State structure
113 */
115 estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
116 estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
117 estate->es_range_table = NIL;
118 estate->es_range_table_size = 0;
119 estate->es_relations = NULL;
120 estate->es_rowmarks = NULL;
121 estate->es_rteperminfos = NIL;
122 estate->es_plannedstmt = NULL;
123 estate->es_part_prune_infos = NIL;
124 estate->es_part_prune_states = NIL;
125 estate->es_part_prune_results = NIL;
126 estate->es_unpruned_relids = NULL;
127
128 estate->es_junkFilter = NULL;
129
130 estate->es_output_cid = (CommandId) 0;
131
132 estate->es_result_relations = NULL;
136
139
140 estate->es_param_list_info = NULL;
141 estate->es_param_exec_vals = NULL;
142
143 estate->es_queryEnv = NULL;
144
145 estate->es_query_cxt = qcontext;
146
147 estate->es_tupleTable = NIL;
148
149 estate->es_processed = 0;
150 estate->es_total_processed = 0;
151
152 estate->es_top_eflags = 0;
153 estate->es_instrument = 0;
154 estate->es_finished = false;
155
156 estate->es_exprcontexts = NIL;
157
158 estate->es_subplanstates = NIL;
159
160 estate->es_auxmodifytables = NIL;
161
163
164 estate->es_sourceText = NULL;
165
166 estate->es_use_parallel_mode = false;
169
170 estate->es_jit_flags = 0;
171 estate->es_jit = NULL;
172
173 /*
174 * Return the executor state structure
175 */
176 MemoryContextSwitchTo(oldcontext);
177
178 return estate;
179}
uint32 CommandId
Definition c.h:750
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define makeNode(_type_)
Definition nodes.h:161
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define NIL
Definition pg_list.h:68
static int fb(int x)
@ ForwardScanDirection
Definition sdir.h:28
#define InvalidSnapshot
Definition snapshot.h:119
uint64 es_processed
Definition execnodes.h:750
List * es_part_prune_infos
Definition execnodes.h:706
int es_parallel_workers_to_launch
Definition execnodes.h:782
List * es_tuple_routing_result_relations
Definition execnodes.h:734
int es_top_eflags
Definition execnodes.h:755
struct JitContext * es_jit
Definition execnodes.h:800
int es_instrument
Definition execnodes.h:756
PlannedStmt * es_plannedstmt
Definition execnodes.h:705
QueryEnvironment * es_queryEnv
Definition execnodes.h:743
ResultRelInfo ** es_result_relations
Definition execnodes.h:721
ParamExecData * es_param_exec_vals
Definition execnodes.h:741
uint64 es_total_processed
Definition execnodes.h:752
List * es_range_table
Definition execnodes.h:698
List * es_rteperminfos
Definition execnodes.h:704
Bitmapset * es_unpruned_relids
Definition execnodes.h:709
List * es_part_prune_states
Definition execnodes.h:707
List * es_exprcontexts
Definition execnodes.h:759
ParamListInfo es_param_list_info
Definition execnodes.h:740
ExecRowMark ** es_rowmarks
Definition execnodes.h:702
bool es_finished
Definition execnodes.h:757
List * es_insert_pending_result_relations
Definition execnodes.h:807
MemoryContext es_query_cxt
Definition execnodes.h:746
List * es_tupleTable
Definition execnodes.h:748
ScanDirection es_direction
Definition execnodes.h:695
List * es_trig_target_relations
Definition execnodes.h:737
int es_jit_flags
Definition execnodes.h:799
List * es_opened_result_relations
Definition execnodes.h:724
bool es_use_parallel_mode
Definition execnodes.h:780
Relation * es_relations
Definition execnodes.h:700
List * es_subplanstates
Definition execnodes.h:761
ExprContext * es_per_tuple_exprcontext
Definition execnodes.h:770
int es_parallel_workers_launched
Definition execnodes.h:784
CommandId es_output_cid
Definition execnodes.h:718
Index es_range_table_size
Definition execnodes.h:699
List * es_insert_pending_modifytables
Definition execnodes.h:808
const char * es_sourceText
Definition execnodes.h:713
Snapshot es_snapshot
Definition execnodes.h:696
List * es_auxmodifytables
Definition execnodes.h:763
JunkFilter * es_junkFilter
Definition execnodes.h:715
List * es_part_prune_results
Definition execnodes.h:708
Snapshot es_crosscheck_snapshot
Definition execnodes.h:697

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

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

◆ CreateExprContext()

ExprContext * CreateExprContext ( EState estate)

Definition at line 312 of file execUtils.c.

313{
315}
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition execUtils.c:242

References ALLOCSET_DEFAULT_SIZES, and CreateExprContextInternal().

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

◆ CreateExprContextInternal()

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

Definition at line 242 of file execUtils.c.

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

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, fb(), lcons(), makeNode, and MemoryContextSwitchTo().

Referenced by CreateExprContext(), and CreateWorkExprContext().

◆ CreateStandaloneExprContext()

ExprContext * CreateStandaloneExprContext ( void  )

Definition at line 362 of file execUtils.c.

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

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, fb(), and makeNode.

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

◆ CreateWorkExprContext()

ExprContext * CreateWorkExprContext ( EState estate)

Definition at line 327 of file execUtils.c.

328{
329 Size maxBlockSize;
330
331 maxBlockSize = pg_prevpower2_size_t(work_mem * (Size) 1024 / 16);
332
333 /* But no bigger than ALLOCSET_DEFAULT_MAXSIZE */
334 maxBlockSize = Min(maxBlockSize, ALLOCSET_DEFAULT_MAXSIZE);
335
336 /* and no smaller than ALLOCSET_DEFAULT_INITSIZE */
337 maxBlockSize = Max(maxBlockSize, ALLOCSET_DEFAULT_INITSIZE);
338
340 ALLOCSET_DEFAULT_INITSIZE, maxBlockSize);
341}
#define Min(x, y)
Definition c.h:1091
#define Max(x, y)
Definition c.h:1085
size_t Size
Definition c.h:689
int work_mem
Definition globals.c:133
#define ALLOCSET_DEFAULT_MAXSIZE
Definition memutils.h:159
#define ALLOCSET_DEFAULT_MINSIZE
Definition memutils.h:157
#define ALLOCSET_DEFAULT_INITSIZE
Definition memutils.h:158
#define pg_prevpower2_size_t

References ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE, ALLOCSET_DEFAULT_MINSIZE, CreateExprContextInternal(), Max, Min, pg_prevpower2_size_t, and work_mem.

Referenced by hash_create_memory().

◆ ExecAssignExprContext()

◆ ExecAssignProjectionInfo()

void ExecAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc 
)

Definition at line 588 of file execUtils.c.

590{
591 planstate->ps_ProjInfo =
593 planstate->ps_ExprContext,
594 planstate->ps_ResultTupleSlot,
595 planstate,
596 inputDesc);
597}
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition execExpr.c:391
Plan * plan
Definition execnodes.h:1201
TupleTableSlot * ps_ResultTupleSlot
Definition execnodes.h:1241
ProjectionInfo * ps_ProjInfo
Definition execnodes.h:1243
List * targetlist
Definition plannodes.h:235

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

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

◆ ExecAssignScanType()

void ExecAssignScanType ( ScanState scanstate,
TupleDesc  tupDesc 
)

Definition at line 697 of file execUtils.c.

698{
699 TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
700
701 ExecSetSlotDescriptor(slot, tupDesc);
702}
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)

References ExecSetSlotDescriptor(), and fb().

Referenced by ExecWorkTableScan().

◆ ExecCleanTargetListLength()

int ExecCleanTargetListLength ( List targetlist)

Definition at line 1211 of file execUtils.c.

1212{
1213 int len = 0;
1214 ListCell *tl;
1215
1216 foreach(tl, targetlist)
1217 {
1219
1220 if (!curTle->resjunk)
1221 len++;
1222 }
1223 return len;
1224}
const void size_t len
#define lfirst_node(type, lc)
Definition pg_list.h:176

References fb(), len, and lfirst_node.

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

◆ ExecConditionalAssignProjectionInfo()

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

Definition at line 608 of file execUtils.c.

610{
611 if (tlist_matches_tupdesc(planstate,
612 planstate->plan->targetlist,
613 varno,
614 inputDesc))
615 {
616 planstate->ps_ProjInfo = NULL;
617 planstate->resultopsset = planstate->scanopsset;
618 planstate->resultopsfixed = planstate->scanopsfixed;
619 planstate->resultops = planstate->scanops;
620 }
621 else
622 {
623 if (!planstate->ps_ResultTupleSlot)
624 {
626 planstate->resultops = &TTSOpsVirtual;
627 planstate->resultopsfixed = true;
628 planstate->resultopsset = true;
629 }
631 }
632}
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
Definition execUtils.c:635
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition execUtils.c:588
const TupleTableSlotOps * resultops
Definition execnodes.h:1280
bool resultopsset
Definition execnodes.h:1288
const TupleTableSlotOps * scanops
Definition execnodes.h:1277
bool scanopsset
Definition execnodes.h:1285
bool scanopsfixed
Definition execnodes.h:1281
bool resultopsfixed
Definition execnodes.h:1284

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

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

◆ ExecCreateScanSlotFromOuterPlan()

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

Definition at line 709 of file execUtils.c.

712{
714 TupleDesc tupDesc;
715
717 tupDesc = ExecGetResultType(outerPlan);
718
719 ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops, 0);
720}
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops, uint16 flags)
TupleDesc ExecGetResultType(PlanState *planstate)
Definition execUtils.c:500
#define outerPlanState(node)
Definition execnodes.h:1299
#define outerPlan(node)
Definition plannodes.h:267

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

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

◆ ExecGetAllNullSlot()

TupleTableSlot * ExecGetAllNullSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1299 of file execUtils.c.

1300{
1301 if (relInfo->ri_AllNullSlot == NULL)
1302 {
1303 Relation rel = relInfo->ri_RelationDesc;
1304 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1305 TupleTableSlot *slot;
1306
1307 slot = ExecInitExtraTupleSlot(estate,
1308 RelationGetDescr(rel),
1311
1312 relInfo->ri_AllNullSlot = slot;
1313
1314 MemoryContextSwitchTo(oldcontext);
1315 }
1316
1317 return relInfo->ri_AllNullSlot;
1318}
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
#define RelationGetDescr(relation)
Definition rel.h:542
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition tableam.c:59

References EState::es_query_cxt, ExecInitExtraTupleSlot(), ExecStoreAllNullTuple(), fb(), MemoryContextSwitchTo(), RelationGetDescr, and table_slot_callbacks().

Referenced by ExecProcessReturning().

◆ ExecGetAllUpdatedCols()

Bitmapset * ExecGetAllUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1444 of file execUtils.c.

1445{
1446 Bitmapset *ret;
1448
1450
1451 ret = bms_union(ExecGetUpdatedCols(relinfo, estate),
1453
1455
1456 return ret;
1457}
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:251
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition execUtils.c:1429
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition execUtils.c:1408
#define GetPerTupleMemoryContext(estate)
Definition executor.h:672

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

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

◆ ExecGetChildToRootMap()

TupleConversionMap * ExecGetChildToRootMap ( ResultRelInfo resultRelInfo)

Definition at line 1326 of file execUtils.c.

1327{
1328 /* If we didn't already do so, compute the map for this child. */
1329 if (!resultRelInfo->ri_ChildToRootMapValid)
1330 {
1332
1333 if (rootRelInfo)
1334 resultRelInfo->ri_ChildToRootMap =
1336 RelationGetDescr(rootRelInfo->ri_RelationDesc));
1337 else /* this isn't a child result rel */
1338 resultRelInfo->ri_ChildToRootMap = NULL;
1339
1340 resultRelInfo->ri_ChildToRootMapValid = true;
1341 }
1342
1343 return resultRelInfo->ri_ChildToRootMap;
1344}
struct ResultRelInfo * ri_RootResultRelInfo
Definition execnodes.h:654
Relation ri_RelationDesc
Definition execnodes.h:513
TupleConversionMap * ri_ChildToRootMap
Definition execnodes.h:636
bool ri_ChildToRootMapValid
Definition execnodes.h:637
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition tupconvert.c:103

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

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

◆ ExecGetCommonChildSlotOps()

const TupleTableSlotOps * ExecGetCommonChildSlotOps ( PlanState ps)

Definition at line 568 of file execUtils.c.

569{
571
575}
const TupleTableSlotOps * ExecGetCommonSlotOps(PlanState **planstates, int nplans)
Definition execUtils.c:541
#define innerPlanState(node)
Definition execnodes.h:1298
struct parser_state ps

References ExecGetCommonSlotOps(), fb(), innerPlanState, outerPlanState, and ps.

Referenced by build_hash_table(), and build_hash_table().

◆ ExecGetCommonSlotOps()

const TupleTableSlotOps * ExecGetCommonSlotOps ( PlanState **  planstates,
int  nplans 
)

Definition at line 541 of file execUtils.c.

542{
544 bool isfixed;
545
546 if (nplans <= 0)
547 return NULL;
548 result = ExecGetResultSlotOps(planstates[0], &isfixed);
549 if (!isfixed)
550 return NULL;
551 for (int i = 1; i < nplans; i++)
552 {
554
556 if (!isfixed)
557 return NULL;
558 if (result != thisops)
559 return NULL;
560 }
561 return result;
562}
uint32 result
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition execUtils.c:509
int i
Definition isn.c:77

References ExecGetResultSlotOps(), fb(), i, and result.

Referenced by ExecGetCommonChildSlotOps(), ExecInitAppend(), and ExecInitMergeAppend().

◆ ExecGetExtraUpdatedCols()

Bitmapset * ExecGetExtraUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1429 of file execUtils.c.

1430{
1431 /* Compute the info if we didn't already */
1432 if (!relinfo->ri_extraUpdatedCols_valid)
1434 return relinfo->ri_extraUpdatedCols;
1435}
void ExecInitGenerated(ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
@ CMD_UPDATE
Definition nodes.h:276

References CMD_UPDATE, ExecInitGenerated(), and fb().

Referenced by ExecGetAllUpdatedCols(), and index_unchanged_by_update().

◆ ExecGetInsertedCols()

Bitmapset * ExecGetInsertedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1387 of file execUtils.c.

1388{
1390
1391 if (perminfo == NULL)
1392 return NULL;
1393
1394 /* Map the columns to child's attribute numbers if needed. */
1395 if (relinfo->ri_RootResultRelInfo)
1396 {
1398
1399 if (map)
1400 return execute_attr_map_cols(map->attrMap, perminfo->insertedCols);
1401 }
1402
1403 return perminfo->insertedCols;
1404}
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition execUtils.c:1352
static RTEPermissionInfo * GetResultRTEPermissionInfo(ResultRelInfo *relinfo, EState *estate)
Definition execUtils.c:1464
AttrMap * attrMap
Definition tupconvert.h:28
Bitmapset * execute_attr_map_cols(AttrMap *attrMap, Bitmapset *in_cols)
Definition tupconvert.c:253

References TupleConversionMap::attrMap, ExecGetRootToChildMap(), execute_attr_map_cols(), fb(), and GetResultRTEPermissionInfo().

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

◆ ExecGetRangeTableRelation()

Relation ExecGetRangeTableRelation ( EState estate,
Index  rti,
bool  isResultRel 
)

Definition at line 851 of file execUtils.c.

852{
853 Relation rel;
854
855 Assert(rti > 0 && rti <= estate->es_range_table_size);
856
857 if (!isResultRel && !bms_is_member(rti, estate->es_unpruned_relids))
858 elog(ERROR, "trying to open a pruned relation");
859
860 rel = estate->es_relations[rti - 1];
861 if (rel == NULL)
862 {
863 /* First time through, so open the relation */
864 RangeTblEntry *rte = exec_rt_fetch(rti, estate);
865
866 Assert(rte->rtekind == RTE_RELATION);
867
868 if (!IsParallelWorker())
869 {
870 /*
871 * In a normal query, we should already have the appropriate lock,
872 * but verify that through an Assert. Since there's already an
873 * Assert inside table_open that insists on holding some lock, it
874 * seems sufficient to check this only when rellockmode is higher
875 * than the minimum.
876 */
877 rel = table_open(rte->relid, NoLock);
878 Assert(rte->rellockmode == AccessShareLock ||
879 CheckRelationLockedByMe(rel, rte->rellockmode, false));
880 }
881 else
882 {
883 /*
884 * If we are a parallel worker, we need to obtain our own local
885 * lock on the relation. This ensures sane behavior in case the
886 * parent process exits before we do.
887 */
888 rel = table_open(rte->relid, rte->rellockmode);
889 }
890
891 estate->es_relations[rti - 1] = rel;
892 }
893
894 return rel;
895}
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:510
#define Assert(condition)
Definition c.h:943
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition executor.h:710
#define IsParallelWorker()
Definition parallel.h:62
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition lmgr.c:334
#define NoLock
Definition lockdefs.h:34
#define AccessShareLock
Definition lockdefs.h:36
@ RTE_RELATION
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References AccessShareLock, Assert, bms_is_member(), CheckRelationLockedByMe(), elog, ERROR, EState::es_relations, EState::es_unpruned_relids, exec_rt_fetch(), fb(), IsParallelWorker, NoLock, RTE_RELATION, and table_open().

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

◆ ExecGetResultRelCheckAsUser()

Oid ExecGetResultRelCheckAsUser ( ResultRelInfo relInfo,
EState estate 
)

Definition at line 1515 of file execUtils.c.

1516{
1518
1519 /* XXX - maybe ok to return GetUserId() in this case? */
1520 if (perminfo == NULL)
1521 elog(ERROR, "no RTEPermissionInfo found for result relation with OID %u",
1522 RelationGetRelid(relInfo->ri_RelationDesc));
1523
1524 return perminfo->checkAsUser ? perminfo->checkAsUser : GetUserId();
1525}
Oid GetUserId(void)
Definition miscinit.c:470
#define RelationGetRelid(relation)
Definition rel.h:516

References elog, ERROR, fb(), GetResultRTEPermissionInfo(), GetUserId(), and RelationGetRelid.

Referenced by create_foreign_modify().

◆ ExecGetResultSlotOps()

const TupleTableSlotOps * ExecGetResultSlotOps ( PlanState planstate,
bool isfixed 
)

Definition at line 509 of file execUtils.c.

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

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

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

◆ ExecGetResultType()

◆ ExecGetReturningSlot()

TupleTableSlot * ExecGetReturningSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1274 of file execUtils.c.

1275{
1276 if (relInfo->ri_ReturningSlot == NULL)
1277 {
1278 Relation rel = relInfo->ri_RelationDesc;
1279 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1280
1281 relInfo->ri_ReturningSlot =
1283 RelationGetDescr(rel),
1285
1286 MemoryContextSwitchTo(oldcontext);
1287 }
1288
1289 return relInfo->ri_ReturningSlot;
1290}

References EState::es_query_cxt, ExecInitExtraTupleSlot(), fb(), MemoryContextSwitchTo(), RelationGetDescr, and table_slot_callbacks().

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

◆ ExecGetRootToChildMap()

TupleConversionMap * ExecGetRootToChildMap ( ResultRelInfo resultRelInfo,
EState estate 
)

Definition at line 1352 of file execUtils.c.

1353{
1354 /* Mustn't get called for a non-child result relation. */
1355 Assert(resultRelInfo->ri_RootResultRelInfo);
1356
1357 /* If we didn't already do so, compute the map for this child. */
1358 if (!resultRelInfo->ri_RootToChildMapValid)
1359 {
1361 TupleDesc indesc = RelationGetDescr(rootRelInfo->ri_RelationDesc);
1362 TupleDesc outdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
1363 Relation childrel = resultRelInfo->ri_RelationDesc;
1364 AttrMap *attrMap;
1365 MemoryContext oldcontext;
1366
1367 /*
1368 * When this child table is not a partition (!relispartition), it may
1369 * have columns that are not present in the root table, which we ask
1370 * to ignore by passing true for missing_ok.
1371 */
1372 oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1373 attrMap = build_attrmap_by_name_if_req(indesc, outdesc,
1374 !childrel->rd_rel->relispartition);
1375 if (attrMap)
1376 resultRelInfo->ri_RootToChildMap =
1377 convert_tuples_by_name_attrmap(indesc, outdesc, attrMap);
1378 MemoryContextSwitchTo(oldcontext);
1379 resultRelInfo->ri_RootToChildMapValid = true;
1380 }
1381
1382 return resultRelInfo->ri_RootToChildMap;
1383}
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
Definition attmap.c:261
TupleConversionMap * ri_RootToChildMap
Definition execnodes.h:642
bool ri_RootToChildMapValid
Definition execnodes.h:643
TupleConversionMap * convert_tuples_by_name_attrmap(TupleDesc indesc, TupleDesc outdesc, AttrMap *attrMap)
Definition tupconvert.c:125

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

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

◆ ExecGetTriggerNewSlot()

TupleTableSlot * ExecGetTriggerNewSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1252 of file execUtils.c.

1253{
1254 if (relInfo->ri_TrigNewSlot == NULL)
1255 {
1256 Relation rel = relInfo->ri_RelationDesc;
1257 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1258
1259 relInfo->ri_TrigNewSlot =
1261 RelationGetDescr(rel),
1263
1264 MemoryContextSwitchTo(oldcontext);
1265 }
1266
1267 return relInfo->ri_TrigNewSlot;
1268}

References EState::es_query_cxt, ExecInitExtraTupleSlot(), fb(), MemoryContextSwitchTo(), RelationGetDescr, and table_slot_callbacks().

Referenced by AfterTriggerExecute(), and AfterTriggerSaveEvent().

◆ ExecGetTriggerOldSlot()

TupleTableSlot * ExecGetTriggerOldSlot ( EState estate,
ResultRelInfo relInfo 
)

Definition at line 1230 of file execUtils.c.

1231{
1232 if (relInfo->ri_TrigOldSlot == NULL)
1233 {
1234 Relation rel = relInfo->ri_RelationDesc;
1235 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1236
1237 relInfo->ri_TrigOldSlot =
1239 RelationGetDescr(rel),
1241
1242 MemoryContextSwitchTo(oldcontext);
1243 }
1244
1245 return relInfo->ri_TrigOldSlot;
1246}

References EState::es_query_cxt, ExecInitExtraTupleSlot(), fb(), MemoryContextSwitchTo(), RelationGetDescr, and table_slot_callbacks().

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

◆ ExecGetUpdatedCols()

Bitmapset * ExecGetUpdatedCols ( ResultRelInfo relinfo,
EState estate 
)

Definition at line 1408 of file execUtils.c.

1409{
1411
1412 if (perminfo == NULL)
1413 return NULL;
1414
1415 /* Map the columns to child's attribute numbers if needed. */
1416 if (relinfo->ri_RootResultRelInfo)
1417 {
1419
1420 if (map)
1421 return execute_attr_map_cols(map->attrMap, perminfo->updatedCols);
1422 }
1423
1424 return perminfo->updatedCols;
1425}

References TupleConversionMap::attrMap, ExecGetRootToChildMap(), execute_attr_map_cols(), fb(), and GetResultRTEPermissionInfo().

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

◆ ExecInitRangeTable()

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

Definition at line 799 of file execUtils.c.

801{
802 /* Remember the range table List as-is */
803 estate->es_range_table = rangeTable;
804
805 /* ... and the RTEPermissionInfo List too */
806 estate->es_rteperminfos = permInfos;
807
808 /* Set size of associated arrays */
810
811 /*
812 * Initialize the bitmapset of RT indexes (es_unpruned_relids)
813 * representing relations that will be scanned during execution. This set
814 * is initially populated by the caller and may be extended later by
815 * ExecDoInitialPruning() to include RT indexes of unpruned leaf
816 * partitions.
817 */
819
820 /*
821 * Allocate an array to store an open Relation corresponding to each
822 * rangetable entry, and initialize entries to NULL. Relations are opened
823 * and stored here as needed.
824 */
825 estate->es_relations = (Relation *)
826 palloc0(estate->es_range_table_size * sizeof(Relation));
827
828 /*
829 * es_result_relations and es_rowmarks are also parallel to
830 * es_range_table, but are allocated only if needed.
831 */
832 estate->es_result_relations = NULL;
833 estate->es_rowmarks = NULL;
834}
void * palloc0(Size size)
Definition mcxt.c:1417
static int list_length(const List *l)
Definition pg_list.h:152

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

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

◆ ExecInitResultRelation()

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

Definition at line 906 of file execUtils.c.

908{
910
912 InitResultRelInfo(resultRelInfo,
914 rti,
915 NULL,
916 estate->es_instrument);
917
918 if (estate->es_result_relations == NULL)
920 palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
921 estate->es_result_relations[rti - 1] = resultRelInfo;
922
923 /*
924 * Saving in the list allows to avoid needlessly traversing the whole
925 * array when only a few of its entries are possibly non-NULL.
926 */
928 lappend(estate->es_opened_result_relations, resultRelInfo);
929}
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Definition execMain.c:1271
Relation ExecGetRangeTableRelation(EState *estate, Index rti, bool isResultRel)
Definition execUtils.c:851
List * lappend(List *list, void *datum)
Definition list.c:339

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

Referenced by CopyFrom(), and ExecInitModifyTable().

◆ ExecOpenScanRelation()

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

Definition at line 768 of file execUtils.c.

769{
770 Relation rel;
771
772 /* Open the relation. */
773 rel = ExecGetRangeTableRelation(estate, scanrelid, false);
774
775 /*
776 * Complain if we're attempting a scan of an unscannable relation, except
777 * when the query won't actually be run. This is a slightly klugy place
778 * to do this, perhaps, but there is no better place.
779 */
780 if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
784 errmsg("materialized view \"%s\" has not been populated",
786 errhint("Use the REFRESH MATERIALIZED VIEW command.")));
787
788 return rel;
789}
int errcode(int sqlerrcode)
Definition elog.c:874
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
Definition elog.h:152
#define EXEC_FLAG_WITH_NO_DATA
Definition executor.h:73
#define EXEC_FLAG_EXPLAIN_ONLY
Definition executor.h:67
static char * errmsg
#define RelationIsScannable(relation)
Definition rel.h:680
#define RelationGetRelationName(relation)
Definition rel.h:550

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

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

◆ ExecRelationIsTargetRelation()

bool ExecRelationIsTargetRelation ( EState estate,
Index  scanrelid 
)

Definition at line 734 of file execUtils.c.

735{
736 return bms_is_member(scanrelid, estate->es_plannedstmt->resultRelationRelids);
737}
Bitmapset * resultRelationRelids
Definition plannodes.h:121

References bms_is_member(), EState::es_plannedstmt, and PlannedStmt::resultRelationRelids.

◆ ExecTargetListLength()

int ExecTargetListLength ( List targetlist)

Definition at line 1201 of file execUtils.c.

1202{
1203 /* This used to be more complex, but fjoins are dead */
1204 return list_length(targetlist);
1205}

References list_length().

Referenced by ExecTypeFromTLInternal().

◆ executor_errposition()

int executor_errposition ( EState estate,
int  location 
)

Definition at line 962 of file execUtils.c.

963{
964 int pos;
965
966 /* No-op if location was not provided */
967 if (location < 0)
968 return 0;
969 /* Can't do anything if source text is not available */
970 if (estate == NULL || estate->es_sourceText == NULL)
971 return 0;
972 /* Convert offset to character number */
973 pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
974 /* And pass it to the ereport mechanism */
975 return errposition(pos);
976}
int errposition(int cursorpos)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1185

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

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

◆ FreeExecutorState()

void FreeExecutorState ( EState estate)

Definition at line 197 of file execUtils.c.

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

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

Referenced by afterTriggerInvokeEvents(), ATExecAddColumn(), ATRewriteTable(), check_default_partition_contents(), compute_expr_stats(), compute_index_stats(), CopyFrom(), EvalPlanQualEnd(), evaluate_expr(), ExecuteCallStmt(), ExecuteQuery(), ExecuteTruncateGuts(), ExplainExecuteQuery(), finish_edata(), freestate_cluster(), get_qual_for_range(), heapam_index_build_range_scan(), heapam_index_validate_scan(), IndexCheckExclusion(), make_build_data(), MergePartitionsMoveRows(), operator_predicate_proof(), plpgsql_inline_handler(), plpgsql_xact_cb(), release_change_context(), SplitPartitionMoveRows(), standard_ExecutorEnd(), unique_key_recheck(), and validateDomainCheckConstraint().

◆ FreeExprContext()

void FreeExprContext ( ExprContext econtext,
bool  isCommit 
)

Definition at line 421 of file execUtils.c.

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

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

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

◆ GetAttributeByName()

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

Definition at line 1087 of file execUtils.c.

1088{
1090 Datum result;
1091 Oid tupType;
1093 TupleDesc tupDesc;
1095 int i;
1096
1097 if (attname == NULL)
1098 elog(ERROR, "invalid attribute name");
1099
1100 if (isNull == NULL)
1101 elog(ERROR, "a NULL isNull pointer was passed");
1102
1103 if (tuple == NULL)
1104 {
1105 /* Kinda bogus but compatible with old behavior... */
1106 *isNull = true;
1107 return (Datum) 0;
1108 }
1109
1113
1115 for (i = 0; i < tupDesc->natts; i++)
1116 {
1117 Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1118
1119 if (namestrcmp(&(att->attname), attname) == 0)
1120 {
1121 attrno = att->attnum;
1122 break;
1123 }
1124 }
1125
1127 elog(ERROR, "attribute \"%s\" does not exist", attname);
1128
1129 /*
1130 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1131 * the fields in the struct just in case user tries to inspect system
1132 * columns.
1133 */
1135 ItemPointerSetInvalid(&(tmptup.t_self));
1136 tmptup.t_tableOid = InvalidOid;
1137 tmptup.t_data = tuple;
1138
1140 attrno,
1141 tupDesc,
1142 isNull);
1143
1144 ReleaseTupleDesc(tupDesc);
1145
1146 return result;
1147}
int16 AttrNumber
Definition attnum.h:21
#define InvalidAttrNumber
Definition attnum.h:23
int32_t int32
Definition c.h:620
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition itemptr.h:184
int namestrcmp(Name name, const char *str)
Definition name.c:247
NameData attname
FormData_pg_attribute * Form_pg_attribute
#define InvalidOid
unsigned int Oid
#define ReleaseTupleDesc(tupdesc)
Definition tupdesc.h:240
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition typcache.c:1947

References attname, elog, ERROR, fb(), heap_getattr(), HeapTupleHeaderGetDatumLength(), HeapTupleHeaderGetTypeId(), HeapTupleHeaderGetTypMod(), i, InvalidAttrNumber, InvalidOid, ItemPointerSetInvalid(), lookup_rowtype_tupdesc(), namestrcmp(), TupleDescData::natts, ReleaseTupleDesc, result, and TupleDescAttr().

Referenced by c_overpaid(), and overpaid().

◆ GetAttributeByNum()

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

Definition at line 1150 of file execUtils.c.

1153{
1154 Datum result;
1155 Oid tupType;
1157 TupleDesc tupDesc;
1159
1161 elog(ERROR, "invalid attribute number %d", attrno);
1162
1163 if (isNull == NULL)
1164 elog(ERROR, "a NULL isNull pointer was passed");
1165
1166 if (tuple == NULL)
1167 {
1168 /* Kinda bogus but compatible with old behavior... */
1169 *isNull = true;
1170 return (Datum) 0;
1171 }
1172
1176
1177 /*
1178 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1179 * the fields in the struct just in case user tries to inspect system
1180 * columns.
1181 */
1183 ItemPointerSetInvalid(&(tmptup.t_self));
1184 tmptup.t_tableOid = InvalidOid;
1185 tmptup.t_data = tuple;
1186
1188 attrno,
1189 tupDesc,
1190 isNull);
1191
1192 ReleaseTupleDesc(tupDesc);
1193
1194 return result;
1195}
#define AttributeNumberIsValid(attributeNumber)
Definition attnum.h:34

References AttributeNumberIsValid, elog, ERROR, fb(), heap_getattr(), HeapTupleHeaderGetDatumLength(), HeapTupleHeaderGetTypeId(), HeapTupleHeaderGetTypMod(), InvalidOid, ItemPointerSetInvalid(), lookup_rowtype_tupdesc(), ReleaseTupleDesc, and result.

◆ GetResultRTEPermissionInfo()

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

Definition at line 1464 of file execUtils.c.

1465{
1466 Index rti;
1469
1470 if (relinfo->ri_RootResultRelInfo)
1471 {
1472 /*
1473 * For inheritance child result relations (a partition routing target
1474 * of an INSERT or a child UPDATE target), this returns the root
1475 * parent's RTE to fetch the RTEPermissionInfo because that's the only
1476 * one that has one assigned.
1477 */
1478 rti = relinfo->ri_RootResultRelInfo->ri_RangeTableIndex;
1479 }
1480 else if (relinfo->ri_RangeTableIndex != 0)
1481 {
1482 /*
1483 * Non-child result relation should have their own RTEPermissionInfo.
1484 */
1485 rti = relinfo->ri_RangeTableIndex;
1486 }
1487 else
1488 {
1489 /*
1490 * The relation isn't in the range table and it isn't a partition
1491 * routing target. This ResultRelInfo must've been created only for
1492 * firing triggers and the relation is not being inserted into. (See
1493 * ExecGetTriggerResultRel.)
1494 */
1495 rti = 0;
1496 }
1497
1498 if (rti > 0)
1499 {
1500 rte = exec_rt_fetch(rti, estate);
1502 }
1503
1504 return perminfo;
1505}
unsigned int Index
Definition c.h:698
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)

References EState::es_rteperminfos, exec_rt_fetch(), fb(), and getRTEPermissionInfo().

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

◆ MakePerTupleExprContext()

ExprContext * MakePerTupleExprContext ( EState estate)

Definition at line 463 of file execUtils.c.

464{
465 if (estate->es_per_tuple_exprcontext == NULL)
467
468 return estate->es_per_tuple_exprcontext;
469}

References CreateExprContext(), EState::es_per_tuple_exprcontext, and fb().

◆ RegisterExprContextCallback()

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

Definition at line 989 of file execUtils.c.

992{
994
995 /* Save the info in appropriate memory context */
998 sizeof(ExprContext_CB));
999
1001 ecxt_callback->arg = arg;
1002
1003 /* link to front of list for appropriate execution order */
1004 ecxt_callback->next = econtext->ecxt_callbacks;
1005 econtext->ecxt_callbacks = ecxt_callback;
1006}
Datum arg
Definition elog.c:1322
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
on_exit_nicely_callback function
ExprContextCallbackFunction function
Definition execnodes.h:254

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

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

◆ ReScanExprContext()

void ReScanExprContext ( ExprContext econtext)

Definition at line 448 of file execUtils.c.

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

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

◆ ScanRelIsReadOnly()

◆ ShutdownExprContext()

static void ShutdownExprContext ( ExprContext econtext,
bool  isCommit 
)
static

Definition at line 1046 of file execUtils.c.

1047{
1049 MemoryContext oldcontext;
1050
1051 /* Fast path in normal case where there's nothing to do. */
1052 if (econtext->ecxt_callbacks == NULL)
1053 return;
1054
1055 /*
1056 * Call the callbacks in econtext's per-tuple context. This ensures that
1057 * any memory they might leak will get cleaned up.
1058 */
1059 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
1060
1061 /*
1062 * Call each callback function in reverse registration order.
1063 */
1064 while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
1065 {
1066 econtext->ecxt_callbacks = ecxt_callback->next;
1067 if (isCommit)
1070 }
1071
1072 MemoryContextSwitchTo(oldcontext);
1073}
struct ExprContext_CB * next
Definition execnodes.h:253

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

Referenced by FreeExprContext(), and ReScanExprContext().

◆ tlist_matches_tupdesc()

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

Definition at line 635 of file execUtils.c.

636{
637 int numattrs = tupdesc->natts;
638 int attrno;
639 ListCell *tlist_item = list_head(tlist);
640
641 /* Check the tlist attributes */
642 for (attrno = 1; attrno <= numattrs; attrno++)
643 {
645 Var *var;
646
647 if (tlist_item == NULL)
648 return false; /* tlist too short */
649 var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr;
650 if (!var || !IsA(var, Var))
651 return false; /* tlist item not a Var */
652 /* if these Asserts fail, planner messed up */
653 Assert(var->varno == varno);
654 Assert(var->varlevelsup == 0);
655 if (var->varattno != attrno)
656 return false; /* out of order */
657 if (att_tup->attisdropped)
658 return false; /* table contains dropped columns */
659 if (att_tup->atthasmissing)
660 return false; /* table contains cols with missing values */
661
662 /*
663 * Note: usually the Var's type should match the tupdesc exactly, but
664 * in situations involving unions of columns that have different
665 * typmods, the Var may have come from above the union and hence have
666 * typmod -1. This is a legitimate situation since the Var still
667 * describes the column, just not as exactly as the tupdesc does. We
668 * could change the planner to prevent it, but it'd then insert
669 * projection steps just to convert from specific typmod to typmod -1,
670 * which is pretty silly.
671 */
672 if (var->vartype != att_tup->atttypid ||
673 (var->vartypmod != att_tup->atttypmod &&
674 var->vartypmod != -1))
675 return false; /* type mismatch */
676
677 tlist_item = lnext(tlist, tlist_item);
678 }
679
680 if (tlist_item)
681 return false; /* tlist too long */
682
683 return true;
684}
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define lfirst(lc)
Definition pg_list.h:172
static ListCell * list_head(const List *l)
Definition pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition pg_list.h:375
AttrNumber varattno
Definition primnodes.h:275
int varno
Definition primnodes.h:270
Index varlevelsup
Definition primnodes.h:295

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

Referenced by ExecConditionalAssignProjectionInfo().

◆ UnregisterExprContextCallback()

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

Definition at line 1015 of file execUtils.c.

1018{
1021
1022 prev_callback = &econtext->ecxt_callbacks;
1023
1024 while ((ecxt_callback = *prev_callback) != NULL)
1025 {
1026 if (ecxt_callback->function == function && ecxt_callback->arg == arg)
1027 {
1030 }
1031 else
1033 }
1034}

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

Referenced by end_MultiFuncCall(), and fmgr_sql().

◆ UpdateChangedParamSet()

void UpdateChangedParamSet ( PlanState node,
Bitmapset newchg 
)

Definition at line 936 of file execUtils.c.

937{
939
940 /*
941 * The plan node only depends on params listed in its allParam set. Don't
942 * include anything else into its chgParam set.
943 */
945 node->chgParam = bms_join(node->chgParam, parmset);
946}
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:292
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition bitmapset.c:1214
Bitmapset * chgParam
Definition execnodes.h:1235
Bitmapset * allParam
Definition plannodes.h:256

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

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