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