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 : #ifndef FRONTEND
161 : /*
162 : * Return size of the hash bucket. Useful for estimating memory usage.
163 : */
164 : static inline size_t
165 72796 : TupleHashEntrySize(void)
166 : {
167 72796 : return sizeof(TupleHashEntryData);
168 : }
169 :
170 : /*
171 : * Return tuple from hash entry.
172 : */
173 : static inline MinimalTuple
174 562204 : TupleHashEntryGetTuple(TupleHashEntry entry)
175 : {
176 562204 : return entry->firstTuple;
177 : }
178 :
179 : /*
180 : * Get a pointer into the additional space allocated for this entry. The
181 : * memory will be maxaligned and zeroed.
182 : *
183 : * The amount of space available is the additionalsize requested in the call
184 : * to BuildTupleHashTable(). If additionalsize was specified as zero, return
185 : * NULL.
186 : */
187 : static inline void *
188 8209142 : TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
189 : {
190 8209142 : if (hashtable->additionalsize > 0)
191 6199580 : return (char *) entry->firstTuple - hashtable->additionalsize;
192 : else
193 2009562 : return NULL;
194 : }
195 : #endif
196 :
197 : /*
198 : * prototypes from functions in execJunk.c
199 : */
200 : extern JunkFilter *ExecInitJunkFilter(List *targetList,
201 : TupleTableSlot *slot);
202 : extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
203 : TupleDesc cleanTupType,
204 : TupleTableSlot *slot);
205 : extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
206 : const char *attrName);
207 : extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
208 : const char *attrName);
209 : extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
210 : TupleTableSlot *slot);
211 :
212 : /*
213 : * ExecGetJunkAttribute
214 : *
215 : * Given a junk filter's input tuple (slot) and a junk attribute's number
216 : * previously found by ExecFindJunkAttribute, extract & return the value and
217 : * isNull flag of the attribute.
218 : */
219 : #ifndef FRONTEND
220 : static inline Datum
221 1999532 : ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
222 : {
223 : Assert(attno > 0);
224 1999532 : return slot_getattr(slot, attno, isNull);
225 : }
226 : #endif
227 :
228 : /*
229 : * prototypes from functions in execMain.c
230 : */
231 : extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
232 : extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
233 : extern void ExecutorRun(QueryDesc *queryDesc,
234 : ScanDirection direction, uint64 count);
235 : extern void standard_ExecutorRun(QueryDesc *queryDesc,
236 : ScanDirection direction, uint64 count);
237 : extern void ExecutorFinish(QueryDesc *queryDesc);
238 : extern void standard_ExecutorFinish(QueryDesc *queryDesc);
239 : extern void ExecutorEnd(QueryDesc *queryDesc);
240 : extern void standard_ExecutorEnd(QueryDesc *queryDesc);
241 : extern void ExecutorRewind(QueryDesc *queryDesc);
242 : extern bool ExecCheckPermissions(List *rangeTable,
243 : List *rteperminfos, bool ereport_on_violation);
244 : extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
245 : List *mergeActions);
246 : extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
247 : Relation resultRelationDesc,
248 : Index resultRelationIndex,
249 : ResultRelInfo *partition_root_rri,
250 : int instrument_options);
251 : extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid,
252 : ResultRelInfo *rootRelInfo);
253 : extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo);
254 : extern void ExecConstraints(ResultRelInfo *resultRelInfo,
255 : TupleTableSlot *slot, EState *estate);
256 : extern AttrNumber ExecRelGenVirtualNotNull(ResultRelInfo *resultRelInfo,
257 : TupleTableSlot *slot,
258 : EState *estate,
259 : List *notnull_virtual_attrs);
260 : extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo,
261 : TupleTableSlot *slot, EState *estate, bool emitError);
262 : extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
263 : TupleTableSlot *slot, EState *estate);
264 : extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
265 : TupleTableSlot *slot, EState *estate);
266 : extern char *ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot,
267 : TupleDesc tupdesc,
268 : Bitmapset *modifiedCols,
269 : int maxfieldlen);
270 : extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
271 : extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
272 : extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
273 : extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
274 : Index rti, TupleTableSlot *inputslot);
275 : extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
276 : Plan *subplan, List *auxrowmarks,
277 : int epqParam, List *resultRelations);
278 : extern void EvalPlanQualSetPlan(EPQState *epqstate,
279 : Plan *subplan, List *auxrowmarks);
280 : extern TupleTableSlot *EvalPlanQualSlot(EPQState *epqstate,
281 : Relation relation, Index rti);
282 :
283 : #define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
284 : extern bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot);
285 : extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
286 : extern void EvalPlanQualBegin(EPQState *epqstate);
287 : extern void EvalPlanQualEnd(EPQState *epqstate);
288 :
289 : /*
290 : * functions in execProcnode.c
291 : */
292 : extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
293 : extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
294 : extern Node *MultiExecProcNode(PlanState *node);
295 : extern void ExecEndNode(PlanState *node);
296 : extern void ExecShutdownNode(PlanState *node);
297 : extern void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node);
298 :
299 :
300 : /* ----------------------------------------------------------------
301 : * ExecProcNode
302 : *
303 : * Execute the given node to return a(nother) tuple.
304 : * ----------------------------------------------------------------
305 : */
306 : #ifndef FRONTEND
307 : static inline TupleTableSlot *
308 128046368 : ExecProcNode(PlanState *node)
309 : {
310 128046368 : if (node->chgParam != NULL) /* something changed? */
311 312250 : ExecReScan(node); /* let ReScan handle this */
312 :
313 128046368 : return node->ExecProcNode(node);
314 : }
315 : #endif
316 :
317 : /*
318 : * prototypes from functions in execExpr.c
319 : */
320 : extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
321 : extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
322 : extern ExprState *ExecInitQual(List *qual, PlanState *parent);
323 : extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
324 : extern List *ExecInitExprList(List *nodes, PlanState *parent);
325 : extern ExprState *ExecBuildAggTrans(AggState *aggstate, struct AggStatePerPhaseData *phase,
326 : bool doSort, bool doHash, bool nullcheck);
327 : extern ExprState *ExecBuildHash32FromAttrs(TupleDesc desc,
328 : const TupleTableSlotOps *ops,
329 : FmgrInfo *hashfunctions,
330 : Oid *collations,
331 : int numCols,
332 : AttrNumber *keyColIdx,
333 : PlanState *parent,
334 : uint32 init_value);
335 : extern ExprState *ExecBuildHash32Expr(TupleDesc desc,
336 : const TupleTableSlotOps *ops,
337 : const Oid *hashfunc_oids,
338 : const List *collations,
339 : const List *hash_exprs,
340 : const bool *opstrict, PlanState *parent,
341 : uint32 init_value, bool keep_nulls);
342 : extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
343 : const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
344 : int numCols,
345 : const AttrNumber *keyColIdx,
346 : const Oid *eqfunctions,
347 : const Oid *collations,
348 : PlanState *parent);
349 : extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
350 : const TupleTableSlotOps *lops,
351 : const TupleTableSlotOps *rops,
352 : const Oid *eqfunctions,
353 : const Oid *collations,
354 : const List *param_exprs,
355 : PlanState *parent);
356 : extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
357 : ExprContext *econtext,
358 : TupleTableSlot *slot,
359 : PlanState *parent,
360 : TupleDesc inputDesc);
361 : extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
362 : bool evalTargetList,
363 : List *targetColnos,
364 : TupleDesc relDesc,
365 : ExprContext *econtext,
366 : TupleTableSlot *slot,
367 : PlanState *parent);
368 : extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
369 : extern ExprState *ExecPrepareQual(List *qual, EState *estate);
370 : extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
371 : extern List *ExecPrepareExprList(List *nodes, EState *estate);
372 :
373 : /*
374 : * ExecEvalExpr
375 : *
376 : * Evaluate expression identified by "state" in the execution context
377 : * given by "econtext". *isNull is set to the is-null flag for the result,
378 : * and the Datum value is the function result.
379 : *
380 : * The caller should already have switched into the temporary memory
381 : * context econtext->ecxt_per_tuple_memory. The convenience entry point
382 : * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
383 : * do the switch in an outer loop.
384 : */
385 : #ifndef FRONTEND
386 : static inline Datum
387 22329492 : ExecEvalExpr(ExprState *state,
388 : ExprContext *econtext,
389 : bool *isNull)
390 : {
391 22329492 : return state->evalfunc(state, econtext, isNull);
392 : }
393 : #endif
394 :
395 : /*
396 : * ExecEvalExprNoReturn
397 : *
398 : * Like ExecEvalExpr(), but for cases where no return value is expected,
399 : * because the side-effects of expression evaluation are what's desired. This
400 : * is e.g. used for projection and aggregate transition computation.
401 :
402 : * Evaluate expression identified by "state" in the execution context
403 : * given by "econtext".
404 : *
405 : * The caller should already have switched into the temporary memory context
406 : * econtext->ecxt_per_tuple_memory. The convenience entry point
407 : * ExecEvalExprNoReturnSwitchContext() is provided for callers who don't
408 : * prefer to do the switch in an outer loop.
409 : */
410 : #ifndef FRONTEND
411 : static inline void
412 97953734 : ExecEvalExprNoReturn(ExprState *state,
413 : ExprContext *econtext)
414 : {
415 : PG_USED_FOR_ASSERTS_ONLY Datum retDatum;
416 :
417 97953734 : retDatum = state->evalfunc(state, econtext, NULL);
418 :
419 : Assert(retDatum == (Datum) 0);
420 97940318 : }
421 : #endif
422 :
423 : /*
424 : * ExecEvalExprSwitchContext
425 : *
426 : * Same as ExecEvalExpr, but get into the right allocation context explicitly.
427 : */
428 : #ifndef FRONTEND
429 : static inline Datum
430 116354720 : ExecEvalExprSwitchContext(ExprState *state,
431 : ExprContext *econtext,
432 : bool *isNull)
433 : {
434 : Datum retDatum;
435 : MemoryContext oldContext;
436 :
437 116354720 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
438 116354720 : retDatum = state->evalfunc(state, econtext, isNull);
439 116350808 : MemoryContextSwitchTo(oldContext);
440 116350808 : return retDatum;
441 : }
442 : #endif
443 :
444 : /*
445 : * ExecEvalExprNoReturnSwitchContext
446 : *
447 : * Same as ExecEvalExprNoReturn, but get into the right allocation context
448 : * explicitly.
449 : */
450 : #ifndef FRONTEND
451 : static inline void
452 97953734 : ExecEvalExprNoReturnSwitchContext(ExprState *state,
453 : ExprContext *econtext)
454 : {
455 : MemoryContext oldContext;
456 :
457 97953734 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
458 97953734 : ExecEvalExprNoReturn(state, econtext);
459 97940318 : MemoryContextSwitchTo(oldContext);
460 97940318 : }
461 : #endif
462 :
463 : /*
464 : * ExecProject
465 : *
466 : * Projects a tuple based on projection info and stores it in the slot passed
467 : * to ExecBuildProjectionInfo().
468 : *
469 : * Note: the result is always a virtual tuple; therefore it may reference
470 : * the contents of the exprContext's scan tuples and/or temporary results
471 : * constructed in the exprContext. If the caller wishes the result to be
472 : * valid longer than that data will be valid, he must call ExecMaterializeSlot
473 : * on the result slot.
474 : */
475 : #ifndef FRONTEND
476 : static inline TupleTableSlot *
477 69963254 : ExecProject(ProjectionInfo *projInfo)
478 : {
479 69963254 : ExprContext *econtext = projInfo->pi_exprContext;
480 69963254 : ExprState *state = &projInfo->pi_state;
481 69963254 : TupleTableSlot *slot = state->resultslot;
482 :
483 : /*
484 : * Clear any former contents of the result slot. This makes it safe for
485 : * us to use the slot's Datum/isnull arrays as workspace.
486 : */
487 69963254 : ExecClearTuple(slot);
488 :
489 : /* Run the expression */
490 69963254 : ExecEvalExprNoReturnSwitchContext(state, econtext);
491 :
492 : /*
493 : * Successfully formed a result row. Mark the result slot as containing a
494 : * valid virtual tuple (inlined version of ExecStoreVirtualTuple()).
495 : */
496 69949916 : slot->tts_flags &= ~TTS_FLAG_EMPTY;
497 69949916 : slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
498 :
499 69949916 : return slot;
500 : }
501 : #endif
502 :
503 : /*
504 : * ExecQual - evaluate a qual prepared with ExecInitQual (possibly via
505 : * ExecPrepareQual). Returns true if qual is satisfied, else false.
506 : *
507 : * Note: ExecQual used to have a third argument "resultForNull". The
508 : * behavior of this function now corresponds to resultForNull == false.
509 : * If you want the resultForNull == true behavior, see ExecCheck.
510 : */
511 : #ifndef FRONTEND
512 : static inline bool
513 89830650 : ExecQual(ExprState *state, ExprContext *econtext)
514 : {
515 : Datum ret;
516 : bool isnull;
517 :
518 : /* short-circuit (here and in ExecInitQual) for empty restriction list */
519 89830650 : if (state == NULL)
520 5517136 : return true;
521 :
522 : /* verify that expression was compiled using ExecInitQual */
523 : Assert(state->flags & EEO_FLAG_IS_QUAL);
524 :
525 84313514 : ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
526 :
527 : /* EEOP_QUAL should never return NULL */
528 : Assert(!isnull);
529 :
530 84313480 : return DatumGetBool(ret);
531 : }
532 : #endif
533 :
534 : /*
535 : * ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
536 : * context.
537 : */
538 : #ifndef FRONTEND
539 : static inline bool
540 22651416 : ExecQualAndReset(ExprState *state, ExprContext *econtext)
541 : {
542 22651416 : bool ret = ExecQual(state, econtext);
543 :
544 : /* inline ResetExprContext, to avoid ordering issue in this file */
545 22651416 : MemoryContextReset(econtext->ecxt_per_tuple_memory);
546 22651416 : return ret;
547 : }
548 : #endif
549 :
550 : extern bool ExecCheck(ExprState *state, ExprContext *econtext);
551 :
552 : /*
553 : * prototypes from functions in execSRF.c
554 : */
555 : extern SetExprState *ExecInitTableFunctionResult(Expr *expr,
556 : ExprContext *econtext, PlanState *parent);
557 : extern Tuplestorestate *ExecMakeTableFunctionResult(SetExprState *setexpr,
558 : ExprContext *econtext,
559 : MemoryContext argContext,
560 : TupleDesc expectedDesc,
561 : bool randomAccess);
562 : extern SetExprState *ExecInitFunctionResultSet(Expr *expr,
563 : ExprContext *econtext, PlanState *parent);
564 : extern Datum ExecMakeFunctionResultSet(SetExprState *fcache,
565 : ExprContext *econtext,
566 : MemoryContext argContext,
567 : bool *isNull,
568 : ExprDoneCond *isDone);
569 :
570 : /*
571 : * prototypes from functions in execScan.c
572 : */
573 : typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
574 : typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
575 :
576 : extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
577 : ExecScanRecheckMtd recheckMtd);
578 : extern void ExecAssignScanProjectionInfo(ScanState *node);
579 : extern void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno);
580 : extern void ExecScanReScan(ScanState *node);
581 :
582 : /*
583 : * prototypes from functions in execTuples.c
584 : */
585 : extern void ExecInitResultTypeTL(PlanState *planstate);
586 : extern void ExecInitResultSlot(PlanState *planstate,
587 : const TupleTableSlotOps *tts_ops);
588 : extern void ExecInitResultTupleSlotTL(PlanState *planstate,
589 : const TupleTableSlotOps *tts_ops);
590 : extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate,
591 : TupleDesc tupledesc,
592 : const TupleTableSlotOps *tts_ops);
593 : extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate,
594 : TupleDesc tupledesc,
595 : const TupleTableSlotOps *tts_ops);
596 : extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate, TupleDesc tupType,
597 : const TupleTableSlotOps *tts_ops);
598 : extern TupleDesc ExecTypeFromTL(List *targetList);
599 : extern TupleDesc ExecCleanTypeFromTL(List *targetList);
600 : extern TupleDesc ExecTypeFromExprList(List *exprList);
601 : extern void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList);
602 : extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
603 :
604 : typedef struct TupOutputState
605 : {
606 : TupleTableSlot *slot;
607 : DestReceiver *dest;
608 : } TupOutputState;
609 :
610 : extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
611 : TupleDesc tupdesc,
612 : const TupleTableSlotOps *tts_ops);
613 : extern void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull);
614 : extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
615 : extern void end_tup_output(TupOutputState *tstate);
616 :
617 : /*
618 : * Write a single line of text given as a C string.
619 : *
620 : * Should only be used with a single-TEXT-attribute tupdesc.
621 : */
622 : #define do_text_output_oneline(tstate, str_to_emit) \
623 : do { \
624 : Datum values_[1]; \
625 : bool isnull_[1]; \
626 : values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
627 : isnull_[0] = false; \
628 : do_tup_output(tstate, values_, isnull_); \
629 : pfree(DatumGetPointer(values_[0])); \
630 : } while (0)
631 :
632 :
633 : /*
634 : * prototypes from functions in execUtils.c
635 : */
636 : extern EState *CreateExecutorState(void);
637 : extern void FreeExecutorState(EState *estate);
638 : extern ExprContext *CreateExprContext(EState *estate);
639 : extern ExprContext *CreateWorkExprContext(EState *estate);
640 : extern ExprContext *CreateStandaloneExprContext(void);
641 : extern void FreeExprContext(ExprContext *econtext, bool isCommit);
642 : extern void ReScanExprContext(ExprContext *econtext);
643 :
644 : #define ResetExprContext(econtext) \
645 : MemoryContextReset((econtext)->ecxt_per_tuple_memory)
646 :
647 : extern ExprContext *MakePerTupleExprContext(EState *estate);
648 :
649 : /* Get an EState's per-output-tuple exprcontext, making it if first use */
650 : #define GetPerTupleExprContext(estate) \
651 : ((estate)->es_per_tuple_exprcontext ? \
652 : (estate)->es_per_tuple_exprcontext : \
653 : MakePerTupleExprContext(estate))
654 :
655 : #define GetPerTupleMemoryContext(estate) \
656 : (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
657 :
658 : /* Reset an EState's per-output-tuple exprcontext, if one's been created */
659 : #define ResetPerTupleExprContext(estate) \
660 : do { \
661 : if ((estate)->es_per_tuple_exprcontext) \
662 : ResetExprContext((estate)->es_per_tuple_exprcontext); \
663 : } while (0)
664 :
665 : extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
666 : extern TupleDesc ExecGetResultType(PlanState *planstate);
667 : extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
668 : bool *isfixed);
669 : extern const TupleTableSlotOps *ExecGetCommonSlotOps(PlanState **planstates,
670 : int nplans);
671 : extern const TupleTableSlotOps *ExecGetCommonChildSlotOps(PlanState *ps);
672 : extern void ExecAssignProjectionInfo(PlanState *planstate,
673 : TupleDesc inputDesc);
674 : extern void ExecConditionalAssignProjectionInfo(PlanState *planstate,
675 : TupleDesc inputDesc, int varno);
676 : extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
677 : extern void ExecCreateScanSlotFromOuterPlan(EState *estate,
678 : ScanState *scanstate,
679 : const TupleTableSlotOps *tts_ops);
680 :
681 : extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
682 :
683 : extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
684 :
685 : extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos,
686 : Bitmapset *unpruned_relids);
687 : extern void ExecCloseRangeTableRelations(EState *estate);
688 : extern void ExecCloseResultRelations(EState *estate);
689 :
690 : static inline RangeTblEntry *
691 821100 : exec_rt_fetch(Index rti, EState *estate)
692 : {
693 821100 : return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
694 : }
695 :
696 : extern Relation ExecGetRangeTableRelation(EState *estate, Index rti,
697 : bool isResultRel);
698 : extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
699 : Index rti);
700 :
701 : extern int executor_errposition(EState *estate, int location);
702 :
703 : extern void RegisterExprContextCallback(ExprContext *econtext,
704 : ExprContextCallbackFunction function,
705 : Datum arg);
706 : extern void UnregisterExprContextCallback(ExprContext *econtext,
707 : ExprContextCallbackFunction function,
708 : Datum arg);
709 :
710 : extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
711 : bool *isNull);
712 : extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
713 : bool *isNull);
714 :
715 : extern int ExecTargetListLength(List *targetlist);
716 : extern int ExecCleanTargetListLength(List *targetlist);
717 :
718 : extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
719 : extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
720 : extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
721 : extern TupleTableSlot *ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo);
722 : extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
723 : extern TupleConversionMap *ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate);
724 :
725 : extern Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate);
726 : extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
727 : extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
728 : extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
729 : extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
730 :
731 : /*
732 : * prototypes from functions in execIndexing.c
733 : */
734 : extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
735 : extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
736 : extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
737 : TupleTableSlot *slot, EState *estate,
738 : bool update,
739 : bool noDupErr,
740 : bool *specConflict, List *arbiterIndexes,
741 : bool onlySummarizing);
742 : extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
743 : TupleTableSlot *slot,
744 : EState *estate, ItemPointer conflictTid,
745 : ItemPointer tupleid,
746 : List *arbiterIndexes);
747 : extern void check_exclusion_constraint(Relation heap, Relation index,
748 : IndexInfo *indexInfo,
749 : ItemPointer tupleid,
750 : const Datum *values, const bool *isnull,
751 : EState *estate, bool newIndex);
752 :
753 : /*
754 : * prototypes from functions in execReplication.c
755 : */
756 : extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
757 : LockTupleMode lockmode,
758 : TupleTableSlot *searchslot,
759 : TupleTableSlot *outslot);
760 : extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
761 : TupleTableSlot *searchslot, TupleTableSlot *outslot);
762 :
763 : extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
764 : EState *estate, TupleTableSlot *slot);
765 : extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
766 : EState *estate, EPQState *epqstate,
767 : TupleTableSlot *searchslot, TupleTableSlot *slot);
768 : extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
769 : EState *estate, EPQState *epqstate,
770 : TupleTableSlot *searchslot);
771 : extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
772 :
773 : extern void CheckSubscriptionRelkind(char relkind, const char *nspname,
774 : const char *relname);
775 :
776 : /*
777 : * prototypes from functions in nodeModifyTable.c
778 : */
779 : extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
780 : TupleTableSlot *planSlot,
781 : TupleTableSlot *oldSlot);
782 : extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
783 : Oid resultoid,
784 : bool missing_ok,
785 : bool update_cache);
786 :
787 : #endif /* EXECUTOR_H */
|