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