executor.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*-------------------------------------------------------------------------
  2. *
  3. * executor.h
  4. * support for the POSTGRES executor module
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, 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. #include "executor/execdesc.h"
  17. #include "fmgr.h"
  18. #include "nodes/lockoptions.h"
  19. #include "nodes/parsenodes.h"
  20. #include "utils/memutils.h"
  21. /*
  22. * The "eflags" argument to ExecutorStart and the various ExecInitNode
  23. * routines is a bitwise OR of the following flag bits, which tell the
  24. * called plan node what to expect. Note that the flags will get modified
  25. * as they are passed down the plan tree, since an upper node may require
  26. * functionality in its subnode not demanded of the plan as a whole
  27. * (example: MergeJoin requires mark/restore capability in its inner input),
  28. * or an upper node may shield its input from some functionality requirement
  29. * (example: Materialize shields its input from needing to do backward scan).
  30. *
  31. * EXPLAIN_ONLY indicates that the plan tree is being initialized just so
  32. * EXPLAIN can print it out; it will not be run. Hence, no side-effects
  33. * of startup should occur. However, error checks (such as permission checks)
  34. * should be performed.
  35. *
  36. * REWIND indicates that the plan node should try to efficiently support
  37. * rescans without parameter changes. (Nodes must support ExecReScan calls
  38. * in any case, but if this flag was not given, they are at liberty to do it
  39. * through complete recalculation. Note that a parameter change forces a
  40. * full recalculation in any case.)
  41. *
  42. * BACKWARD indicates that the plan node must respect the es_direction flag.
  43. * When this is not passed, the plan node will only be run forwards.
  44. *
  45. * MARK indicates that the plan node must support Mark/Restore calls.
  46. * When this is not passed, no Mark/Restore will occur.
  47. *
  48. * SKIP_TRIGGERS tells ExecutorStart/ExecutorFinish to skip calling
  49. * AfterTriggerBeginQuery/AfterTriggerEndQuery. This does not necessarily
  50. * mean that the plan can't queue any AFTER triggers; just that the caller
  51. * is responsible for there being a trigger context for them to be queued in.
  52. */
  53. #define EXEC_FLAG_EXPLAIN_ONLY 0x0001 /* EXPLAIN, no ANALYZE */
  54. #define EXEC_FLAG_REWIND 0x0002 /* need efficient rescan */
  55. #define EXEC_FLAG_BACKWARD 0x0004 /* need backward scan */
  56. #define EXEC_FLAG_MARK 0x0008 /* need mark/restore */
  57. #define EXEC_FLAG_SKIP_TRIGGERS 0x0010 /* skip AfterTrigger calls */
  58. #define EXEC_FLAG_WITH_NO_DATA 0x0020 /* rel scannability doesn't matter */
  59. /* Hook for plugins to get control in ExecutorStart() */
  60. typedef void (*ExecutorStart_hook_type) (QueryDesc *queryDesc, int eflags);
  61. extern PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook;
  62. /* Hook for plugins to get control in ExecutorRun() */
  63. typedef void (*ExecutorRun_hook_type) (QueryDesc *queryDesc,
  64. ScanDirection direction,
  65. uint64 count,
  66. bool execute_once);
  67. extern PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook;
  68. /* Hook for plugins to get control in ExecutorFinish() */
  69. typedef void (*ExecutorFinish_hook_type) (QueryDesc *queryDesc);
  70. extern PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook;
  71. /* Hook for plugins to get control in ExecutorEnd() */
  72. typedef void (*ExecutorEnd_hook_type) (QueryDesc *queryDesc);
  73. extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
  74. /* Hook for plugins to get control in ExecCheckRTPerms() */
  75. typedef bool (*ExecutorCheckPerms_hook_type) (List *, bool);
  76. extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
  77. /*
  78. * prototypes from functions in execAmi.c
  79. */
  80. struct Path; /* avoid including pathnodes.h here */
  81. extern void ExecReScan(PlanState *node);
  82. extern void ExecMarkPos(PlanState *node);
  83. extern void ExecRestrPos(PlanState *node);
  84. extern bool ExecSupportsMarkRestore(struct Path *pathnode);
  85. extern bool ExecSupportsBackwardScan(Plan *node);
  86. extern bool ExecMaterializesOutput(NodeTag plantype);
  87. /*
  88. * prototypes from functions in execCurrent.c
  89. */
  90. extern bool execCurrentOf(CurrentOfExpr *cexpr,
  91. ExprContext *econtext,
  92. Oid table_oid,
  93. ItemPointer current_tid);
  94. /*
  95. * prototypes from functions in execGrouping.c
  96. */
  97. extern ExprState *execTuplesMatchPrepare(TupleDesc desc,
  98. int numCols,
  99. const AttrNumber *keyColIdx,
  100. const Oid *eqOperators,
  101. const Oid *collations,
  102. PlanState *parent);
  103. extern void execTuplesHashPrepare(int numCols,
  104. const Oid *eqOperators,
  105. Oid **eqFuncOids,
  106. FmgrInfo **hashFunctions);
  107. extern TupleHashTable BuildTupleHashTable(PlanState *parent,
  108. TupleDesc inputDesc,
  109. int numCols, AttrNumber *keyColIdx,
  110. const Oid *eqfuncoids,
  111. FmgrInfo *hashfunctions,
  112. Oid *collations,
  113. long nbuckets, Size additionalsize,
  114. MemoryContext tablecxt,
  115. MemoryContext tempcxt, bool use_variable_hash_iv);
  116. extern TupleHashTable BuildTupleHashTableExt(PlanState *parent,
  117. TupleDesc inputDesc,
  118. int numCols, AttrNumber *keyColIdx,
  119. const Oid *eqfuncoids,
  120. FmgrInfo *hashfunctions,
  121. Oid *collations,
  122. long nbuckets, Size additionalsize,
  123. MemoryContext metacxt,
  124. MemoryContext tablecxt,
  125. MemoryContext tempcxt, bool use_variable_hash_iv);
  126. extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
  127. TupleTableSlot *slot,
  128. bool *isnew, uint32 *hash);
  129. extern uint32 TupleHashTableHash(TupleHashTable hashtable,
  130. TupleTableSlot *slot);
  131. extern TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable,
  132. TupleTableSlot *slot,
  133. bool *isnew, uint32 hash);
  134. extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
  135. TupleTableSlot *slot,
  136. ExprState *eqcomp,
  137. FmgrInfo *hashfunctions);
  138. extern void ResetTupleHashTable(TupleHashTable hashtable);
  139. /*
  140. * prototypes from functions in execJunk.c
  141. */
  142. extern JunkFilter *ExecInitJunkFilter(List *targetList,
  143. TupleTableSlot *slot);
  144. extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
  145. TupleDesc cleanTupType,
  146. TupleTableSlot *slot);
  147. extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
  148. const char *attrName);
  149. extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
  150. const char *attrName);
  151. extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
  152. TupleTableSlot *slot);
  153. /*
  154. * ExecGetJunkAttribute
  155. *
  156. * Given a junk filter's input tuple (slot) and a junk attribute's number
  157. * previously found by ExecFindJunkAttribute, extract & return the value and
  158. * isNull flag of the attribute.
  159. */
  160. #ifndef FRONTEND
  161. static inline Datum
  162. ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
  163. {
  164. Assert(attno > 0);
  165. return slot_getattr(slot, attno, isNull);
  166. }
  167. #endif
  168. /*
  169. * prototypes from functions in execMain.c
  170. */
  171. extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
  172. extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
  173. extern void ExecutorRun(QueryDesc *queryDesc,
  174. ScanDirection direction, uint64 count, bool execute_once);
  175. extern void standard_ExecutorRun(QueryDesc *queryDesc,
  176. ScanDirection direction, uint64 count, bool execute_once);
  177. extern void ExecutorFinish(QueryDesc *queryDesc);
  178. extern void standard_ExecutorFinish(QueryDesc *queryDesc);
  179. extern void ExecutorEnd(QueryDesc *queryDesc);
  180. extern void standard_ExecutorEnd(QueryDesc *queryDesc);
  181. extern void ExecutorRewind(QueryDesc *queryDesc);
  182. extern bool ExecCheckRTPerms(List *rangeTable, bool ereport_on_violation);
  183. extern void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation);
  184. extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
  185. Relation resultRelationDesc,
  186. Index resultRelationIndex,
  187. ResultRelInfo *partition_root_rri,
  188. int instrument_options);
  189. extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid,
  190. ResultRelInfo *rootRelInfo);
  191. extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo);
  192. extern void ExecConstraints(ResultRelInfo *resultRelInfo,
  193. TupleTableSlot *slot, EState *estate);
  194. extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo,
  195. TupleTableSlot *slot, EState *estate, bool emitError);
  196. extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
  197. TupleTableSlot *slot, EState *estate);
  198. extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
  199. TupleTableSlot *slot, EState *estate);
  200. extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
  201. extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
  202. extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
  203. extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
  204. Index rti, TupleTableSlot *testslot);
  205. extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
  206. Plan *subplan, List *auxrowmarks, int epqParam);
  207. extern void EvalPlanQualInitExt(EPQState *epqstate, EState *parentestate,
  208. Plan *subplan, List *auxrowmarks,
  209. int epqParam, List *resultRelations);
  210. extern void EvalPlanQualSetPlan(EPQState *epqstate,
  211. Plan *subplan, List *auxrowmarks);
  212. extern TupleTableSlot *EvalPlanQualSlot(EPQState *epqstate,
  213. Relation relation, Index rti);
  214. #define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
  215. extern bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot);
  216. extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
  217. extern void EvalPlanQualBegin(EPQState *epqstate);
  218. extern void EvalPlanQualEnd(EPQState *epqstate);
  219. /*
  220. * functions in execProcnode.c
  221. */
  222. extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
  223. extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
  224. extern Node *MultiExecProcNode(PlanState *node);
  225. extern void ExecEndNode(PlanState *node);
  226. extern bool ExecShutdownNode(PlanState *node);
  227. extern void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node);
  228. /* ----------------------------------------------------------------
  229. * ExecProcNode
  230. *
  231. * Execute the given node to return a(nother) tuple.
  232. * ----------------------------------------------------------------
  233. */
  234. #ifndef FRONTEND
  235. static inline TupleTableSlot *
  236. ExecProcNode(PlanState *node)
  237. {
  238. if (node->chgParam != NULL) /* something changed? */
  239. ExecReScan(node); /* let ReScan handle this */
  240. return node->ExecProcNode(node);
  241. }
  242. #endif
  243. /*
  244. * prototypes from functions in execExpr.c
  245. */
  246. extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
  247. extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
  248. extern ExprState *ExecInitQual(List *qual, PlanState *parent);
  249. extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
  250. extern List *ExecInitExprList(List *nodes, PlanState *parent);
  251. extern ExprState *ExecBuildAggTrans(AggState *aggstate, struct AggStatePerPhaseData *phase,
  252. bool doSort, bool doHash, bool nullcheck);
  253. extern ExprState *ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
  254. const TupleTableSlotOps *lops, const TupleTableSlotOps *rops,
  255. int numCols,
  256. const AttrNumber *keyColIdx,
  257. const Oid *eqfunctions,
  258. const Oid *collations,
  259. PlanState *parent);
  260. extern ExprState *ExecBuildParamSetEqual(TupleDesc desc,
  261. const TupleTableSlotOps *lops,
  262. const TupleTableSlotOps *rops,
  263. const Oid *eqfunctions,
  264. const Oid *collations,
  265. const List *param_exprs,
  266. PlanState *parent);
  267. extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
  268. ExprContext *econtext,
  269. TupleTableSlot *slot,
  270. PlanState *parent,
  271. TupleDesc inputDesc);
  272. extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
  273. bool evalTargetList,
  274. List *targetColnos,
  275. TupleDesc relDesc,
  276. ExprContext *econtext,
  277. TupleTableSlot *slot,
  278. PlanState *parent);
  279. extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
  280. extern ExprState *ExecPrepareQual(List *qual, EState *estate);
  281. extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
  282. extern List *ExecPrepareExprList(List *nodes, EState *estate);
  283. /*
  284. * ExecEvalExpr
  285. *
  286. * Evaluate expression identified by "state" in the execution context
  287. * given by "econtext". *isNull is set to the is-null flag for the result,
  288. * and the Datum value is the function result.
  289. *
  290. * The caller should already have switched into the temporary memory
  291. * context econtext->ecxt_per_tuple_memory. The convenience entry point
  292. * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
  293. * do the switch in an outer loop.
  294. */
  295. #ifndef FRONTEND
  296. static inline Datum
  297. ExecEvalExpr(ExprState *state,
  298. ExprContext *econtext,
  299. bool *isNull)
  300. {
  301. return state->evalfunc(state, econtext, isNull);
  302. }
  303. #endif
  304. /*
  305. * ExecEvalExprSwitchContext
  306. *
  307. * Same as ExecEvalExpr, but get into the right allocation context explicitly.
  308. */
  309. #ifndef FRONTEND
  310. static inline Datum
  311. ExecEvalExprSwitchContext(ExprState *state,
  312. ExprContext *econtext,
  313. bool *isNull)
  314. {
  315. Datum retDatum;
  316. MemoryContext oldContext;
  317. oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
  318. retDatum = state->evalfunc(state, econtext, isNull);
  319. MemoryContextSwitchTo(oldContext);
  320. return retDatum;
  321. }
  322. #endif
  323. /*
  324. * ExecProject
  325. *
  326. * Projects a tuple based on projection info and stores it in the slot passed
  327. * to ExecBuildProjectionInfo().
  328. *
  329. * Note: the result is always a virtual tuple; therefore it may reference
  330. * the contents of the exprContext's scan tuples and/or temporary results
  331. * constructed in the exprContext. If the caller wishes the result to be
  332. * valid longer than that data will be valid, he must call ExecMaterializeSlot
  333. * on the result slot.
  334. */
  335. #ifndef FRONTEND
  336. static inline TupleTableSlot *
  337. ExecProject(ProjectionInfo *projInfo)
  338. {
  339. ExprContext *econtext = projInfo->pi_exprContext;
  340. ExprState *state = &projInfo->pi_state;
  341. TupleTableSlot *slot = state->resultslot;
  342. bool isnull;
  343. /*
  344. * Clear any former contents of the result slot. This makes it safe for
  345. * us to use the slot's Datum/isnull arrays as workspace.
  346. */
  347. ExecClearTuple(slot);
  348. /* Run the expression, discarding scalar result from the last column. */
  349. (void) ExecEvalExprSwitchContext(state, econtext, &isnull);
  350. /*
  351. * Successfully formed a result row. Mark the result slot as containing a
  352. * valid virtual tuple (inlined version of ExecStoreVirtualTuple()).
  353. */
  354. slot->tts_flags &= ~TTS_FLAG_EMPTY;
  355. slot->tts_nvalid = slot->tts_tupleDescriptor->natts;
  356. return slot;
  357. }
  358. #endif
  359. /*
  360. * ExecQual - evaluate a qual prepared with ExecInitQual (possibly via
  361. * ExecPrepareQual). Returns true if qual is satisfied, else false.
  362. *
  363. * Note: ExecQual used to have a third argument "resultForNull". The
  364. * behavior of this function now corresponds to resultForNull == false.
  365. * If you want the resultForNull == true behavior, see ExecCheck.
  366. */
  367. #ifndef FRONTEND
  368. static inline bool
  369. ExecQual(ExprState *state, ExprContext *econtext)
  370. {
  371. Datum ret;
  372. bool isnull;
  373. /* short-circuit (here and in ExecInitQual) for empty restriction list */
  374. if (state == NULL)
  375. return true;
  376. /* verify that expression was compiled using ExecInitQual */
  377. Assert(state->flags & EEO_FLAG_IS_QUAL);
  378. ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
  379. /* EEOP_QUAL should never return NULL */
  380. Assert(!isnull);
  381. return DatumGetBool(ret);
  382. }
  383. #endif
  384. /*
  385. * ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
  386. * context.
  387. */
  388. #ifndef FRONTEND
  389. static inline bool
  390. ExecQualAndReset(ExprState *state, ExprContext *econtext)
  391. {
  392. bool ret = ExecQual(state, econtext);
  393. /* inline ResetExprContext, to avoid ordering issue in this file */
  394. MemoryContextReset(econtext->ecxt_per_tuple_memory);
  395. return ret;
  396. }
  397. #endif
  398. extern bool ExecCheck(ExprState *state, ExprContext *context);
  399. /*
  400. * prototypes from functions in execSRF.c
  401. */
  402. extern SetExprState *ExecInitTableFunctionResult(Expr *expr,
  403. ExprContext *econtext, PlanState *parent);
  404. extern Tuplestorestate *ExecMakeTableFunctionResult(SetExprState *setexpr,
  405. ExprContext *econtext,
  406. MemoryContext argContext,
  407. TupleDesc expectedDesc,
  408. bool randomAccess);
  409. extern SetExprState *ExecInitFunctionResultSet(Expr *expr,
  410. ExprContext *econtext, PlanState *parent);
  411. extern Datum ExecMakeFunctionResultSet(SetExprState *fcache,
  412. ExprContext *econtext,
  413. MemoryContext argContext,
  414. bool *isNull,
  415. ExprDoneCond *isDone);
  416. /*
  417. * prototypes from functions in execScan.c
  418. */
  419. typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
  420. typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
  421. extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
  422. ExecScanRecheckMtd recheckMtd);
  423. extern void ExecAssignScanProjectionInfo(ScanState *node);
  424. extern void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno);
  425. extern void ExecScanReScan(ScanState *node);
  426. /*
  427. * prototypes from functions in execTuples.c
  428. */
  429. extern void ExecInitResultTypeTL(PlanState *planstate);
  430. extern void ExecInitResultSlot(PlanState *planstate,
  431. const TupleTableSlotOps *tts_ops);
  432. extern void ExecInitResultTupleSlotTL(PlanState *planstate,
  433. const TupleTableSlotOps *tts_ops);
  434. extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate,
  435. TupleDesc tupleDesc,
  436. const TupleTableSlotOps *tts_ops);
  437. extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate,
  438. TupleDesc tupledesc,
  439. const TupleTableSlotOps *tts_ops);
  440. extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate, TupleDesc tupType,
  441. const TupleTableSlotOps *tts_ops);
  442. extern TupleDesc ExecTypeFromTL(List *targetList);
  443. extern TupleDesc ExecCleanTypeFromTL(List *targetList);
  444. extern TupleDesc ExecTypeFromExprList(List *exprList);
  445. extern void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList);
  446. extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
  447. typedef struct TupOutputState
  448. {
  449. TupleTableSlot *slot;
  450. DestReceiver *dest;
  451. } TupOutputState;
  452. extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
  453. TupleDesc tupdesc,
  454. const TupleTableSlotOps *tts_ops);
  455. extern void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull);
  456. extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
  457. extern void end_tup_output(TupOutputState *tstate);
  458. /*
  459. * Write a single line of text given as a C string.
  460. *
  461. * Should only be used with a single-TEXT-attribute tupdesc.
  462. */
  463. #define do_text_output_oneline(tstate, str_to_emit) \
  464. do { \
  465. Datum values_[1]; \
  466. bool isnull_[1]; \
  467. values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
  468. isnull_[0] = false; \
  469. do_tup_output(tstate, values_, isnull_); \
  470. pfree(DatumGetPointer(values_[0])); \
  471. } while (0)
  472. /*
  473. * prototypes from functions in execUtils.c
  474. */
  475. extern EState *CreateExecutorState(void);
  476. extern void FreeExecutorState(EState *estate);
  477. extern ExprContext *CreateExprContext(EState *estate);
  478. extern ExprContext *CreateWorkExprContext(EState *estate);
  479. extern ExprContext *CreateStandaloneExprContext(void);
  480. extern void FreeExprContext(ExprContext *econtext, bool isCommit);
  481. extern void ReScanExprContext(ExprContext *econtext);
  482. #define ResetExprContext(econtext) \
  483. MemoryContextReset((econtext)->ecxt_per_tuple_memory)
  484. extern ExprContext *MakePerTupleExprContext(EState *estate);
  485. /* Get an EState's per-output-tuple exprcontext, making it if first use */
  486. #define GetPerTupleExprContext(estate) \
  487. ((estate)->es_per_tuple_exprcontext ? \
  488. (estate)->es_per_tuple_exprcontext : \
  489. MakePerTupleExprContext(estate))
  490. #define GetPerTupleMemoryContext(estate) \
  491. (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
  492. /* Reset an EState's per-output-tuple exprcontext, if one's been created */
  493. #define ResetPerTupleExprContext(estate) \
  494. do { \
  495. if ((estate)->es_per_tuple_exprcontext) \
  496. ResetExprContext((estate)->es_per_tuple_exprcontext); \
  497. } while (0)
  498. extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
  499. extern TupleDesc ExecGetResultType(PlanState *planstate);
  500. extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
  501. bool *isfixed);
  502. extern void ExecAssignProjectionInfo(PlanState *planstate,
  503. TupleDesc inputDesc);
  504. extern void ExecConditionalAssignProjectionInfo(PlanState *planstate,
  505. TupleDesc inputDesc, int varno);
  506. extern void ExecFreeExprContext(PlanState *planstate);
  507. extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
  508. extern void ExecCreateScanSlotFromOuterPlan(EState *estate,
  509. ScanState *scanstate,
  510. const TupleTableSlotOps *tts_ops);
  511. extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
  512. extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
  513. extern void ExecInitRangeTable(EState *estate, List *rangeTable);
  514. extern void ExecCloseRangeTableRelations(EState *estate);
  515. extern void ExecCloseResultRelations(EState *estate);
  516. static inline RangeTblEntry *
  517. exec_rt_fetch(Index rti, EState *estate)
  518. {
  519. return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
  520. }
  521. extern Relation ExecGetRangeTableRelation(EState *estate, Index rti);
  522. extern void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo,
  523. Index rti);
  524. extern int executor_errposition(EState *estate, int location);
  525. extern void RegisterExprContextCallback(ExprContext *econtext,
  526. ExprContextCallbackFunction function,
  527. Datum arg);
  528. extern void UnregisterExprContextCallback(ExprContext *econtext,
  529. ExprContextCallbackFunction function,
  530. Datum arg);
  531. extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
  532. bool *isNull);
  533. extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
  534. bool *isNull);
  535. extern int ExecTargetListLength(List *targetlist);
  536. extern int ExecCleanTargetListLength(List *targetlist);
  537. extern TupleTableSlot *ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo);
  538. extern TupleTableSlot *ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo);
  539. extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo);
  540. extern TupleConversionMap *ExecGetChildToRootMap(ResultRelInfo *resultRelInfo);
  541. extern Bitmapset *ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate);
  542. extern Bitmapset *ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate);
  543. extern Bitmapset *ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate);
  544. extern Bitmapset *ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate);
  545. /*
  546. * prototypes from functions in execIndexing.c
  547. */
  548. extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
  549. extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
  550. extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
  551. TupleTableSlot *slot, EState *estate,
  552. bool update,
  553. bool noDupErr,
  554. bool *specConflict, List *arbiterIndexes);
  555. extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
  556. TupleTableSlot *slot,
  557. EState *estate, ItemPointer conflictTid,
  558. List *arbiterIndexes);
  559. extern void check_exclusion_constraint(Relation heap, Relation index,
  560. IndexInfo *indexInfo,
  561. ItemPointer tupleid,
  562. Datum *values, bool *isnull,
  563. EState *estate, bool newIndex);
  564. /*
  565. * prototypes from functions in execReplication.c
  566. */
  567. extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
  568. LockTupleMode lockmode,
  569. TupleTableSlot *searchslot,
  570. TupleTableSlot *outslot);
  571. extern bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
  572. TupleTableSlot *searchslot, TupleTableSlot *outslot);
  573. extern void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
  574. EState *estate, TupleTableSlot *slot);
  575. extern void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
  576. EState *estate, EPQState *epqstate,
  577. TupleTableSlot *searchslot, TupleTableSlot *slot);
  578. extern void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
  579. EState *estate, EPQState *epqstate,
  580. TupleTableSlot *searchslot);
  581. extern void CheckCmdReplicaIdentity(Relation rel, CmdType cmd);
  582. extern void CheckSubscriptionRelkind(char relkind, const char *nspname,
  583. const char *relname);
  584. /*
  585. * prototypes from functions in nodeModifyTable.c
  586. */
  587. extern TupleTableSlot *ExecGetUpdateNewTuple(ResultRelInfo *relinfo,
  588. TupleTableSlot *planSlot,
  589. TupleTableSlot *oldSlot);
  590. extern ResultRelInfo *ExecLookupResultRelByOid(ModifyTableState *node,
  591. Oid resultoid,
  592. bool missing_ok,
  593. bool update_cache);
  594. #endif /* EXECUTOR_H */