LCOV - code coverage report
Current view: top level - src/include/executor - executor.h (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 49 49
Test Date: 2026-07-03 19:57:34 Functions: 100.0 % 13 13
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 6 6

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

Generated by: LCOV version 2.0-1