OSDN Git Service

Update copyright for 2009.
[pg-rex/syncrep.git] / src / include / executor / executor.h
1 /*-------------------------------------------------------------------------
2  *
3  * executor.h
4  *        support for the POSTGRES executor module
5  *
6  *
7  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.154 2009/01/01 17:23:59 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef EXECUTOR_H
15 #define EXECUTOR_H
16
17 #include "executor/execdesc.h"
18 #include "nodes/parsenodes.h"
19
20
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 (such as creating a SELECT INTO target table).
34  * However, error checks (such as permission checks) 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 #define EXEC_FLAG_EXPLAIN_ONLY  0x0001  /* EXPLAIN, no ANALYZE */
49 #define EXEC_FLAG_REWIND                0x0002  /* need efficient rescan */
50 #define EXEC_FLAG_BACKWARD              0x0004  /* need backward scan */
51 #define EXEC_FLAG_MARK                  0x0008  /* need mark/restore */
52
53
54 /*
55  * ExecEvalExpr was formerly a function containing a switch statement;
56  * now it's just a macro invoking the function pointed to by an ExprState
57  * node.  Beware of double evaluation of the ExprState argument!
58  */
59 #define ExecEvalExpr(expr, econtext, isNull, isDone) \
60         ((*(expr)->evalfunc) (expr, econtext, isNull, isDone))
61
62
63 /* Hook for plugins to get control in ExecutorStart() */
64 typedef void (*ExecutorStart_hook_type) (QueryDesc *queryDesc, int eflags);
65 extern PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook;
66
67 /* Hook for plugins to get control in ExecutorRun() */
68 typedef void (*ExecutorRun_hook_type) (QueryDesc *queryDesc,
69                                                                            ScanDirection direction,
70                                                                            long count);
71 extern PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook;
72
73 /* Hook for plugins to get control in ExecutorEnd() */
74 typedef void (*ExecutorEnd_hook_type) (QueryDesc *queryDesc);
75 extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
76
77
78 /*
79  * prototypes from functions in execAmi.c
80  */
81 extern void ExecReScan(PlanState *node, ExprContext *exprCtxt);
82 extern void ExecMarkPos(PlanState *node);
83 extern void ExecRestrPos(PlanState *node);
84 extern bool ExecSupportsMarkRestore(NodeTag plantype);
85 extern bool ExecSupportsBackwardScan(Plan *node);
86
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 /*
96  * prototypes from functions in execGrouping.c
97  */
98 extern bool execTuplesMatch(TupleTableSlot *slot1,
99                                 TupleTableSlot *slot2,
100                                 int numCols,
101                                 AttrNumber *matchColIdx,
102                                 FmgrInfo *eqfunctions,
103                                 MemoryContext evalContext);
104 extern bool execTuplesUnequal(TupleTableSlot *slot1,
105                                   TupleTableSlot *slot2,
106                                   int numCols,
107                                   AttrNumber *matchColIdx,
108                                   FmgrInfo *eqfunctions,
109                                   MemoryContext evalContext);
110 extern FmgrInfo *execTuplesMatchPrepare(int numCols,
111                                            Oid *eqOperators);
112 extern void execTuplesHashPrepare(int numCols,
113                                           Oid *eqOperators,
114                                           FmgrInfo **eqFunctions,
115                                           FmgrInfo **hashFunctions);
116 extern TupleHashTable BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
117                                         FmgrInfo *eqfunctions,
118                                         FmgrInfo *hashfunctions,
119                                         int nbuckets, Size entrysize,
120                                         MemoryContext tablecxt,
121                                         MemoryContext tempcxt);
122 extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
123                                          TupleTableSlot *slot,
124                                          bool *isnew);
125 extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
126                                    TupleTableSlot *slot,
127                                    FmgrInfo *eqfunctions,
128                                    FmgrInfo *hashfunctions);
129
130 /*
131  * prototypes from functions in execJunk.c
132  */
133 extern JunkFilter *ExecInitJunkFilter(List *targetList, bool hasoid,
134                                    TupleTableSlot *slot);
135 extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
136                                                          TupleDesc cleanTupType,
137                                                          TupleTableSlot *slot);
138 extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
139                                           const char *attrName);
140 extern Datum ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno,
141                                          bool *isNull);
142 extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
143                            TupleTableSlot *slot);
144 extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
145
146
147 /*
148  * prototypes from functions in execMain.c
149  */
150 extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
151 extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
152 extern void ExecutorRun(QueryDesc *queryDesc,
153                                                 ScanDirection direction, long count);
154 extern void standard_ExecutorRun(QueryDesc *queryDesc,
155                                                                  ScanDirection direction, long count);
156 extern void ExecutorEnd(QueryDesc *queryDesc);
157 extern void standard_ExecutorEnd(QueryDesc *queryDesc);
158 extern void ExecutorRewind(QueryDesc *queryDesc);
159 extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
160                                   Relation resultRelationDesc,
161                                   Index resultRelationIndex,
162                                   CmdType operation,
163                                   bool doInstrument);
164 extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid);
165 extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids);
166 extern void ExecConstraints(ResultRelInfo *resultRelInfo,
167                                 TupleTableSlot *slot, EState *estate);
168 extern TupleTableSlot *EvalPlanQual(EState *estate, Index rti,
169                          ItemPointer tid, TransactionId priorXmax);
170 extern PlanState *ExecGetActivePlanTree(QueryDesc *queryDesc);
171 extern DestReceiver *CreateIntoRelDestReceiver(void);
172
173 /*
174  * prototypes from functions in execProcnode.c
175  */
176 extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
177 extern TupleTableSlot *ExecProcNode(PlanState *node);
178 extern Node *MultiExecProcNode(PlanState *node);
179 extern int      ExecCountSlotsNode(Plan *node);
180 extern void ExecEndNode(PlanState *node);
181
182 /*
183  * prototypes from functions in execQual.c
184  */
185 extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
186                                   bool *isNull);
187 extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
188                                    bool *isNull);
189 extern Tuplestorestate *ExecMakeTableFunctionResult(ExprState *funcexpr,
190                                                         ExprContext *econtext,
191                                                         TupleDesc expectedDesc,
192                                                         bool randomAccess);
193 extern Datum ExecEvalExprSwitchContext(ExprState *expression, ExprContext *econtext,
194                                                   bool *isNull, ExprDoneCond *isDone);
195 extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
196 extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
197 extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull);
198 extern int      ExecTargetListLength(List *targetlist);
199 extern int      ExecCleanTargetListLength(List *targetlist);
200 extern TupleTableSlot *ExecProject(ProjectionInfo *projInfo,
201                         ExprDoneCond *isDone);
202
203 /*
204  * prototypes from functions in execScan.c
205  */
206 typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
207
208 extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd);
209 extern void ExecAssignScanProjectionInfo(ScanState *node);
210
211 /*
212  * prototypes from functions in execTuples.c
213  */
214 extern void ExecInitResultTupleSlot(EState *estate, PlanState *planstate);
215 extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate);
216 extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate);
217 extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate,
218                                           TupleDesc tupType);
219 extern TupleDesc ExecTypeFromTL(List *targetList, bool hasoid);
220 extern TupleDesc ExecCleanTypeFromTL(List *targetList, bool hasoid);
221 extern TupleDesc ExecTypeFromExprList(List *exprList);
222 extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
223
224 typedef struct TupOutputState
225 {
226         /* use "struct" here to allow forward reference */
227         struct AttInMetadata *metadata;
228         TupleTableSlot *slot;
229         DestReceiver *dest;
230 } TupOutputState;
231
232 extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
233                                                  TupleDesc tupdesc);
234 extern void do_tup_output(TupOutputState *tstate, char **values);
235 extern void do_text_output_multiline(TupOutputState *tstate, char *text);
236 extern void end_tup_output(TupOutputState *tstate);
237
238 /*
239  * Write a single line of text given as a C string.
240  *
241  * Should only be used with a single-TEXT-attribute tupdesc.
242  */
243 #define do_text_output_oneline(tstate, text_to_emit) \
244         do { \
245                 char *values_[1]; \
246                 values_[0] = (text_to_emit); \
247                 do_tup_output(tstate, values_); \
248         } while (0)
249
250
251 /*
252  * prototypes from functions in execUtils.c
253  */
254 extern EState *CreateExecutorState(void);
255 extern void FreeExecutorState(EState *estate);
256 extern ExprContext *CreateExprContext(EState *estate);
257 extern ExprContext *CreateStandaloneExprContext(void);
258 extern void FreeExprContext(ExprContext *econtext);
259 extern void ReScanExprContext(ExprContext *econtext);
260
261 #define ResetExprContext(econtext) \
262         MemoryContextReset((econtext)->ecxt_per_tuple_memory)
263
264 extern ExprContext *MakePerTupleExprContext(EState *estate);
265
266 /* Get an EState's per-output-tuple exprcontext, making it if first use */
267 #define GetPerTupleExprContext(estate) \
268         ((estate)->es_per_tuple_exprcontext ? \
269          (estate)->es_per_tuple_exprcontext : \
270          MakePerTupleExprContext(estate))
271
272 #define GetPerTupleMemoryContext(estate) \
273         (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
274
275 /* Reset an EState's per-output-tuple exprcontext, if one's been created */
276 #define ResetPerTupleExprContext(estate) \
277         do { \
278                 if ((estate)->es_per_tuple_exprcontext) \
279                         ResetExprContext((estate)->es_per_tuple_exprcontext); \
280         } while (0)
281
282 extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
283 extern void ExecAssignResultType(PlanState *planstate, TupleDesc tupDesc);
284 extern void ExecAssignResultTypeFromTL(PlanState *planstate);
285 extern TupleDesc ExecGetResultType(PlanState *planstate);
286 extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
287                                                 ExprContext *econtext,
288                                                 TupleTableSlot *slot,
289                                                 TupleDesc inputDesc);
290 extern void ExecAssignProjectionInfo(PlanState *planstate,
291                                                  TupleDesc inputDesc);
292 extern void ExecFreeExprContext(PlanState *planstate);
293 extern TupleDesc ExecGetScanType(ScanState *scanstate);
294 extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
295 extern void ExecAssignScanTypeFromOuterPlan(ScanState *scanstate);
296
297 extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
298
299 extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid);
300 extern void ExecCloseScanRelation(Relation scanrel);
301
302 extern void ExecOpenIndices(ResultRelInfo *resultRelInfo);
303 extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
304 extern void ExecInsertIndexTuples(TupleTableSlot *slot, ItemPointer tupleid,
305                                           EState *estate, bool is_vacuum);
306
307 extern void RegisterExprContextCallback(ExprContext *econtext,
308                                                         ExprContextCallbackFunction function,
309                                                         Datum arg);
310 extern void UnregisterExprContextCallback(ExprContext *econtext,
311                                                           ExprContextCallbackFunction function,
312                                                           Datum arg);
313
314 #endif   /* EXECUTOR_H  */