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