Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * executor.h
4 : * support for the POSTGRES executor module
5 : *
6 : *
7 : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 : * Portions Copyright (c) 1994, Regents of the University of California
9 : *
10 : * src/include/executor/executor.h
11 : *
12 : *-------------------------------------------------------------------------
13 : */
14 : #ifndef EXECUTOR_H
15 : #define EXECUTOR_H
16 :
17 : #include "executor/execdesc.h"
18 : #include "fmgr.h"
19 : #include "nodes/lockoptions.h"
20 : #include "nodes/parsenodes.h"
21 : #include "utils/memutils.h"
22 : #include "utils/plancache.h"
23 :
24 :
25 : /*
26 : * The "eflags" argument to ExecutorStart and the various ExecInitNode
27 : * routines is a bitwise OR of the following flag bits, which tell the
28 : * called plan node what to expect. Note that the flags will get modified
29 : * as they are passed down the plan tree, since an upper node may require
30 : * functionality in its subnode not demanded of the plan as a whole
31 : * (example: MergeJoin requires mark/restore capability in its inner input),
32 : * or an upper node may shield its input from some functionality requirement
33 : * (example: Materialize shields its input from needing to do backward scan).
34 : *
35 : * EXPLAIN_ONLY indicates that the plan tree is being initialized just so
36 : * EXPLAIN can print it out; it will not be run. Hence, no side-effects
37 : * of startup should occur. However, error checks (such as permission checks)
38 : * should be performed.
39 : *
40 : * EXPLAIN_GENERIC can only be used together with EXPLAIN_ONLY. It indicates
41 : * that a generic plan is being shown using EXPLAIN (GENERIC_PLAN), which
42 : * means that missing parameter values must be tolerated. Currently, the only
43 : * effect is to suppress execution-time partition pruning.
44 : *
45 : * REWIND indicates that the plan node should try to efficiently support
46 : * rescans without parameter changes. (Nodes must support ExecReScan calls
47 : * in any case, but if this flag was not given, they are at liberty to do it
48 : * through complete recalculation. Note that a parameter change forces a
49 : * full recalculation in any case.)
50 : *
51 : * BACKWARD indicates that the plan node must respect the es_direction flag.
52 : * When this is not passed, the plan node will only be run forwards.
53 : *
54 : * MARK indicates that the plan node must support Mark/Restore calls.
55 : * When this is not passed, no Mark/Restore will occur.
56 : *
57 : * SKIP_TRIGGERS tells ExecutorStart/ExecutorFinish to skip calling
58 : * AfterTriggerBeginQuery/AfterTriggerEndQuery. This does not necessarily
59 : * mean that the plan can't queue any AFTER triggers; just that the caller
60 : * is responsible for there being a trigger context for them to be queued in.
61 : *
62 : * WITH_NO_DATA indicates that we are performing REFRESH MATERIALIZED VIEW
63 : * ... WITH NO DATA. Currently, the only effect is to suppress errors about
64 : * scanning unpopulated materialized views.
65 : */
66 : #define EXEC_FLAG_EXPLAIN_ONLY 0x0001 /* EXPLAIN, no ANALYZE */
67 : #define EXEC_FLAG_EXPLAIN_GENERIC 0x0002 /* EXPLAIN (GENERIC_PLAN) */
68 : #define EXEC_FLAG_REWIND 0x0004 /* need efficient rescan */
69 : #define EXEC_FLAG_BACKWARD 0x0008 /* need backward scan */
70 : #define EXEC_FLAG_MARK 0x0010 /* need mark/restore */
71 : #define EXEC_FLAG_SKIP_TRIGGERS 0x0020 /* skip AfterTrigger setup */
72 : #define EXEC_FLAG_WITH_NO_DATA 0x0040 /* REFRESH ... WITH NO DATA */
73 :
74 :
75 : /* Hook for plugins to get control in ExecutorStart() */
76 : typedef bool (*ExecutorStart_hook_type) (QueryDesc *queryDesc, int eflags);
77 : extern PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook;
78 :
79 : /* Hook for plugins to get control in ExecutorRun() */
80 : typedef void (*ExecutorRun_hook_type) (QueryDesc *queryDesc,
81 : ScanDirection direction,
82 : uint64 count);
83 : extern PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook;
84 :
85 : /* Hook for plugins to get control in ExecutorFinish() */
86 : typedef void (*ExecutorFinish_hook_type) (QueryDesc *queryDesc);
87 : extern PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook;
88 :
89 : /* Hook for plugins to get control in ExecutorEnd() */
90 : typedef void (*ExecutorEnd_hook_type) (QueryDesc *queryDesc);
91 : extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
92 :
93 : /* Hook for plugins to get control in ExecCheckPermissions() */
94 : typedef bool (*ExecutorCheckPerms_hook_type) (List *rangeTable,
95 : List *rtePermInfos,
96 : bool ereport_on_violation);
97 : extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
98 :
99 :
100 : /*
101 : * prototypes from functions in execAmi.c
102 : */
103 : struct Path; /* avoid including pathnodes.h here */
104 :
105 : extern void ExecReScan(PlanState *node);
106 : extern void ExecMarkPos(PlanState *node);
107 : extern void ExecRestrPos(PlanState *node);
108 : extern bool ExecSupportsMarkRestore(struct Path *pathnode);
109 : extern bool ExecSupportsBackwardScan(Plan *node);
110 : extern bool ExecMaterializesOutput(NodeTag plantype);
111 :
112 : /*
113 : * prototypes from functions in execCurrent.c
114 : */
115 : extern bool execCurrentOf(CurrentOfExpr *cexpr,
116 : ExprContext *econtext,
117 : Oid table_oid,
118 : ItemPointer current_tid);
119 :
120 : /*
121 : * prototypes from functions in execGrouping.c
122 : */
123 : extern ExprState *execTuplesMatchPrepare(TupleDesc desc,
124 : int numCols,
125 : const AttrNumber *keyColIdx,
126 : const Oid *eqOperators,
127 : const Oid *collations,
128 : PlanState *parent);
129 : extern void execTuplesHashPrepare(int numCols,
130 : const Oid *eqOperators,
131 : Oid **eqFuncOids,
132 : FmgrInfo **hashFunctions);
133 : extern TupleHashTable BuildTupleHashTable(PlanState *parent,
134 : TupleDesc inputDesc,
135 : const TupleTableSlotOps *inputOps,
136 : int numCols,
137 : AttrNumber *keyColIdx,
138 : const Oid *eqfuncoids,
139 : FmgrInfo *hashfunctions,
140 : Oid *collations,
141 : long nbuckets,
142 : Size additionalsize,
143 : MemoryContext metacxt,
144 : MemoryContext tablecxt,
145 : MemoryContext tempcxt,
146 : bool use_variable_hash_iv);
147 : extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
148 : TupleTableSlot *slot,
149 : bool *isnew, uint32 *hash);
150 : extern uint32 TupleHashTableHash(TupleHashTable hashtable,
151 : TupleTableSlot *slot);
152 : extern TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable,
153 : TupleTableSlot *slot,
154 : bool *isnew, uint32 hash);
155 : extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
156 : TupleTableSlot *slot,
157 : ExprState *eqcomp,
158 : ExprState *hashexpr);
159 : extern void ResetTupleHashTable(TupleHashTable hashtable);
160 :
161 : /*
162 : * prototypes from functions in execJunk.c
163 : */
164 : extern JunkFilter *ExecInitJunkFilter(List *targetList,
165 : TupleTableSlot *slot);
166 : extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
167 : TupleDesc cleanTupType,
168 : TupleTableSlot *slot);
169 : extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
170 : const char *attrName);
171 : extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
172 : const char *attrName);
173 : extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
174 : TupleTableSlot *slot);
175 :
176 : /*
177 : * ExecGetJunkAttribute
178 : *
179 : * Given a junk filter's input tuple (slot) and a junk attribute's number
180 : * previously found by ExecFindJunkAttribute, extract & return the value and
181 : * isNull flag of the attribute.
182 : */
183 : #ifndef FRONTEND
184 : static inline Datum
185 1986946 : ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
186 : {
187 : Assert(attno > 0);
188 1986946 : return slot_getattr(slot, attno, isNull);
189 : }
190 : #endif
191 :
192 : /*
193 : * prototypes from functions in execMain.c
194 : */
195 : extern bool ExecutorStart(QueryDesc *queryDesc, int eflags);
196 : extern void ExecutorStartCachedPlan(QueryDesc *queryDesc, int eflags,
197 : CachedPlanSource *plansource,
198 : int query_index);
199 : extern bool standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
200 : extern void ExecutorRun(QueryDesc *queryDesc,
201 : ScanDirection direction, uint64 count);
202 : extern void standard_ExecutorRun(QueryDesc *queryDesc,
203 : ScanDirection direction, uint64 count);
204 : extern void ExecutorFinish(QueryDesc *queryDesc);
205 : extern void standard_ExecutorFinish(QueryDesc *queryDesc);
206 : extern void ExecutorEnd(QueryDesc *queryDesc);
207 : extern void standard_ExecutorEnd(QueryDesc *queryDesc);
208 : extern void ExecutorRewind(QueryDesc *queryDesc);
209 : extern bool ExecCheckPermissions(List *rangeTable,
210 : List *rteperminfos, bool ereport_on_violation);
211 : extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
212 : List *mergeActions);
213 : extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
214 : Relation resultRelationDesc,
215 : Index resultRelationIndex,
216 : ResultRelInfo *partition_root_rri,
217 : int instrument_options);
218 : extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid,
219 : ResultRelInfo *rootRelInfo);
220 : extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo);
221 : extern void ExecConstraints(ResultRelInfo *resultRelInfo,
222 : TupleTableSlot *slot, EState *estate);
223 : extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo,
224 : TupleTableSlot *slot, EState *estate, bool emitError);
225 : extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
226 : TupleTableSlot *slot, EState *estate);
227 : extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
228 : TupleTableSlot *slot, EState *estate);
229 : extern char *ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot,
230 : TupleDesc tupdesc,
231 : Bitmapset *modifiedCols,
232 : int maxfieldlen);
233 : extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
234 : extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
235 : extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
236 : extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
237 : Index rti, TupleTableSlot *inputslot);
238 : extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
239 : Plan *subplan, List *auxrowmarks,
240 : int epqParam, List *resultRelations);
241 : extern void EvalPlanQualSetPlan(EPQState *epqstate,
242 : Plan *subplan, List *auxrowmarks);
243 : extern TupleTableSlot *EvalPlanQualSlot(EPQState *epqstate,
244 : Relation relation, Index rti);
245 :
246 : #define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
247 : extern bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot);
248 : extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
249 : extern void EvalPlanQualBegin(EPQState *epqstate);
250 : extern void EvalPlanQualEnd(EPQState *epqstate);
251 :
252 : /*
253 : * functions in execProcnode.c
254 : */
255 : extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
256 : extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
257 : extern Node *MultiExecProcNode(PlanState *node);
258 : extern void ExecEndNode(PlanState *node);
259 : extern void ExecShutdownNode(PlanState *node);
260 : extern void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node);
261 :
262 : /*
263 : * Is the CachedPlan in es_cachedplan still valid?
264 : *
265 : * Called from InitPlan() because invalidation messages that affect the plan
266 : * might be received after locks have been taken on runtime-prunable relations.
267 : * The caller should take appropriate action if the plan has become invalid.
268 : */
269 : static inline bool
270 1982912 : ExecPlanStillValid(EState *estate)
271 : {
272 2342570 : return estate->es_cachedplan == NULL ? true :
273 359658 : CachedPlanValid(estate->es_cachedplan);
274 : }
275 :
276 : /*
277 : * Locks are needed only if running a cached plan that might contain unlocked
278 : * relations, such as a reused generic plan.
279 : */
280 : static inline bool
281 750 : ExecShouldLockRelations(EState *estate)
282 : {
283 1040 : return estate->es_cachedplan == NULL ? false :
284 290 : CachedPlanRequiresLocking(estate->es_cachedplan);
285 : }
286 :
287 : /* ----------------------------------------------------------------
288 : * ExecProcNode
289 : *
290 : * Execute the given node to return a(nother) tuple.
291 : * ----------------------------------------------------------------
292 : */
293 : #ifndef FRONTEND
294 : static inline TupleTableSlot *
295 115898242 : ExecProcNode(PlanState *node)
296 : {
297 115898242 : if (node->chgParam != NULL) /* something changed? */
298 282780 : ExecReScan(node); /* let ReScan handle this */
299 :
300 115898242 : return node->ExecProcNode(node);
301 : }
302 : #endif
303 :
304 : /*
305 : * prototypes from functions in execExpr.c
306 : */
307 : extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
308 : extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
309 : extern ExprState *ExecInitQual(List *qual, PlanState *parent);
310 : extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
311 : extern List *ExecInitExprList(List *nodes, PlanState *parent);
312 : extern ExprState *ExecBuildAggTrans(AggState *aggstate, struct AggStatePerPhaseData *phase,
313 : bool doSort, bool doHash, bool nullcheck);
314 : extern ExprState *ExecBuildHash32FromAttrs(TupleDesc desc,
315 : const TupleTableSlotOps *ops,
316 : FmgrInfo *hashfunctions,
317 : Oid *collations,
318 : int numCols,
319 : AttrNumber *keyColIdx,
320 : PlanState *parent,
321 : uint32 init_value);
322 : extern ExprState *ExecBuildHash32Expr(TupleDesc desc,
323 : const TupleTableSlotOps *ops,
324 : const Oid *hashfunc_oids,
325 : const List *collations,
326 : const List *hash_exprs,
327 : const bool *opstrict, PlanState *parent,
328 : uint32 init_value, bool keep_nulls);
329 : extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
330 : const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
331 : int numCols,
332 : const AttrNumber *keyColIdx,
333 : const Oid *eqfunctions,
334 : const Oid *collations,
335 : PlanState *parent);
336 : extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
337 : const TupleTableSlotOps *lops,
338 : const TupleTableSlotOps *rops,
339 : const Oid *eqfunctions,
340 : const Oid *collations,
341 : const List *param_exprs,
342 : PlanState *parent);
343 : extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
344 : ExprContext *econtext,
345 : TupleTableSlot *slot,
346 : PlanState *parent,
347 : TupleDesc inputDesc);
348 : extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
349 : bool evalTargetList,
350 : List *targetColnos,
351 : TupleDesc relDesc,
352 : ExprContext *econtext,
353 : TupleTableSlot *slot,
354 : PlanState *parent);
355 : extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
356 : extern ExprState *ExecPrepareQual(List *qual, EState *estate);
357 : extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
358 : extern List *ExecPrepareExprList(List *nodes, EState *estate);
359 :
360 : /*
361 : * ExecEvalExpr
362 : *
363 : * Evaluate expression identified by "state" in the execution context
364 : * given by "econtext". *isNull is set to the is-null flag for the result,
365 : * and the Datum value is the function result.
366 : *
367 : * The caller should already have switched into the temporary memory
368 : * context econtext->ecxt_per_tuple_memory. The convenience entry point
369 : * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
370 : * do the switch in an outer loop.
371 : */
372 : #ifndef FRONTEND
373 : static inline Datum
374 19969640 : ExecEvalExpr(ExprState *state,
375 : ExprContext *econtext,
376 : bool *isNull)
377 : {
378 19969640 : return state->evalfunc(state, econtext, isNull);
379 : }
380 : #endif
381 :
382 : /*
383 : * ExecEvalExprSwitchContext
384 : *
385 : * Same as ExecEvalExpr, but get into the right allocation context explicitly.
386 : */
387 : #ifndef FRONTEND
388 : static inline Datum
389 192553004 : ExecEvalExprSwitchContext(ExprState *state,
390 : ExprContext *econtext,
391 : bool *isNull)
392 : {
393 : Datum retDatum;
394 : MemoryContext oldContext;
395 :
396 192553004 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
397 192553004 : retDatum = state->evalfunc(state, econtext, isNull);
398 192535610 : MemoryContextSwitchTo(oldContext);
399 192535610 : return retDatum;
400 : }
401 : #endif
402 :
403 : /*
404 : * ExecProject
405 : *
406 : * Projects a tuple based on projection info and stores it in the slot passed
407 : * to ExecBuildProjectionInfo().
408 : *
409 : * Note: the result is always a virtual tuple; therefore it may reference
410 : * the contents of the exprContext's scan tuples and/or temporary results
411 : * constructed in the exprContext. If the caller wishes the result to be
412 : * valid longer than that data will be valid, he must call ExecMaterializeSlot
413 : * on the result slot.
414 : */
415 : #ifndef FRONTEND
416 : static inline TupleTableSlot *
417 62812420 : ExecProject(ProjectionInfo *projInfo)
418 : {
419 62812420 : ExprContext *econtext = projInfo->pi_exprContext;
420 62812420 : ExprState *state = &projInfo->pi_state;
421 62812420 : TupleTableSlot *slot = state->resultslot;
422 : bool isnull;
423 :
424 : /*
425 : * Clear any former contents of the result slot. This makes it safe for
426 : * us to use the slot's Datum/isnull arrays as workspace.
427 : */
428 62812420 : ExecClearTuple(slot);
429 :
430 : /* Run the expression, discarding scalar result from the last column. */
431 62812420 : (void) ExecEvalExprSwitchContext(state, econtext, &isnull);
432 :
433 : /*
434 : * Successfully formed a result row. Mark the result slot as containing a
435 : * valid virtual tuple (inlined version of ExecStoreVirtualTuple()).
436 : */
437 62798824 : slot->tts_flags &= ~TTS_FLAG_EMPTY;
438 62798824 : slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
439 :
440 62798824 : return slot;
441 : }
442 : #endif
443 :
444 : /*
445 : * ExecQual - evaluate a qual prepared with ExecInitQual (possibly via
446 : * ExecPrepareQual). Returns true if qual is satisfied, else false.
447 : *
448 : * Note: ExecQual used to have a third argument "resultForNull". The
449 : * behavior of this function now corresponds to resultForNull == false.
450 : * If you want the resultForNull == true behavior, see ExecCheck.
451 : */
452 : #ifndef FRONTEND
453 : static inline bool
454 81915366 : ExecQual(ExprState *state, ExprContext *econtext)
455 : {
456 : Datum ret;
457 : bool isnull;
458 :
459 : /* short-circuit (here and in ExecInitQual) for empty restriction list */
460 81915366 : if (state == NULL)
461 5268514 : return true;
462 :
463 : /* verify that expression was compiled using ExecInitQual */
464 : Assert(state->flags & EEO_FLAG_IS_QUAL);
465 :
466 76646852 : ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
467 :
468 : /* EEOP_QUAL should never return NULL */
469 : Assert(!isnull);
470 :
471 76646818 : return DatumGetBool(ret);
472 : }
473 : #endif
474 :
475 : /*
476 : * ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
477 : * context.
478 : */
479 : #ifndef FRONTEND
480 : static inline bool
481 20468710 : ExecQualAndReset(ExprState *state, ExprContext *econtext)
482 : {
483 20468710 : bool ret = ExecQual(state, econtext);
484 :
485 : /* inline ResetExprContext, to avoid ordering issue in this file */
486 20468710 : MemoryContextReset(econtext->ecxt_per_tuple_memory);
487 20468710 : return ret;
488 : }
489 : #endif
490 :
491 : extern bool ExecCheck(ExprState *state, ExprContext *econtext);
492 :
493 : /*
494 : * prototypes from functions in execSRF.c
495 : */
496 : extern SetExprState *ExecInitTableFunctionResult(Expr *expr,
497 : ExprContext *econtext, PlanState *parent);
498 : extern Tuplestorestate *ExecMakeTableFunctionResult(SetExprState *setexpr,
499 : ExprContext *econtext,
500 : MemoryContext argContext,
501 : TupleDesc expectedDesc,
502 : bool randomAccess);
503 : extern SetExprState *ExecInitFunctionResultSet(Expr *expr,
504 : ExprContext *econtext, PlanState *parent);
505 : extern Datum ExecMakeFunctionResultSet(SetExprState *fcache,
506 : ExprContext *econtext,
507 : MemoryContext argContext,
508 : bool *isNull,
509 : ExprDoneCond *isDone);
510 :
511 : /*
512 : * prototypes from functions in execScan.c
513 : */
514 : typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
515 : typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
516 :
517 : extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
518 : ExecScanRecheckMtd recheckMtd);
519 : extern void ExecAssignScanProjectionInfo(ScanState *node);
520 : extern void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno);
521 : extern void ExecScanReScan(ScanState *node);
522 :
523 : /*
524 : * prototypes from functions in execTuples.c
525 : */
526 : extern void ExecInitResultTypeTL(PlanState *planstate);
527 : extern void ExecInitResultSlot(PlanState *planstate,
528 : const TupleTableSlotOps *tts_ops);
529 : extern void ExecInitResultTupleSlotTL(PlanState *planstate,
530 : const TupleTableSlotOps *tts_ops);
531 : extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate,
532 : TupleDesc tupledesc,
533 : const TupleTableSlotOps *tts_ops);
534 : extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate,
535 : TupleDesc tupledesc,
536 : const TupleTableSlotOps *tts_ops);
537 : extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate, TupleDesc tupType,
538 : const TupleTableSlotOps *tts_ops);
539 : extern TupleDesc ExecTypeFromTL(List *targetList);
540 : extern TupleDesc ExecCleanTypeFromTL(List *targetList);
541 : extern TupleDesc ExecTypeFromExprList(List *exprList);
542 : extern void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList);
543 : extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
544 :
545 : typedef struct TupOutputState
546 : {
547 : TupleTableSlot *slot;
548 : DestReceiver *dest;
549 : } TupOutputState;
550 :
551 : extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
552 : TupleDesc tupdesc,
553 : const TupleTableSlotOps *tts_ops);
554 : extern void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull);
555 : extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
556 : extern void end_tup_output(TupOutputState *tstate);
557 :
558 : /*
559 : * Write a single line of text given as a C string.
560 : *
561 : * Should only be used with a single-TEXT-attribute tupdesc.
562 : */
563 : #define do_text_output_oneline(tstate, str_to_emit) \
564 : do { \
565 : Datum values_[1]; \
566 : bool isnull_[1]; \
567 : values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
568 : isnull_[0] = false; \
569 : do_tup_output(tstate, values_, isnull_); \
570 : pfree(DatumGetPointer(values_[0])); \
571 : } while (0)
572 :
573 :
574 : /*
575 : * prototypes from functions in execUtils.c
576 : */
577 : extern EState *CreateExecutorState(void);
578 : extern void FreeExecutorState(EState *estate);
579 : extern ExprContext *CreateExprContext(EState *estate);
580 : extern ExprContext *CreateWorkExprContext(EState *estate);
581 : extern ExprContext *CreateStandaloneExprContext(void);
582 : extern void FreeExprContext(ExprContext *econtext, bool isCommit);
583 : extern void ReScanExprContext(ExprContext *econtext);
584 :
585 : #define ResetExprContext(econtext) \
586 : MemoryContextReset((econtext)->ecxt_per_tuple_memory)
587 :
588 : extern ExprContext *MakePerTupleExprContext(EState *estate);
589 :
590 : /* Get an EState's per-output-tuple exprcontext, making it if first use */
591 : #define GetPerTupleExprContext(estate) \
592 : ((estate)->es_per_tuple_exprcontext ? \
593 : (estate)->es_per_tuple_exprcontext : \
594 : MakePerTupleExprContext(estate))
595 :
596 : #define GetPerTupleMemoryContext(estate) \
597 : (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
598 :
599 : /* Reset an EState's per-output-tuple exprcontext, if one's been created */
600 : #define ResetPerTupleExprContext(estate) \
601 : do { \
602 : if ((estate)->es_per_tuple_exprcontext) \
603 : ResetExprContext((estate)->es_per_tuple_exprcontext); \
604 : } while (0)
605 :
606 : extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
607 : extern TupleDesc ExecGetResultType(PlanState *planstate);
608 : extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
609 : bool *isfixed);
610 : extern const TupleTableSlotOps *ExecGetCommonSlotOps(PlanState **planstates,
611 : int nplans);
612 : extern const TupleTableSlotOps *ExecGetCommonChildSlotOps(PlanState *ps);
613 : extern void ExecAssignProjectionInfo(PlanState *planstate,
614 : TupleDesc inputDesc);
615 : extern void ExecConditionalAssignProjectionInfo(PlanState *planstate,
616 : TupleDesc inputDesc, int varno);
617 : extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
618 : extern void ExecCreateScanSlotFromOuterPlan(EState *estate,
619 : ScanState *scanstate,
620 : const TupleTableSlotOps *tts_ops);
621 :
622 : extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
623 :
624 : extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
625 :
626 : extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos,
627 : Bitmapset *unpruned_relids);
628 : extern void ExecCloseRangeTableRelations(EState *estate);
629 : extern void ExecCloseResultRelations(EState *estate);
630 :
631 : static inline RangeTblEntry *
632 923232 : exec_rt_fetch(Index rti, EState *estate)
633 : {
634 923232 : return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
635 : }
636 :
637 : extern Relation ExecGetRangeTableRelation(EState *estate, Index rti);
638 : extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
639 : Index rti);
640 :
641 : extern int executor_errposition(EState *estate, int location);
642 :
643 : extern void RegisterExprContextCallback(ExprContext *econtext,
644 : ExprContextCallbackFunction function,
645 : Datum arg);
646 : extern void UnregisterExprContextCallback(ExprContext *econtext,
647 : ExprContextCallbackFunction function,
648 : Datum arg);
649 :
650 : extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
651 : bool *isNull);
652 : extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
653 : bool *isNull);
654 :
655 : extern int ExecTargetListLength(List *targetlist);
656 : extern int ExecCleanTargetListLength(List *targetlist);
657 :
658 : extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
659 : extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
660 : extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
661 : extern TupleTableSlot *ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo);
662 : extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
663 : extern TupleConversionMap *ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate);
664 :
665 : extern Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate);
666 : extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
667 : extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
668 : extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
669 : extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
670 :
671 : /*
672 : * prototypes from functions in execIndexing.c
673 : */
674 : extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
675 : extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
676 : extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
677 : TupleTableSlot *slot, EState *estate,
678 : bool update,
679 : bool noDupErr,
680 : bool *specConflict, List *arbiterIndexes,
681 : bool onlySummarizing);
682 : extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
683 : TupleTableSlot *slot,
684 : EState *estate, ItemPointer conflictTid,
685 : ItemPointer tupleid,
686 : List *arbiterIndexes);
687 : extern void check_exclusion_constraint(Relation heap, Relation index,
688 : IndexInfo *indexInfo,
689 : ItemPointer tupleid,
690 : const Datum *values, const bool *isnull,
691 : EState *estate, bool newIndex);
692 :
693 : /*
694 : * prototypes from functions in execReplication.c
695 : */
696 : extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
697 : LockTupleMode lockmode,
698 : TupleTableSlot *searchslot,
699 : TupleTableSlot *outslot);
700 : extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
701 : TupleTableSlot *searchslot, TupleTableSlot *outslot);
702 :
703 : extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
704 : EState *estate, TupleTableSlot *slot);
705 : extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
706 : EState *estate, EPQState *epqstate,
707 : TupleTableSlot *searchslot, TupleTableSlot *slot);
708 : extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
709 : EState *estate, EPQState *epqstate,
710 : TupleTableSlot *searchslot);
711 : extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
712 :
713 : extern void CheckSubscriptionRelkind(char relkind, const char *nspname,
714 : const char *relname);
715 :
716 : /*
717 : * prototypes from functions in nodeModifyTable.c
718 : */
719 : extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
720 : TupleTableSlot *planSlot,
721 : TupleTableSlot *oldSlot);
722 : extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
723 : Oid resultoid,
724 : bool missing_ok,
725 : bool update_cache);
726 :
727 : #endif /* EXECUTOR_H */
|