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 "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 : : /* Avoid including access/transam.h here */
26 : : typedef struct FullTransactionId FullTransactionId;
27 : :
28 : : /*
29 : : * The "eflags" argument to ExecutorStart and the various ExecInitNode
30 : : * routines is a bitwise OR of the following flag bits, which tell the
31 : : * called plan node what to expect. Note that the flags will get modified
32 : : * as they are passed down the plan tree, since an upper node may require
33 : : * functionality in its subnode not demanded of the plan as a whole
34 : : * (example: MergeJoin requires mark/restore capability in its inner input),
35 : : * or an upper node may shield its input from some functionality requirement
36 : : * (example: Materialize shields its input from needing to do backward scan).
37 : : *
38 : : * EXPLAIN_ONLY indicates that the plan tree is being initialized just so
39 : : * EXPLAIN can print it out; it will not be run. Hence, no side-effects
40 : : * of startup should occur. However, error checks (such as permission checks)
41 : : * should be performed.
42 : : *
43 : : * EXPLAIN_GENERIC can only be used together with EXPLAIN_ONLY. It indicates
44 : : * that a generic plan is being shown using EXPLAIN (GENERIC_PLAN), which
45 : : * means that missing parameter values must be tolerated. Currently, the only
46 : : * effect is to suppress execution-time partition pruning.
47 : : *
48 : : * REWIND indicates that the plan node should try to efficiently support
49 : : * rescans without parameter changes. (Nodes must support ExecReScan calls
50 : : * in any case, but if this flag was not given, they are at liberty to do it
51 : : * through complete recalculation. Note that a parameter change forces a
52 : : * full recalculation in any case.)
53 : : *
54 : : * BACKWARD indicates that the plan node must respect the es_direction flag.
55 : : * When this is not passed, the plan node will only be run forwards.
56 : : *
57 : : * MARK indicates that the plan node must support Mark/Restore calls.
58 : : * When this is not passed, no Mark/Restore will occur.
59 : : *
60 : : * SKIP_TRIGGERS tells ExecutorStart/ExecutorFinish to skip calling
61 : : * AfterTriggerBeginQuery/AfterTriggerEndQuery. This does not necessarily
62 : : * mean that the plan can't queue any AFTER triggers; just that the caller
63 : : * is responsible for there being a trigger context for them to be queued in.
64 : : *
65 : : * WITH_NO_DATA indicates that we are performing REFRESH MATERIALIZED VIEW
66 : : * ... WITH NO DATA. Currently, the only effect is to suppress errors about
67 : : * scanning unpopulated materialized views.
68 : : */
69 : : #define EXEC_FLAG_EXPLAIN_ONLY 0x0001 /* EXPLAIN, no ANALYZE */
70 : : #define EXEC_FLAG_EXPLAIN_GENERIC 0x0002 /* EXPLAIN (GENERIC_PLAN) */
71 : : #define EXEC_FLAG_REWIND 0x0004 /* need efficient rescan */
72 : : #define EXEC_FLAG_BACKWARD 0x0008 /* need backward scan */
73 : : #define EXEC_FLAG_MARK 0x0010 /* need mark/restore */
74 : : #define EXEC_FLAG_SKIP_TRIGGERS 0x0020 /* skip AfterTrigger setup */
75 : : #define EXEC_FLAG_WITH_NO_DATA 0x0040 /* REFRESH ... WITH NO DATA */
76 : :
77 : :
78 : : /* Hook for plugins to get control in ExecutorStart() */
79 : : typedef void (*ExecutorStart_hook_type) (QueryDesc *queryDesc, int eflags);
80 : : extern PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook;
81 : :
82 : : /* Hook for plugins to get control in ExecutorRun() */
83 : : typedef void (*ExecutorRun_hook_type) (QueryDesc *queryDesc,
84 : : ScanDirection direction,
85 : : uint64 count);
86 : : extern PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook;
87 : :
88 : : /* Hook for plugins to get control in ExecutorFinish() */
89 : : typedef void (*ExecutorFinish_hook_type) (QueryDesc *queryDesc);
90 : : extern PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook;
91 : :
92 : : /* Hook for plugins to get control in ExecutorEnd() */
93 : : typedef void (*ExecutorEnd_hook_type) (QueryDesc *queryDesc);
94 : : extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
95 : :
96 : : /* Hook for plugins to get control in ExecCheckPermissions() */
97 : : typedef bool (*ExecutorCheckPerms_hook_type) (List *rangeTable,
98 : : List *rtePermInfos,
99 : : bool ereport_on_violation);
100 : : extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
101 : :
102 : :
103 : : /*
104 : : * prototypes from functions in execAmi.c
105 : : */
106 : : typedef struct Path Path; /* avoid including pathnodes.h here */
107 : :
108 : : extern void ExecReScan(PlanState *node);
109 : : extern void ExecMarkPos(PlanState *node);
110 : : extern void ExecRestrPos(PlanState *node);
111 : : extern bool ExecSupportsMarkRestore(Path *pathnode);
112 : : extern bool ExecSupportsBackwardScan(Plan *node);
113 : : extern bool ExecMaterializesOutput(NodeTag plantype);
114 : :
115 : : /*
116 : : * prototypes from functions in execCurrent.c
117 : : */
118 : : extern bool execCurrentOf(CurrentOfExpr *cexpr,
119 : : ExprContext *econtext,
120 : : Oid table_oid,
121 : : ItemPointer current_tid);
122 : :
123 : : /*
124 : : * prototypes from functions in execGrouping.c
125 : : */
126 : : extern ExprState *execTuplesMatchPrepare(TupleDesc desc,
127 : : int numCols,
128 : : const AttrNumber *keyColIdx,
129 : : const Oid *eqOperators,
130 : : const Oid *collations,
131 : : PlanState *parent);
132 : : extern void execTuplesHashPrepare(int numCols,
133 : : const Oid *eqOperators,
134 : : Oid **eqFuncOids,
135 : : FmgrInfo **hashFunctions);
136 : : extern TupleHashTable BuildTupleHashTable(PlanState *parent,
137 : : TupleDesc inputDesc,
138 : : const TupleTableSlotOps *inputOps,
139 : : int numCols,
140 : : AttrNumber *keyColIdx,
141 : : const Oid *eqfuncoids,
142 : : FmgrInfo *hashfunctions,
143 : : Oid *collations,
144 : : double nelements,
145 : : Size additionalsize,
146 : : MemoryContext metacxt,
147 : : MemoryContext tuplescxt,
148 : : MemoryContext tempcxt,
149 : : bool use_variable_hash_iv);
150 : : extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
151 : : TupleTableSlot *slot,
152 : : bool *isnew, uint32 *hash);
153 : : extern uint32 TupleHashTableHash(TupleHashTable hashtable,
154 : : TupleTableSlot *slot);
155 : : extern TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable,
156 : : TupleTableSlot *slot,
157 : : bool *isnew, uint32 hash);
158 : : extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
159 : : TupleTableSlot *slot,
160 : : ExprState *eqcomp,
161 : : ExprState *hashexpr);
162 : : extern void ResetTupleHashTable(TupleHashTable hashtable);
163 : : extern Size EstimateTupleHashTableSpace(double nentries,
164 : : Size tupleWidth,
165 : : Size additionalsize);
166 : :
167 : : #ifndef FRONTEND
168 : : /*
169 : : * Return size of the hash bucket. Useful for estimating memory usage.
170 : : */
171 : : static inline size_t
614 jdavis@postgresql.or 172 :CBC 63120 : TupleHashEntrySize(void)
173 : : {
174 : 63120 : return sizeof(TupleHashEntryData);
175 : : }
176 : :
177 : : /*
178 : : * Return tuple from hash entry.
179 : : */
180 : : static inline MinimalTuple
181 : 422701 : TupleHashEntryGetTuple(TupleHashEntry entry)
182 : : {
183 : 422701 : return entry->firstTuple;
184 : : }
185 : :
186 : : /*
187 : : * Get a pointer into the additional space allocated for this entry. The
188 : : * memory will be maxaligned and zeroed.
189 : : *
190 : : * The amount of space available is the additionalsize requested in the call
191 : : * to BuildTupleHashTable(). If additionalsize was specified as zero, return
192 : : * NULL.
193 : : */
194 : : static inline void *
195 : 6225259 : TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
196 : : {
197 [ + + ]: 6225259 : if (hashtable->additionalsize > 0)
198 : 4925379 : return (char *) entry->firstTuple - hashtable->additionalsize;
199 : : else
200 : 1299880 : return NULL;
201 : : }
202 : : #endif
203 : :
204 : : /*
205 : : * prototypes from functions in execJunk.c
206 : : */
207 : : extern JunkFilter *ExecInitJunkFilter(List *targetList,
208 : : TupleTableSlot *slot);
209 : : extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
210 : : TupleDesc cleanTupType,
211 : : TupleTableSlot *slot);
212 : : extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
213 : : const char *attrName);
214 : : extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
215 : : const char *attrName);
216 : : extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
217 : : TupleTableSlot *slot);
218 : :
219 : : /*
220 : : * ExecGetJunkAttribute
221 : : *
222 : : * Given a junk filter's input tuple (slot) and a junk attribute's number
223 : : * previously found by ExecFindJunkAttribute, extract & return the value and
224 : : * isNull flag of the attribute.
225 : : */
226 : : #ifndef FRONTEND
227 : : static inline Datum
2068 tgl@sss.pgh.pa.us 228 : 3333904 : ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
229 : : {
230 [ - + ]: 3333904 : Assert(attno > 0);
231 : 3333904 : return slot_getattr(slot, attno, isNull);
232 : : }
233 : : #endif
234 : :
235 : : /*
236 : : * prototypes from functions in execMain.c
237 : : */
238 : : extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
239 : : extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
240 : : extern void ExecutorRun(QueryDesc *queryDesc,
241 : : ScanDirection direction, uint64 count);
242 : : extern void standard_ExecutorRun(QueryDesc *queryDesc,
243 : : ScanDirection direction, uint64 count);
244 : : extern void ExecutorFinish(QueryDesc *queryDesc);
245 : : extern void standard_ExecutorFinish(QueryDesc *queryDesc);
246 : : extern void ExecutorEnd(QueryDesc *queryDesc);
247 : : extern void standard_ExecutorEnd(QueryDesc *queryDesc);
248 : : extern void ExecutorRewind(QueryDesc *queryDesc);
249 : : extern bool ExecCheckPermissions(List *rangeTable,
250 : : List *rteperminfos, bool ereport_on_violation);
251 : : extern bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo);
252 : : extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
253 : : OnConflictAction onConflictAction,
254 : : List *mergeActions);
255 : : extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
256 : : Relation resultRelationDesc,
257 : : Index resultRelationIndex,
258 : : ResultRelInfo *partition_root_rri,
259 : : int instrument_options);
260 : : extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid,
261 : : ResultRelInfo *rootRelInfo);
262 : : extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo);
263 : : extern void ExecConstraints(ResultRelInfo *resultRelInfo,
264 : : TupleTableSlot *slot, EState *estate);
265 : : extern AttrNumber ExecRelGenVirtualNotNull(ResultRelInfo *resultRelInfo,
266 : : TupleTableSlot *slot,
267 : : EState *estate,
268 : : List *notnull_virtual_attrs);
269 : : extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo,
270 : : TupleTableSlot *slot, EState *estate, bool emitError);
271 : : extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
272 : : TupleTableSlot *slot, EState *estate);
273 : : extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
274 : : TupleTableSlot *slot, EState *estate);
275 : : extern char *ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot,
276 : : TupleDesc tupdesc,
277 : : Bitmapset *modifiedCols,
278 : : int maxfieldlen);
279 : : extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
280 : : extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
281 : : extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
282 : : extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
283 : : Index rti, TupleTableSlot *inputslot);
284 : : extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
285 : : Plan *subplan, List *auxrowmarks,
286 : : int epqParam, List *resultRelations);
287 : : extern void EvalPlanQualSetPlan(EPQState *epqstate,
288 : : Plan *subplan, List *auxrowmarks);
289 : : extern TupleTableSlot *EvalPlanQualSlot(EPQState *epqstate,
290 : : Relation relation, Index rti);
291 : :
292 : : #define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
293 : : extern bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot);
294 : : extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
295 : : extern void EvalPlanQualBegin(EPQState *epqstate);
296 : : extern void EvalPlanQualEnd(EPQState *epqstate);
297 : :
298 : : /*
299 : : * functions in execProcnode.c
300 : : */
301 : : extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
302 : : extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
303 : : extern Node *MultiExecProcNode(PlanState *node);
304 : : extern void ExecEndNode(PlanState *node);
305 : : extern void ExecShutdownNode(PlanState *node);
306 : : extern void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node);
307 : :
308 : : /*
309 : : * ExecProcNodeInstr() is implemented in instrument.c, as that allows for
310 : : * inlining of the instrumentation functions, but thematically it ought to be
311 : : * in execProcnode.c.
312 : : */
313 : : extern TupleTableSlot *ExecProcNodeInstr(PlanState *node);
314 : :
315 : :
316 : : /* ----------------------------------------------------------------
317 : : * ExecProcNode
318 : : *
319 : : * Execute the given node to return a(nother) tuple.
320 : : * ----------------------------------------------------------------
321 : : */
322 : : #ifndef FRONTEND
323 : : static inline TupleTableSlot *
3421 andres@anarazel.de 324 : 93533763 : ExecProcNode(PlanState *node)
325 : : {
326 [ + + ]: 93533763 : if (node->chgParam != NULL) /* something changed? */
327 : 237352 : ExecReScan(node); /* let ReScan handle this */
328 : :
329 : 93533763 : return node->ExecProcNode(node);
330 : : }
331 : : #endif
332 : :
333 : : /*
334 : : * prototypes from functions in execExpr.c
335 : : */
336 : : extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
337 : : extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
338 : : extern ExprState *ExecInitQual(List *qual, PlanState *parent);
339 : : extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
340 : : extern List *ExecInitExprList(List *nodes, PlanState *parent);
341 : : extern ExprState *ExecBuildAggTrans(AggState *aggstate, struct AggStatePerPhaseData *phase,
342 : : bool doSort, bool doHash, bool nullcheck);
343 : : extern ExprState *ExecBuildHash32FromAttrs(TupleDesc desc,
344 : : const TupleTableSlotOps *ops,
345 : : FmgrInfo *hashfunctions,
346 : : Oid *collations,
347 : : int numCols,
348 : : AttrNumber *keyColIdx,
349 : : PlanState *parent,
350 : : uint32 init_value);
351 : : extern ExprState *ExecBuildHash32Expr(TupleDesc desc,
352 : : const TupleTableSlotOps *ops,
353 : : const Oid *hashfunc_oids,
354 : : const List *collations,
355 : : const List *hash_exprs,
356 : : const bool *opstrict, PlanState *parent,
357 : : uint32 init_value);
358 : : extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
359 : : const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
360 : : int numCols,
361 : : const AttrNumber *keyColIdx,
362 : : const Oid *eqfunctions,
363 : : const Oid *collations,
364 : : PlanState *parent);
365 : : extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
366 : : const TupleTableSlotOps *lops,
367 : : const TupleTableSlotOps *rops,
368 : : const Oid *eqfunctions,
369 : : const Oid *collations,
370 : : const List *param_exprs,
371 : : PlanState *parent);
372 : : extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
373 : : ExprContext *econtext,
374 : : TupleTableSlot *slot,
375 : : PlanState *parent,
376 : : TupleDesc inputDesc);
377 : : extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
378 : : bool evalTargetList,
379 : : List *targetColnos,
380 : : TupleDesc relDesc,
381 : : ExprContext *econtext,
382 : : TupleTableSlot *slot,
383 : : PlanState *parent);
384 : : extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
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
3546 403 : 17221789 : ExecEvalExpr(ExprState *state,
404 : : ExprContext *econtext,
405 : : bool *isNull)
406 : : {
3369 peter_e@gmx.net 407 : 17221789 : 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
627 dgustafsson@postgres 428 : 71938823 : ExecEvalExprNoReturn(ExprState *state,
429 : : ExprContext *econtext)
430 : : {
431 : : PG_USED_FOR_ASSERTS_ONLY Datum retDatum;
432 : :
433 : 71938823 : retDatum = state->evalfunc(state, econtext, NULL);
434 : :
435 [ - + ]: 71929354 : Assert(retDatum == (Datum) 0);
436 : 71929354 : }
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
3546 andres@anarazel.de 446 : 80252749 : ExecEvalExprSwitchContext(ExprState *state,
447 : : ExprContext *econtext,
448 : : bool *isNull)
449 : : {
450 : : Datum retDatum;
451 : : MemoryContext oldContext;
452 : :
453 : 80252749 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
3369 peter_e@gmx.net 454 : 80252749 : retDatum = state->evalfunc(state, econtext, isNull);
3546 andres@anarazel.de 455 : 80249825 : MemoryContextSwitchTo(oldContext);
456 : 80249825 : 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
627 dgustafsson@postgres 468 : 71938823 : ExecEvalExprNoReturnSwitchContext(ExprState *state,
469 : : ExprContext *econtext)
470 : : {
471 : : MemoryContext oldContext;
472 : :
473 : 71938823 : oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
474 : 71938823 : ExecEvalExprNoReturn(state, econtext);
475 : 71929354 : MemoryContextSwitchTo(oldContext);
476 : 71929354 : }
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 *
3546 andres@anarazel.de 493 : 50658019 : ExecProject(ProjectionInfo *projInfo)
494 : : {
495 : 50658019 : ExprContext *econtext = projInfo->pi_exprContext;
496 : 50658019 : ExprState *state = &projInfo->pi_state;
497 : 50658019 : 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 : 50658019 : ExecClearTuple(slot);
504 : :
505 : : /* Run the expression */
627 dgustafsson@postgres 506 : 50658019 : 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 : : */
2966 andres@anarazel.de 512 : 50648610 : slot->tts_flags &= ~TTS_FLAG_EMPTY;
3546 513 : 50648610 : slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
514 : :
515 : 50648610 : 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 : 61000569 : 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 [ + + ]: 61000569 : if (state == NULL)
536 : 4112109 : return true;
537 : :
538 : : /* verify that expression was compiled using ExecInitQual */
539 [ - + ]: 56888460 : Assert(state->flags & EEO_FLAG_IS_QUAL);
540 : :
541 : 56888460 : ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
542 : :
543 : : /* EEOP_QUAL should never return NULL */
544 [ - + ]: 56888380 : Assert(!isnull);
545 : :
546 : 56888380 : 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
3225 556 : 16664648 : ExecQualAndReset(ExprState *state, ExprContext *econtext)
557 : : {
558 : 16664648 : bool ret = ExecQual(state, econtext);
559 : :
560 : : /* inline ResetExprContext, to avoid ordering issue in this file */
561 : 16664648 : MemoryContextReset(econtext->ecxt_per_tuple_memory);
562 : 16664648 : 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 : : extern void ExecCloseTrigTargetRelations(EState *estate);
709 : :
710 : : static inline RangeTblEntry *
2977 tgl@sss.pgh.pa.us 711 : 552053 : exec_rt_fetch(Index rti, EState *estate)
712 : : {
2665 713 : 552053 : return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
714 : : }
715 : :
716 : : extern Relation ExecGetRangeTableRelation(EState *estate, Index rti,
717 : : bool isResultRel);
718 : : extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
719 : : Index rti);
720 : :
721 : : extern int executor_errposition(EState *estate, int location);
722 : :
723 : : extern void RegisterExprContextCallback(ExprContext *econtext,
724 : : ExprContextCallbackFunction function,
725 : : Datum arg);
726 : : extern void UnregisterExprContextCallback(ExprContext *econtext,
727 : : ExprContextCallbackFunction function,
728 : : Datum arg);
729 : :
730 : : extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
731 : : bool *isNull);
732 : : extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
733 : : bool *isNull);
734 : :
735 : : extern int ExecTargetListLength(List *targetlist);
736 : : extern int ExecCleanTargetListLength(List *targetlist);
737 : :
738 : : extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
739 : : extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
740 : : extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
741 : : extern TupleTableSlot *ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo);
742 : : extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
743 : : extern TupleConversionMap *ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate);
744 : :
745 : : extern Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate);
746 : : extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
747 : : extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
748 : : extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
749 : : extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
750 : :
751 : : /*
752 : : * prototypes from functions in execIndexing.c
753 : : */
754 : : extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
755 : : extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
756 : :
757 : : /* flags for ExecInsertIndexTuples */
758 : : #define EIIT_IS_UPDATE (1<<0)
759 : : #define EIIT_NO_DUPE_ERROR (1<<1)
760 : : #define EIIT_ONLY_SUMMARIZING (1<<2)
761 : : extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, EState *estate,
762 : : uint32 flags, TupleTableSlot *slot,
763 : : List *arbiterIndexes,
764 : : bool *specConflict);
765 : : extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
766 : : TupleTableSlot *slot,
767 : : EState *estate, ItemPointer conflictTid,
768 : : const ItemPointerData *tupleid,
769 : : List *arbiterIndexes);
770 : : extern void check_exclusion_constraint(Relation heap, Relation index,
771 : : IndexInfo *indexInfo,
772 : : const ItemPointerData *tupleid,
773 : : const Datum *values, const bool *isnull,
774 : : EState *estate, bool newIndex);
775 : :
776 : : /*
777 : : * prototypes from functions in execReplication.c
778 : : */
779 : : extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
780 : : bool skipduplicates,
781 : : LockTupleMode lockmode,
782 : : TupleTableSlot *searchslot,
783 : : TupleTableSlot *outslot);
784 : : extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
785 : : TupleTableSlot *searchslot, TupleTableSlot *outslot);
786 : : extern bool RelationFindDeletedTupleInfoSeq(Relation rel, Oid identidxoid,
787 : : TupleTableSlot *searchslot,
788 : : TransactionId oldestxmin,
789 : : FullTransactionId *delete_xid,
790 : : ReplOriginId *delete_origin,
791 : : TimestampTz *delete_time);
792 : : extern bool RelationFindDeletedTupleInfoByIndex(Relation rel, Oid idxoid,
793 : : bool skipduplicates,
794 : : TupleTableSlot *searchslot,
795 : : TransactionId oldestxmin,
796 : : FullTransactionId *delete_xid,
797 : : ReplOriginId *delete_origin,
798 : : TimestampTz *delete_time);
799 : : extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
800 : : EState *estate, TupleTableSlot *slot);
801 : : extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
802 : : EState *estate, EPQState *epqstate,
803 : : TupleTableSlot *searchslot, TupleTableSlot *slot);
804 : : extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
805 : : EState *estate, EPQState *epqstate,
806 : : TupleTableSlot *searchslot);
807 : : extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
808 : :
809 : : extern void CheckSubscriptionTargetRel(Oid relid, char remoterelkind,
810 : : const char *nspname,
811 : : const char *relname);
812 : :
813 : : /*
814 : : * prototypes from functions in nodeModifyTable.c
815 : : */
816 : : extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
817 : : TupleTableSlot *planSlot,
818 : : TupleTableSlot *oldSlot);
819 : : extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
820 : : Oid resultoid,
821 : : bool missing_ok,
822 : : bool update_cache);
823 : :
824 : : #endif /* EXECUTOR_H */
|