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

Generated by: LCOV version 1.14