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