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