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

Generated by: LCOV version 2.0-1