Age Owner TLA Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * executor.h
4 : * support for the POSTGRES executor module
5 : *
6 : *
7 : * Portions Copyright (c) 1996-2023, 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 : bool execute_once);
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 : int numCols, AttrNumber *keyColIdx,
136 : const Oid *eqfuncoids,
137 : FmgrInfo *hashfunctions,
138 : Oid *collations,
139 : long nbuckets, Size additionalsize,
140 : MemoryContext tablecxt,
141 : MemoryContext tempcxt, bool use_variable_hash_iv);
142 : extern TupleHashTable BuildTupleHashTableExt(PlanState *parent,
143 : TupleDesc inputDesc,
144 : int numCols, AttrNumber *keyColIdx,
145 : const Oid *eqfuncoids,
146 : FmgrInfo *hashfunctions,
147 : Oid *collations,
148 : long nbuckets, Size additionalsize,
149 : MemoryContext metacxt,
150 : MemoryContext tablecxt,
151 : MemoryContext tempcxt, bool use_variable_hash_iv);
152 : extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
153 : TupleTableSlot *slot,
154 : bool *isnew, uint32 *hash);
155 : extern uint32 TupleHashTableHash(TupleHashTable hashtable,
156 : TupleTableSlot *slot);
157 : extern TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable,
158 : TupleTableSlot *slot,
159 : bool *isnew, uint32 hash);
160 : extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
161 : TupleTableSlot *slot,
162 : ExprState *eqcomp,
163 : FmgrInfo *hashfunctions);
164 : extern void ResetTupleHashTable(TupleHashTable hashtable);
165 :
166 : /*
167 : * prototypes from functions in execJunk.c
168 : */
169 : extern JunkFilter *ExecInitJunkFilter(List *targetList,
170 : TupleTableSlot *slot);
171 : extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
172 : TupleDesc cleanTupType,
173 : TupleTableSlot *slot);
174 : extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
175 : const char *attrName);
176 : extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
177 : const char *attrName);
178 : extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
179 : TupleTableSlot *slot);
180 :
181 : /*
182 : * ExecGetJunkAttribute
183 : *
184 : * Given a junk filter's input tuple (slot) and a junk attribute's number
185 : * previously found by ExecFindJunkAttribute, extract & return the value and
186 : * isNull flag of the attribute.
187 : */
188 : #ifndef FRONTEND
189 : static inline Datum
739 tgl 190 GIC 1037598 : ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
191 : {
192 1037598 : Assert(attno > 0);
193 1037598 : return slot_getattr(slot, attno, isNull);
194 : }
195 : #endif
196 :
197 : /*
198 : * prototypes from functions in execMain.c
199 : */
200 : extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
201 : extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
5273 tgl 202 ECB : extern void ExecutorRun(QueryDesc *queryDesc,
203 : ScanDirection direction, uint64 count, bool execute_once);
204 : extern void standard_ExecutorRun(QueryDesc *queryDesc,
1418 205 : ScanDirection direction, uint64 count, bool execute_once);
206 : extern void ExecutorFinish(QueryDesc *queryDesc);
207 : extern void standard_ExecutorFinish(QueryDesc *queryDesc);
208 : extern void ExecutorEnd(QueryDesc *queryDesc);
209 : extern void standard_ExecutorEnd(QueryDesc *queryDesc);
210 : extern void ExecutorRewind(QueryDesc *queryDesc);
211 : extern bool ExecCheckPermissions(List *rangeTable,
212 : List *rteperminfos, bool ereport_on_violation);
213 : extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation);
214 : extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
215 : Relation resultRelationDesc,
216 : Index resultRelationIndex,
217 : ResultRelInfo *partition_root_rri,
218 : int instrument_options);
219 : extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid,
220 : ResultRelInfo *rootRelInfo);
221 : extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo);
222 : extern void ExecConstraints(ResultRelInfo *resultRelInfo,
223 : TupleTableSlot *slot, EState *estate);
224 : extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo,
225 : TupleTableSlot *slot, EState *estate, bool emitError);
226 : extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
227 : TupleTableSlot *slot, EState *estate);
228 : extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
229 : TupleTableSlot *slot, EState *estate);
230 : extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
231 : extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
232 : extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
233 : extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
234 : Index rti, TupleTableSlot *inputslot);
235 : extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
236 : Plan *subplan, List *auxrowmarks, int epqParam);
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 *
2092 andres 267 GIC 61085020 : ExecProcNode(PlanState *node)
268 : {
269 61085020 : if (node->chgParam != NULL) /* something changed? */
270 190433 : ExecReScan(node); /* let ReScan handle this */
271 :
272 61085020 : 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);
1935 tgl 280 ECB : extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
281 : extern ExprState *ExecInitQual(List *qual, PlanState *parent);
2217 andres 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,
1131 jdavis 285 : bool doSort, bool doHash, bool nullcheck);
286 : extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
287 : const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
288 : int numCols,
289 : const AttrNumber *keyColIdx,
290 : const Oid *eqfunctions,
291 : const Oid *collations,
292 : PlanState *parent);
293 : extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
294 : const TupleTableSlotOps *lops,
295 : const TupleTableSlotOps *rops,
296 : const Oid *eqfunctions,
297 : const Oid *collations,
298 : const List *param_exprs,
299 : PlanState *parent);
300 : extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
301 : ExprContext *econtext,
302 : TupleTableSlot *slot,
303 : PlanState *parent,
304 : TupleDesc inputDesc);
305 : extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
306 : bool evalTargetList,
307 : List *targetColnos,
308 : TupleDesc relDesc,
309 : ExprContext *econtext,
310 : TupleTableSlot *slot,
311 : PlanState *parent);
312 : extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
313 : extern ExprState *ExecPrepareQual(List *qual, EState *estate);
314 : extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
315 : extern List *ExecPrepareExprList(List *nodes, EState *estate);
316 :
317 : /*
318 : * ExecEvalExpr
319 : *
320 : * Evaluate expression identified by "state" in the execution context
321 : * given by "econtext". *isNull is set to the is-null flag for the result,
322 : * and the Datum value is the function result.
323 : *
324 : * The caller should already have switched into the temporary memory
325 : * context econtext->ecxt_per_tuple_memory. The convenience entry point
326 : * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
327 : * do the switch in an outer loop.
328 : */
329 : #ifndef FRONTEND
330 : static inline Datum
2217 andres 331 GIC 20915348 : ExecEvalExpr(ExprState *state,
332 : ExprContext *econtext,
333 : bool *isNull)
334 : {
2040 peter_e 335 20915348 : return state->evalfunc(state, econtext, isNull);
336 : }
337 : #endif
338 :
339 : /*
340 : * ExecEvalExprSwitchContext
341 : *
342 : * Same as ExecEvalExpr, but get into the right allocation context explicitly.
343 : */
2217 andres 344 ECB : #ifndef FRONTEND
345 : static inline Datum
2217 andres 346 GIC 83412439 : ExecEvalExprSwitchContext(ExprState *state,
347 : ExprContext *econtext,
2217 andres 348 ECB : bool *isNull)
349 : {
350 : Datum retDatum;
351 : MemoryContext oldContext;
352 :
2217 andres 353 GIC 83412439 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
2040 peter_e 354 83412439 : retDatum = state->evalfunc(state, econtext, isNull);
2217 andres 355 83404331 : MemoryContextSwitchTo(oldContext);
356 83404331 : return retDatum;
357 : }
358 : #endif
2217 andres 359 ECB :
360 : /*
361 : * ExecProject
362 : *
363 : * Projects a tuple based on projection info and stores it in the slot passed
364 : * to ExecBuildProjectionInfo().
365 : *
366 : * Note: the result is always a virtual tuple; therefore it may reference
367 : * the contents of the exprContext's scan tuples and/or temporary results
368 : * constructed in the exprContext. If the caller wishes the result to be
369 : * valid longer than that data will be valid, he must call ExecMaterializeSlot
370 : * on the result slot.
371 : */
372 : #ifndef FRONTEND
373 : static inline TupleTableSlot *
2217 andres 374 GIC 32531108 : ExecProject(ProjectionInfo *projInfo)
375 : {
376 32531108 : ExprContext *econtext = projInfo->pi_exprContext;
377 32531108 : ExprState *state = &projInfo->pi_state;
378 32531108 : TupleTableSlot *slot = state->resultslot;
379 : bool isnull;
380 :
381 : /*
382 : * Clear any former contents of the result slot. This makes it safe for
383 : * us to use the slot's Datum/isnull arrays as workspace.
384 : */
385 32531108 : ExecClearTuple(slot);
386 :
2217 andres 387 ECB : /* Run the expression, discarding scalar result from the last column. */
2217 andres 388 GIC 32531108 : (void) ExecEvalExprSwitchContext(state, econtext, &isnull);
2217 andres 389 ECB :
390 : /*
391 : * Successfully formed a result row. Mark the result slot as containing a
392 : * valid virtual tuple (inlined version of ExecStoreVirtualTuple()).
393 : */
1637 andres 394 GIC 32524596 : slot->tts_flags &= ~TTS_FLAG_EMPTY;
2217 395 32524596 : slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
396 :
397 32524596 : return slot;
2217 andres 398 ECB : }
399 : #endif
400 :
401 : /*
402 : * ExecQual - evaluate a qual prepared with ExecInitQual (possibly via
403 : * ExecPrepareQual). Returns true if qual is satisfied, else false.
404 : *
405 : * Note: ExecQual used to have a third argument "resultForNull". The
406 : * behavior of this function now corresponds to resultForNull == false.
407 : * If you want the resultForNull == true behavior, see ExecCheck.
408 : */
409 : #ifndef FRONTEND
410 : static inline bool
2217 andres 411 GIC 39187594 : ExecQual(ExprState *state, ExprContext *econtext)
412 : {
413 : Datum ret;
414 : bool isnull;
415 :
416 : /* short-circuit (here and in ExecInitQual) for empty restriction list */
417 39187594 : if (state == NULL)
418 2414813 : return true;
419 :
420 : /* verify that expression was compiled using ExecInitQual */
421 36772781 : Assert(state->flags & EEO_FLAG_IS_QUAL);
422 :
423 36772781 : ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
2217 andres 424 ECB :
425 : /* EEOP_QUAL should never return NULL */
2217 andres 426 GIC 36772753 : Assert(!isnull);
427 :
428 36772753 : return DatumGetBool(ret);
429 : }
2217 andres 430 ECB : #endif
431 :
432 : /*
433 : * ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
1896 434 : * context.
435 : */
436 : #ifndef FRONTEND
437 : static inline bool
1896 andres 438 GIC 11359018 : ExecQualAndReset(ExprState *state, ExprContext *econtext)
1896 andres 439 ECB : {
1896 andres 440 GIC 11359018 : bool ret = ExecQual(state, econtext);
1896 andres 441 ECB :
442 : /* inline ResetExprContext, to avoid ordering issue in this file */
1896 andres 443 GIC 11359018 : MemoryContextReset(econtext->ecxt_per_tuple_memory);
444 11359018 : return ret;
445 : }
446 : #endif
447 :
448 : extern bool ExecCheck(ExprState *state, ExprContext *econtext);
449 :
450 : /*
2217 andres 451 ECB : * prototypes from functions in execSRF.c
452 : */
453 : extern SetExprState *ExecInitTableFunctionResult(Expr *expr,
454 : ExprContext *econtext, PlanState *parent);
455 : extern Tuplestorestate *ExecMakeTableFunctionResult(SetExprState *setexpr,
1418 tgl 456 : ExprContext *econtext,
457 : MemoryContext argContext,
458 : TupleDesc expectedDesc,
459 : bool randomAccess);
460 : extern SetExprState *ExecInitFunctionResultSet(Expr *expr,
461 : ExprContext *econtext, PlanState *parent);
462 : extern Datum ExecMakeFunctionResultSet(SetExprState *fcache,
463 : ExprContext *econtext,
464 : MemoryContext argContext,
465 : bool *isNull,
466 : ExprDoneCond *isDone);
467 :
468 : /*
469 : * prototypes from functions in execScan.c
470 : */
471 : typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
472 : typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
473 :
474 : extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
475 : ExecScanRecheckMtd recheckMtd);
476 : extern void ExecAssignScanProjectionInfo(ScanState *node);
477 : extern void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno);
478 : extern void ExecScanReScan(ScanState *node);
479 :
480 : /*
481 : * prototypes from functions in execTuples.c
482 : */
483 : extern void ExecInitResultTypeTL(PlanState *planstate);
484 : extern void ExecInitResultSlot(PlanState *planstate,
485 : const TupleTableSlotOps *tts_ops);
486 : extern void ExecInitResultTupleSlotTL(PlanState *planstate,
487 : const TupleTableSlotOps *tts_ops);
488 : extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate,
489 : TupleDesc tupledesc,
490 : const TupleTableSlotOps *tts_ops);
491 : extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate,
492 : TupleDesc tupledesc,
493 : const TupleTableSlotOps *tts_ops);
494 : extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate, TupleDesc tupType,
495 : const TupleTableSlotOps *tts_ops);
496 : extern TupleDesc ExecTypeFromTL(List *targetList);
497 : extern TupleDesc ExecCleanTypeFromTL(List *targetList);
498 : extern TupleDesc ExecTypeFromExprList(List *exprList);
499 : extern void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList);
500 : extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
501 :
502 : typedef struct TupOutputState
503 : {
504 : TupleTableSlot *slot;
505 : DestReceiver *dest;
506 : } TupOutputState;
507 :
508 : extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
509 : TupleDesc tupdesc,
510 : const TupleTableSlotOps *tts_ops);
511 : extern void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull);
512 : extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
513 : extern void end_tup_output(TupOutputState *tstate);
514 :
515 : /*
516 : * Write a single line of text given as a C string.
517 : *
518 : * Should only be used with a single-TEXT-attribute tupdesc.
519 : */
520 : #define do_text_output_oneline(tstate, str_to_emit) \
521 : do { \
522 : Datum values_[1]; \
523 : bool isnull_[1]; \
524 : values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
525 : isnull_[0] = false; \
526 : do_tup_output(tstate, values_, isnull_); \
527 : pfree(DatumGetPointer(values_[0])); \
528 : } while (0)
529 :
530 :
531 : /*
532 : * prototypes from functions in execUtils.c
533 : */
534 : extern EState *CreateExecutorState(void);
535 : extern void FreeExecutorState(EState *estate);
536 : extern ExprContext *CreateExprContext(EState *estate);
537 : extern ExprContext *CreateWorkExprContext(EState *estate);
538 : extern ExprContext *CreateStandaloneExprContext(void);
539 : extern void FreeExprContext(ExprContext *econtext, bool isCommit);
540 : extern void ReScanExprContext(ExprContext *econtext);
541 :
542 : #define ResetExprContext(econtext) \
543 : MemoryContextReset((econtext)->ecxt_per_tuple_memory)
544 :
545 : extern ExprContext *MakePerTupleExprContext(EState *estate);
546 :
547 : /* Get an EState's per-output-tuple exprcontext, making it if first use */
548 : #define GetPerTupleExprContext(estate) \
549 : ((estate)->es_per_tuple_exprcontext ? \
550 : (estate)->es_per_tuple_exprcontext : \
551 : MakePerTupleExprContext(estate))
552 :
553 : #define GetPerTupleMemoryContext(estate) \
554 : (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
555 :
556 : /* Reset an EState's per-output-tuple exprcontext, if one's been created */
557 : #define ResetPerTupleExprContext(estate) \
558 : do { \
559 : if ((estate)->es_per_tuple_exprcontext) \
560 : ResetExprContext((estate)->es_per_tuple_exprcontext); \
561 : } while (0)
562 :
563 : extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
564 : extern TupleDesc ExecGetResultType(PlanState *planstate);
565 : extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
566 : bool *isfixed);
567 : extern void ExecAssignProjectionInfo(PlanState *planstate,
568 : TupleDesc inputDesc);
569 : extern void ExecConditionalAssignProjectionInfo(PlanState *planstate,
570 : TupleDesc inputDesc, int varno);
571 : extern void ExecFreeExprContext(PlanState *planstate);
572 : extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
573 : extern void ExecCreateScanSlotFromOuterPlan(EState *estate,
574 : ScanState *scanstate,
575 : const TupleTableSlotOps *tts_ops);
576 :
577 : extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
578 :
579 : extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
580 :
581 : extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos);
582 : extern void ExecCloseRangeTableRelations(EState *estate);
583 : extern void ExecCloseResultRelations(EState *estate);
584 :
585 : static inline RangeTblEntry *
1648 tgl 586 GIC 335949 : exec_rt_fetch(Index rti, EState *estate)
587 : {
1336 588 335949 : return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
589 : }
590 :
591 : extern Relation ExecGetRangeTableRelation(EState *estate, Index rti);
592 : extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
593 : Index rti);
594 :
595 : extern int executor_errposition(EState *estate, int location);
596 :
597 : extern void RegisterExprContextCallback(ExprContext *econtext,
598 : ExprContextCallbackFunction function,
1418 tgl 599 ECB : Datum arg);
600 : extern void UnregisterExprContextCallback(ExprContext *econtext,
601 : ExprContextCallbackFunction function,
602 : Datum arg);
603 :
604 : extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
605 : bool *isNull);
606 : extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
607 : bool *isNull);
608 :
609 : extern int ExecTargetListLength(List *targetlist);
610 : extern int ExecCleanTargetListLength(List *targetlist);
611 :
612 : extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
613 : extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
614 : extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
615 : extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
616 : extern TupleConversionMap *ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate);
617 :
618 : extern Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate);
619 : extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
620 : extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
621 : extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
622 : extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
623 :
624 : /*
625 : * prototypes from functions in execIndexing.c
626 : */
627 : extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
628 : extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
629 : extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
630 : TupleTableSlot *slot, EState *estate,
631 : bool update,
632 : bool noDupErr,
633 : bool *specConflict, List *arbiterIndexes,
634 : bool onlySummarizing);
635 : extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
636 : TupleTableSlot *slot,
637 : EState *estate, ItemPointer conflictTid,
638 : List *arbiterIndexes);
639 : extern void check_exclusion_constraint(Relation heap, Relation index,
640 : IndexInfo *indexInfo,
641 : ItemPointer tupleid,
642 : Datum *values, bool *isnull,
643 : EState *estate, bool newIndex);
644 :
645 : /*
646 : * prototypes from functions in execReplication.c
647 : */
648 : extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
649 : LockTupleMode lockmode,
650 : TupleTableSlot *searchslot,
651 : TupleTableSlot *outslot);
652 : extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
653 : TupleTableSlot *searchslot, TupleTableSlot *outslot);
654 :
655 : extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
656 : EState *estate, TupleTableSlot *slot);
657 : extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
658 : EState *estate, EPQState *epqstate,
659 : TupleTableSlot *searchslot, TupleTableSlot *slot);
660 : extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
661 : EState *estate, EPQState *epqstate,
662 : TupleTableSlot *searchslot);
663 : extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
664 :
665 : extern void CheckSubscriptionRelkind(char relkind, const char *nspname,
666 : const char *relname);
667 :
668 : /*
669 : * prototypes from functions in nodeModifyTable.c
670 : */
671 : extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
672 : TupleTableSlot *planSlot,
673 : TupleTableSlot *oldSlot);
674 : extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
675 : Oid resultoid,
676 : bool missing_ok,
677 : bool update_cache);
678 :
679 : #endif /* EXECUTOR_H */
|