00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef EXECUTOR_H
00015 #define EXECUTOR_H
00016
00017 #include "executor/execdesc.h"
00018 #include "nodes/parsenodes.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #define EXEC_FLAG_EXPLAIN_ONLY 0x0001
00058 #define EXEC_FLAG_REWIND 0x0002
00059 #define EXEC_FLAG_BACKWARD 0x0004
00060 #define EXEC_FLAG_MARK 0x0008
00061 #define EXEC_FLAG_SKIP_TRIGGERS 0x0010
00062 #define EXEC_FLAG_WITH_OIDS 0x0020
00063 #define EXEC_FLAG_WITHOUT_OIDS 0x0040
00064 #define EXEC_FLAG_WITH_NO_DATA 0x0080
00065
00066
00067
00068
00069
00070
00071
00072 #define ExecEvalExpr(expr, econtext, isNull, isDone) \
00073 ((*(expr)->evalfunc) (expr, econtext, isNull, isDone))
00074
00075
00076
00077 typedef void (*ExecutorStart_hook_type) (QueryDesc *queryDesc, int eflags);
00078 extern PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook;
00079
00080
00081 typedef void (*ExecutorRun_hook_type) (QueryDesc *queryDesc,
00082 ScanDirection direction,
00083 long count);
00084 extern PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook;
00085
00086
00087 typedef void (*ExecutorFinish_hook_type) (QueryDesc *queryDesc);
00088 extern PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook;
00089
00090
00091 typedef void (*ExecutorEnd_hook_type) (QueryDesc *queryDesc);
00092 extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
00093
00094
00095 typedef bool (*ExecutorCheckPerms_hook_type) (List *, bool);
00096 extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
00097
00098
00099
00100
00101
00102 extern void ExecReScan(PlanState *node);
00103 extern void ExecMarkPos(PlanState *node);
00104 extern void ExecRestrPos(PlanState *node);
00105 extern bool ExecSupportsMarkRestore(NodeTag plantype);
00106 extern bool ExecSupportsBackwardScan(Plan *node);
00107 extern bool ExecMaterializesOutput(NodeTag plantype);
00108
00109
00110
00111
00112 extern bool execCurrentOf(CurrentOfExpr *cexpr,
00113 ExprContext *econtext,
00114 Oid table_oid,
00115 ItemPointer current_tid);
00116
00117
00118
00119
00120 extern bool execTuplesMatch(TupleTableSlot *slot1,
00121 TupleTableSlot *slot2,
00122 int numCols,
00123 AttrNumber *matchColIdx,
00124 FmgrInfo *eqfunctions,
00125 MemoryContext evalContext);
00126 extern bool execTuplesUnequal(TupleTableSlot *slot1,
00127 TupleTableSlot *slot2,
00128 int numCols,
00129 AttrNumber *matchColIdx,
00130 FmgrInfo *eqfunctions,
00131 MemoryContext evalContext);
00132 extern FmgrInfo *execTuplesMatchPrepare(int numCols,
00133 Oid *eqOperators);
00134 extern void execTuplesHashPrepare(int numCols,
00135 Oid *eqOperators,
00136 FmgrInfo **eqFunctions,
00137 FmgrInfo **hashFunctions);
00138 extern TupleHashTable BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
00139 FmgrInfo *eqfunctions,
00140 FmgrInfo *hashfunctions,
00141 long nbuckets, Size entrysize,
00142 MemoryContext tablecxt,
00143 MemoryContext tempcxt);
00144 extern TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable,
00145 TupleTableSlot *slot,
00146 bool *isnew);
00147 extern TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable,
00148 TupleTableSlot *slot,
00149 FmgrInfo *eqfunctions,
00150 FmgrInfo *hashfunctions);
00151
00152
00153
00154
00155 extern JunkFilter *ExecInitJunkFilter(List *targetList, bool hasoid,
00156 TupleTableSlot *slot);
00157 extern JunkFilter *ExecInitJunkFilterConversion(List *targetList,
00158 TupleDesc cleanTupType,
00159 TupleTableSlot *slot);
00160 extern AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter,
00161 const char *attrName);
00162 extern AttrNumber ExecFindJunkAttributeInTlist(List *targetlist,
00163 const char *attrName);
00164 extern Datum ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno,
00165 bool *isNull);
00166 extern TupleTableSlot *ExecFilterJunk(JunkFilter *junkfilter,
00167 TupleTableSlot *slot);
00168
00169
00170
00171
00172
00173 extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
00174 extern void standard_ExecutorStart(QueryDesc *queryDesc, int eflags);
00175 extern void ExecutorRun(QueryDesc *queryDesc,
00176 ScanDirection direction, long count);
00177 extern void standard_ExecutorRun(QueryDesc *queryDesc,
00178 ScanDirection direction, long count);
00179 extern void ExecutorFinish(QueryDesc *queryDesc);
00180 extern void standard_ExecutorFinish(QueryDesc *queryDesc);
00181 extern void ExecutorEnd(QueryDesc *queryDesc);
00182 extern void standard_ExecutorEnd(QueryDesc *queryDesc);
00183 extern void ExecutorRewind(QueryDesc *queryDesc);
00184 extern bool ExecCheckRTPerms(List *rangeTable, bool ereport_on_violation);
00185 extern void CheckValidResultRel(Relation resultRel, CmdType operation);
00186 extern void InitResultRelInfo(ResultRelInfo *resultRelInfo,
00187 Relation resultRelationDesc,
00188 Index resultRelationIndex,
00189 int instrument_options);
00190 extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid);
00191 extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids);
00192 extern void ExecConstraints(ResultRelInfo *resultRelInfo,
00193 TupleTableSlot *slot, EState *estate);
00194 extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti);
00195 extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
00196 extern TupleTableSlot *EvalPlanQual(EState *estate, EPQState *epqstate,
00197 Relation relation, Index rti, int lockmode,
00198 ItemPointer tid, TransactionId priorXmax);
00199 extern HeapTuple EvalPlanQualFetch(EState *estate, Relation relation,
00200 int lockmode, ItemPointer tid, TransactionId priorXmax);
00201 extern void EvalPlanQualInit(EPQState *epqstate, EState *estate,
00202 Plan *subplan, List *auxrowmarks, int epqParam);
00203 extern void EvalPlanQualSetPlan(EPQState *epqstate,
00204 Plan *subplan, List *auxrowmarks);
00205 extern void EvalPlanQualSetTuple(EPQState *epqstate, Index rti,
00206 HeapTuple tuple);
00207 extern HeapTuple EvalPlanQualGetTuple(EPQState *epqstate, Index rti);
00208
00209 #define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
00210 extern void EvalPlanQualFetchRowMarks(EPQState *epqstate);
00211 extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
00212 extern void EvalPlanQualBegin(EPQState *epqstate, EState *parentestate);
00213 extern void EvalPlanQualEnd(EPQState *epqstate);
00214
00215
00216
00217
00218 extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
00219 extern TupleTableSlot *ExecProcNode(PlanState *node);
00220 extern Node *MultiExecProcNode(PlanState *node);
00221 extern void ExecEndNode(PlanState *node);
00222
00223
00224
00225
00226 extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno,
00227 bool *isNull);
00228 extern Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname,
00229 bool *isNull);
00230 extern Tuplestorestate *ExecMakeTableFunctionResult(ExprState *funcexpr,
00231 ExprContext *econtext,
00232 TupleDesc expectedDesc,
00233 bool randomAccess);
00234 extern Datum ExecEvalExprSwitchContext(ExprState *expression, ExprContext *econtext,
00235 bool *isNull, ExprDoneCond *isDone);
00236 extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
00237 extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
00238 extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull);
00239 extern int ExecTargetListLength(List *targetlist);
00240 extern int ExecCleanTargetListLength(List *targetlist);
00241 extern TupleTableSlot *ExecProject(ProjectionInfo *projInfo,
00242 ExprDoneCond *isDone);
00243
00244
00245
00246
00247 typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node);
00248 typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
00249
00250 extern TupleTableSlot *ExecScan(ScanState *node, ExecScanAccessMtd accessMtd,
00251 ExecScanRecheckMtd recheckMtd);
00252 extern void ExecAssignScanProjectionInfo(ScanState *node);
00253 extern void ExecScanReScan(ScanState *node);
00254
00255
00256
00257
00258 extern void ExecInitResultTupleSlot(EState *estate, PlanState *planstate);
00259 extern void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate);
00260 extern TupleTableSlot *ExecInitExtraTupleSlot(EState *estate);
00261 extern TupleTableSlot *ExecInitNullTupleSlot(EState *estate,
00262 TupleDesc tupType);
00263 extern TupleDesc ExecTypeFromTL(List *targetList, bool hasoid);
00264 extern TupleDesc ExecCleanTypeFromTL(List *targetList, bool hasoid);
00265 extern TupleDesc ExecTypeFromExprList(List *exprList, List *namesList);
00266 extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
00267
00268 typedef struct TupOutputState
00269 {
00270 TupleTableSlot *slot;
00271 DestReceiver *dest;
00272 } TupOutputState;
00273
00274 extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
00275 TupleDesc tupdesc);
00276 extern void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull);
00277 extern void do_text_output_multiline(TupOutputState *tstate, char *text);
00278 extern void end_tup_output(TupOutputState *tstate);
00279
00280
00281
00282
00283
00284
00285 #define do_text_output_oneline(tstate, str_to_emit) \
00286 do { \
00287 Datum values_[1]; \
00288 bool isnull_[1]; \
00289 values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
00290 isnull_[0] = false; \
00291 do_tup_output(tstate, values_, isnull_); \
00292 pfree(DatumGetPointer(values_[0])); \
00293 } while (0)
00294
00295
00296
00297
00298
00299 extern EState *CreateExecutorState(void);
00300 extern void FreeExecutorState(EState *estate);
00301 extern ExprContext *CreateExprContext(EState *estate);
00302 extern ExprContext *CreateStandaloneExprContext(void);
00303 extern void FreeExprContext(ExprContext *econtext, bool isCommit);
00304 extern void ReScanExprContext(ExprContext *econtext);
00305
00306 #define ResetExprContext(econtext) \
00307 MemoryContextReset((econtext)->ecxt_per_tuple_memory)
00308
00309 extern ExprContext *MakePerTupleExprContext(EState *estate);
00310
00311
00312 #define GetPerTupleExprContext(estate) \
00313 ((estate)->es_per_tuple_exprcontext ? \
00314 (estate)->es_per_tuple_exprcontext : \
00315 MakePerTupleExprContext(estate))
00316
00317 #define GetPerTupleMemoryContext(estate) \
00318 (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
00319
00320
00321 #define ResetPerTupleExprContext(estate) \
00322 do { \
00323 if ((estate)->es_per_tuple_exprcontext) \
00324 ResetExprContext((estate)->es_per_tuple_exprcontext); \
00325 } while (0)
00326
00327 extern void ExecAssignExprContext(EState *estate, PlanState *planstate);
00328 extern void ExecAssignResultType(PlanState *planstate, TupleDesc tupDesc);
00329 extern void ExecAssignResultTypeFromTL(PlanState *planstate);
00330 extern TupleDesc ExecGetResultType(PlanState *planstate);
00331 extern ProjectionInfo *ExecBuildProjectionInfo(List *targetList,
00332 ExprContext *econtext,
00333 TupleTableSlot *slot,
00334 TupleDesc inputDesc);
00335 extern void ExecAssignProjectionInfo(PlanState *planstate,
00336 TupleDesc inputDesc);
00337 extern void ExecFreeExprContext(PlanState *planstate);
00338 extern TupleDesc ExecGetScanType(ScanState *scanstate);
00339 extern void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc);
00340 extern void ExecAssignScanTypeFromOuterPlan(ScanState *scanstate);
00341
00342 extern bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid);
00343
00344 extern Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags);
00345 extern void ExecCloseScanRelation(Relation scanrel);
00346
00347 extern void ExecOpenIndices(ResultRelInfo *resultRelInfo);
00348 extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
00349 extern List *ExecInsertIndexTuples(TupleTableSlot *slot, ItemPointer tupleid,
00350 EState *estate);
00351 extern bool check_exclusion_constraint(Relation heap, Relation index,
00352 IndexInfo *indexInfo,
00353 ItemPointer tupleid,
00354 Datum *values, bool *isnull,
00355 EState *estate,
00356 bool newIndex, bool errorOK);
00357
00358 extern void RegisterExprContextCallback(ExprContext *econtext,
00359 ExprContextCallbackFunction function,
00360 Datum arg);
00361 extern void UnregisterExprContextCallback(ExprContext *econtext,
00362 ExprContextCallbackFunction function,
00363 Datum arg);
00364
00365 #endif