LCOV - code coverage report
Current view: top level - src/include/executor - executor.h (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 49 49
Test Date: 2026-02-17 17:20:33 Functions: 100.0 % 13 13
Legend: Lines:     hit not hit

            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
     169        43398 : TupleHashEntrySize(void)
     170              : {
     171        43398 :     return sizeof(TupleHashEntryData);
     172              : }
     173              : 
     174              : /*
     175              :  * Return tuple from hash entry.
     176              :  */
     177              : static inline MinimalTuple
     178       281700 : TupleHashEntryGetTuple(TupleHashEntry entry)
     179              : {
     180       281700 :     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      4631041 : TupleHashEntryGetAdditional(TupleHashTable hashtable, TupleHashEntry entry)
     193              : {
     194      4631041 :     if (hashtable->additionalsize > 0)
     195      3709214 :         return (char *) entry->firstTuple - hashtable->additionalsize;
     196              :     else
     197       921827 :         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
     225      1077484 : ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
     226              : {
     227              :     Assert(attno > 0);
     228      1077484 :     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 *
     314     65654092 : ExecProcNode(PlanState *node)
     315              : {
     316     65654092 :     if (node->chgParam != NULL) /* something changed? */
     317       155040 :         ExecReScan(node);       /* let ReScan handle this */
     318              : 
     319     65654092 :     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 *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
     328              : extern ExprState *ExecInitQual(List *qual, PlanState *parent);
     329              : extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
     330              : extern List *ExecInitExprList(List *nodes, PlanState *parent);
     331              : extern ExprState *ExecBuildAggTrans(AggState *aggstate, struct AggStatePerPhaseData *phase,
     332              :                                     bool doSort, bool doHash, bool nullcheck);
     333              : extern ExprState *ExecBuildHash32FromAttrs(TupleDesc desc,
     334              :                                            const TupleTableSlotOps *ops,
     335              :                                            FmgrInfo *hashfunctions,
     336              :                                            Oid *collations,
     337              :                                            int numCols,
     338              :                                            AttrNumber *keyColIdx,
     339              :                                            PlanState *parent,
     340              :                                            uint32 init_value);
     341              : extern ExprState *ExecBuildHash32Expr(TupleDesc desc,
     342              :                                       const TupleTableSlotOps *ops,
     343              :                                       const Oid *hashfunc_oids,
     344              :                                       const List *collations,
     345              :                                       const List *hash_exprs,
     346              :                                       const bool *opstrict, PlanState *parent,
     347              :                                       uint32 init_value, bool keep_nulls);
     348              : extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
     349              :                                          const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
     350              :                                          int numCols,
     351              :                                          const AttrNumber *keyColIdx,
     352              :                                          const Oid *eqfunctions,
     353              :                                          const Oid *collations,
     354              :                                          PlanState *parent);
     355              : extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
     356              :                                          const TupleTableSlotOps *lops,
     357              :                                          const TupleTableSlotOps *rops,
     358              :                                          const Oid *eqfunctions,
     359              :                                          const Oid *collations,
     360              :                                          const List *param_exprs,
     361              :                                          PlanState *parent);
     362              : extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
     363              :                                                ExprContext *econtext,
     364              :                                                TupleTableSlot *slot,
     365              :                                                PlanState *parent,
     366              :                                                TupleDesc inputDesc);
     367              : extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
     368              :                                                  bool evalTargetList,
     369              :                                                  List *targetColnos,
     370              :                                                  TupleDesc relDesc,
     371              :                                                  ExprContext *econtext,
     372              :                                                  TupleTableSlot *slot,
     373              :                                                  PlanState *parent);
     374              : extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
     375              : extern ExprState *ExecPrepareQual(List *qual, EState *estate);
     376              : extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
     377              : extern List *ExecPrepareExprList(List *nodes, EState *estate);
     378              : 
     379              : /*
     380              :  * ExecEvalExpr
     381              :  *
     382              :  * Evaluate expression identified by "state" in the execution context
     383              :  * given by "econtext".  *isNull is set to the is-null flag for the result,
     384              :  * and the Datum value is the function result.
     385              :  *
     386              :  * The caller should already have switched into the temporary memory
     387              :  * context econtext->ecxt_per_tuple_memory.  The convenience entry point
     388              :  * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
     389              :  * do the switch in an outer loop.
     390              :  */
     391              : #ifndef FRONTEND
     392              : static inline Datum
     393     12050118 : ExecEvalExpr(ExprState *state,
     394              :              ExprContext *econtext,
     395              :              bool *isNull)
     396              : {
     397     12050118 :     return state->evalfunc(state, econtext, isNull);
     398              : }
     399              : #endif
     400              : 
     401              : /*
     402              :  * ExecEvalExprNoReturn
     403              :  *
     404              :  * Like ExecEvalExpr(), but for cases where no return value is expected,
     405              :  * because the side-effects of expression evaluation are what's desired. This
     406              :  * is e.g. used for projection and aggregate transition computation.
     407              :  *
     408              :  * Evaluate expression identified by "state" in the execution context
     409              :  * given by "econtext".
     410              :  *
     411              :  * The caller should already have switched into the temporary memory context
     412              :  * econtext->ecxt_per_tuple_memory.  The convenience entry point
     413              :  * ExecEvalExprNoReturnSwitchContext() is provided for callers who don't
     414              :  * prefer to do the switch in an outer loop.
     415              :  */
     416              : #ifndef FRONTEND
     417              : static inline void
     418     50348167 : ExecEvalExprNoReturn(ExprState *state,
     419              :                      ExprContext *econtext)
     420              : {
     421              :     PG_USED_FOR_ASSERTS_ONLY Datum retDatum;
     422              : 
     423     50348167 :     retDatum = state->evalfunc(state, econtext, NULL);
     424              : 
     425              :     Assert(retDatum == (Datum) 0);
     426     50341315 : }
     427              : #endif
     428              : 
     429              : /*
     430              :  * ExecEvalExprSwitchContext
     431              :  *
     432              :  * Same as ExecEvalExpr, but get into the right allocation context explicitly.
     433              :  */
     434              : #ifndef FRONTEND
     435              : static inline Datum
     436     60230213 : ExecEvalExprSwitchContext(ExprState *state,
     437              :                           ExprContext *econtext,
     438              :                           bool *isNull)
     439              : {
     440              :     Datum       retDatum;
     441              :     MemoryContext oldContext;
     442              : 
     443     60230213 :     oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
     444     60230213 :     retDatum = state->evalfunc(state, econtext, isNull);
     445     60228194 :     MemoryContextSwitchTo(oldContext);
     446     60228194 :     return retDatum;
     447              : }
     448              : #endif
     449              : 
     450              : /*
     451              :  * ExecEvalExprNoReturnSwitchContext
     452              :  *
     453              :  * Same as ExecEvalExprNoReturn, but get into the right allocation context
     454              :  * explicitly.
     455              :  */
     456              : #ifndef FRONTEND
     457              : static inline void
     458     50348167 : ExecEvalExprNoReturnSwitchContext(ExprState *state,
     459              :                                   ExprContext *econtext)
     460              : {
     461              :     MemoryContext oldContext;
     462              : 
     463     50348167 :     oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
     464     50348167 :     ExecEvalExprNoReturn(state, econtext);
     465     50341315 :     MemoryContextSwitchTo(oldContext);
     466     50341315 : }
     467              : #endif
     468              : 
     469              : /*
     470              :  * ExecProject
     471              :  *
     472              :  * Projects a tuple based on projection info and stores it in the slot passed
     473              :  * to ExecBuildProjectionInfo().
     474              :  *
     475              :  * Note: the result is always a virtual tuple; therefore it may reference
     476              :  * the contents of the exprContext's scan tuples and/or temporary results
     477              :  * constructed in the exprContext.  If the caller wishes the result to be
     478              :  * valid longer than that data will be valid, he must call ExecMaterializeSlot
     479              :  * on the result slot.
     480              :  */
     481              : #ifndef FRONTEND
     482              : static inline TupleTableSlot *
     483     35279530 : ExecProject(ProjectionInfo *projInfo)
     484              : {
     485     35279530 :     ExprContext *econtext = projInfo->pi_exprContext;
     486     35279530 :     ExprState  *state = &projInfo->pi_state;
     487     35279530 :     TupleTableSlot *slot = state->resultslot;
     488              : 
     489              :     /*
     490              :      * Clear any former contents of the result slot.  This makes it safe for
     491              :      * us to use the slot's Datum/isnull arrays as workspace.
     492              :      */
     493     35279530 :     ExecClearTuple(slot);
     494              : 
     495              :     /* Run the expression */
     496     35279530 :     ExecEvalExprNoReturnSwitchContext(state, econtext);
     497              : 
     498              :     /*
     499              :      * Successfully formed a result row.  Mark the result slot as containing a
     500              :      * valid virtual tuple (inlined version of ExecStoreVirtualTuple()).
     501              :      */
     502     35272717 :     slot->tts_flags &= ~TTS_FLAG_EMPTY;
     503     35272717 :     slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
     504              : 
     505     35272717 :     return slot;
     506              : }
     507              : #endif
     508              : 
     509              : /*
     510              :  * ExecQual - evaluate a qual prepared with ExecInitQual (possibly via
     511              :  * ExecPrepareQual).  Returns true if qual is satisfied, else false.
     512              :  *
     513              :  * Note: ExecQual used to have a third argument "resultForNull".  The
     514              :  * behavior of this function now corresponds to resultForNull == false.
     515              :  * If you want the resultForNull == true behavior, see ExecCheck.
     516              :  */
     517              : #ifndef FRONTEND
     518              : static inline bool
     519     46739994 : ExecQual(ExprState *state, ExprContext *econtext)
     520              : {
     521              :     Datum       ret;
     522              :     bool        isnull;
     523              : 
     524              :     /* short-circuit (here and in ExecInitQual) for empty restriction list */
     525     46739994 :     if (state == NULL)
     526      2877896 :         return true;
     527              : 
     528              :     /* verify that expression was compiled using ExecInitQual */
     529              :     Assert(state->flags & EEO_FLAG_IS_QUAL);
     530              : 
     531     43862098 :     ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
     532              : 
     533              :     /* EEOP_QUAL should never return NULL */
     534              :     Assert(!isnull);
     535              : 
     536     43862081 :     return DatumGetBool(ret);
     537              : }
     538              : #endif
     539              : 
     540              : /*
     541              :  * ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
     542              :  * context.
     543              :  */
     544              : #ifndef FRONTEND
     545              : static inline bool
     546     12708107 : ExecQualAndReset(ExprState *state, ExprContext *econtext)
     547              : {
     548     12708107 :     bool        ret = ExecQual(state, econtext);
     549              : 
     550              :     /* inline ResetExprContext, to avoid ordering issue in this file */
     551     12708107 :     MemoryContextReset(econtext->ecxt_per_tuple_memory);
     552     12708107 :     return ret;
     553              : }
     554              : #endif
     555              : 
     556              : extern bool ExecCheck(ExprState *state, ExprContext *econtext);
     557              : 
     558              : /*
     559              :  * prototypes from functions in execSRF.c
     560              :  */
     561              : extern SetExprState *ExecInitTableFunctionResult(Expr *expr,
     562              :                                                  ExprContext *econtext, PlanState *parent);
     563              : extern Tuplestorestate *ExecMakeTableFunctionResult(SetExprState *setexpr,
     564              :                                                     ExprContext *econtext,
     565              :                                                     MemoryContext argContext,
     566              :                                                     TupleDesc expectedDesc,
     567              :                                                     bool randomAccess);
     568              : extern SetExprState *ExecInitFunctionResultSet(Expr *expr,
     569              :                                                ExprContext *econtext, PlanState *parent);
     570              : extern Datum ExecMakeFunctionResultSet(SetExprState *fcache,
     571              :                                        ExprContext *econtext,
     572              :                                        MemoryContext argContext,
     573              :                                        bool *isNull,
     574              :                                        ExprDoneCond *isDone);
     575              : 
     576              : /*
     577              :  * prototypes from functions in execScan.c
     578              :  */
     579              : typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
     580              : typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
     581              : 
     582              : extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
     583              :                                 ExecScanRecheckMtd recheckMtd);
     584              : extern void ExecAssignScanProjectionInfo(ScanState *node);
     585              : extern void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno);
     586              : extern void ExecScanReScan(ScanState *node);
     587              : 
     588              : /*
     589              :  * prototypes from functions in execTuples.c
     590              :  */
     591              : extern void ExecInitResultTypeTL(PlanState *planstate);
     592              : extern void ExecInitResultSlot(PlanState *planstate,
     593              :                                const TupleTableSlotOps *tts_ops);
     594              : extern void ExecInitResultTupleSlotTL(PlanState *planstate,
     595              :                                       const TupleTableSlotOps *tts_ops);
     596              : extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate,
     597              :                                   TupleDesc tupledesc,
     598              :                                   const TupleTableSlotOps *tts_ops);
     599              : extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate,
     600              :                                               TupleDesc tupledesc,
     601              :                                               const TupleTableSlotOps *tts_ops);
     602              : extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate, TupleDesc tupType,
     603              :                                              const TupleTableSlotOps *tts_ops);
     604              : extern TupleDesc ExecTypeFromTL(List *targetList);
     605              : extern TupleDesc ExecCleanTypeFromTL(List *targetList);
     606              : extern TupleDesc ExecTypeFromExprList(List *exprList);
     607              : extern void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList);
     608              : extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
     609              : 
     610              : typedef struct TupOutputState
     611              : {
     612              :     TupleTableSlot *slot;
     613              :     DestReceiver *dest;
     614              : } TupOutputState;
     615              : 
     616              : extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
     617              :                                                 TupleDesc tupdesc,
     618              :                                                 const TupleTableSlotOps *tts_ops);
     619              : extern void do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull);
     620              : extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
     621              : extern void end_tup_output(TupOutputState *tstate);
     622              : 
     623              : /*
     624              :  * Write a single line of text given as a C string.
     625              :  *
     626              :  * Should only be used with a single-TEXT-attribute tupdesc.
     627              :  */
     628              : #define do_text_output_oneline(tstate, str_to_emit) \
     629              :     do { \
     630              :         Datum   values_[1]; \
     631              :         bool    isnull_[1]; \
     632              :         values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
     633              :         isnull_[0] = false; \
     634              :         do_tup_output(tstate, values_, isnull_); \
     635              :         pfree(DatumGetPointer(values_[0])); \
     636              :     } while (0)
     637              : 
     638              : 
     639              : /*
     640              :  * prototypes from functions in execUtils.c
     641              :  */
     642              : extern EState *CreateExecutorState(void);
     643              : extern void FreeExecutorState(EState *estate);
     644              : extern ExprContext *CreateExprContext(EState *estate);
     645              : extern ExprContext *CreateWorkExprContext(EState *estate);
     646              : extern ExprContext *CreateStandaloneExprContext(void);
     647              : extern void FreeExprContext(ExprContext *econtext, bool isCommit);
     648              : extern void ReScanExprContext(ExprContext *econtext);
     649              : 
     650              : #define ResetExprContext(econtext) \
     651              :     MemoryContextReset((econtext)->ecxt_per_tuple_memory)
     652              : 
     653              : extern ExprContext *MakePerTupleExprContext(EState *estate);
     654              : 
     655              : /* Get an EState's per-output-tuple exprcontext, making it if first use */
     656              : #define GetPerTupleExprContext(estate) \
     657              :     ((estate)->es_per_tuple_exprcontext ? \
     658              :      (estate)->es_per_tuple_exprcontext : \
     659              :      MakePerTupleExprContext(estate))
     660              : 
     661              : #define GetPerTupleMemoryContext(estate) \
     662              :     (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
     663              : 
     664              : /* Reset an EState's per-output-tuple exprcontext, if one's been created */
     665              : #define ResetPerTupleExprContext(estate) \
     666              :     do { \
     667              :         if ((estate)->es_per_tuple_exprcontext) \
     668              :             ResetExprContext((estate)->es_per_tuple_exprcontext); \
     669              :     } while (0)
     670              : 
     671              : extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
     672              : extern TupleDesc ExecGetResultType(PlanState *planstate);
     673              : extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
     674              :                                                      bool *isfixed);
     675              : extern const TupleTableSlotOps *ExecGetCommonSlotOps(PlanState **planstates,
     676              :                                                      int nplans);
     677              : extern const TupleTableSlotOps *ExecGetCommonChildSlotOps(PlanState *ps);
     678              : extern void ExecAssignProjectionInfo(PlanState *planstate,
     679              :                                      TupleDesc inputDesc);
     680              : extern void ExecConditionalAssignProjectionInfo(PlanState *planstate,
     681              :                                                 TupleDesc inputDesc, int varno);
     682              : extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
     683              : extern void ExecCreateScanSlotFromOuterPlan(EState *estate,
     684              :                                             ScanState *scanstate,
     685              :                                             const TupleTableSlotOps *tts_ops);
     686              : 
     687              : extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
     688              : 
     689              : extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
     690              : 
     691              : extern void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos,
     692              :                                Bitmapset *unpruned_relids);
     693              : extern void ExecCloseRangeTableRelations(EState *estate);
     694              : extern void ExecCloseResultRelations(EState *estate);
     695              : 
     696              : static inline RangeTblEntry *
     697       436230 : exec_rt_fetch(Index rti, EState *estate)
     698              : {
     699       436230 :     return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
     700              : }
     701              : 
     702              : extern Relation ExecGetRangeTableRelation(EState *estate, Index rti,
     703              :                                           bool isResultRel);
     704              : extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
     705              :                                    Index rti);
     706              : 
     707              : extern int  executor_errposition(EState *estate, int location);
     708              : 
     709              : extern void RegisterExprContextCallback(ExprContext *econtext,
     710              :                                         ExprContextCallbackFunction function,
     711              :                                         Datum arg);
     712              : extern void UnregisterExprContextCallback(ExprContext *econtext,
     713              :                                           ExprContextCallbackFunction function,
     714              :                                           Datum arg);
     715              : 
     716              : extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
     717              :                                 bool *isNull);
     718              : extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
     719              :                                bool *isNull);
     720              : 
     721              : extern int  ExecTargetListLength(List *targetlist);
     722              : extern int  ExecCleanTargetListLength(List *targetlist);
     723              : 
     724              : extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
     725              : extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
     726              : extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
     727              : extern TupleTableSlot *ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo);
     728              : extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
     729              : extern TupleConversionMap *ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate);
     730              : 
     731              : extern Oid  ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate);
     732              : extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
     733              : extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
     734              : extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
     735              : extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
     736              : 
     737              : /*
     738              :  * prototypes from functions in execIndexing.c
     739              :  */
     740              : extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
     741              : extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
     742              : extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
     743              :                                    TupleTableSlot *slot, EState *estate,
     744              :                                    bool update,
     745              :                                    bool noDupErr,
     746              :                                    bool *specConflict, List *arbiterIndexes,
     747              :                                    bool onlySummarizing);
     748              : extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
     749              :                                       TupleTableSlot *slot,
     750              :                                       EState *estate, ItemPointer conflictTid,
     751              :                                       const ItemPointerData *tupleid,
     752              :                                       List *arbiterIndexes);
     753              : extern void check_exclusion_constraint(Relation heap, Relation index,
     754              :                                        IndexInfo *indexInfo,
     755              :                                        const ItemPointerData *tupleid,
     756              :                                        const Datum *values, const bool *isnull,
     757              :                                        EState *estate, bool newIndex);
     758              : 
     759              : /*
     760              :  * prototypes from functions in execReplication.c
     761              :  */
     762              : extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
     763              :                                          LockTupleMode lockmode,
     764              :                                          TupleTableSlot *searchslot,
     765              :                                          TupleTableSlot *outslot);
     766              : extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
     767              :                                      TupleTableSlot *searchslot, TupleTableSlot *outslot);
     768              : extern bool RelationFindDeletedTupleInfoSeq(Relation rel,
     769              :                                             TupleTableSlot *searchslot,
     770              :                                             TransactionId oldestxmin,
     771              :                                             TransactionId *delete_xid,
     772              :                                             ReplOriginId *delete_origin,
     773              :                                             TimestampTz *delete_time);
     774              : extern bool RelationFindDeletedTupleInfoByIndex(Relation rel, Oid idxoid,
     775              :                                                 TupleTableSlot *searchslot,
     776              :                                                 TransactionId oldestxmin,
     777              :                                                 TransactionId *delete_xid,
     778              :                                                 ReplOriginId *delete_origin,
     779              :                                                 TimestampTz *delete_time);
     780              : extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
     781              :                                      EState *estate, TupleTableSlot *slot);
     782              : extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
     783              :                                      EState *estate, EPQState *epqstate,
     784              :                                      TupleTableSlot *searchslot, TupleTableSlot *slot);
     785              : extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
     786              :                                      EState *estate, EPQState *epqstate,
     787              :                                      TupleTableSlot *searchslot);
     788              : extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
     789              : 
     790              : extern void CheckSubscriptionRelkind(char localrelkind, char remoterelkind,
     791              :                                      const char *nspname, const char *relname);
     792              : 
     793              : /*
     794              :  * prototypes from functions in nodeModifyTable.c
     795              :  */
     796              : extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
     797              :                                              TupleTableSlot *planSlot,
     798              :                                              TupleTableSlot *oldSlot);
     799              : extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
     800              :                                                Oid resultoid,
     801              :                                                bool missing_ok,
     802              :                                                bool update_cache);
     803              : 
     804              : #endif                          /* EXECUTOR_H  */
        

Generated by: LCOV version 2.0-1