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