Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "postgres.h"
00024
00025 #include "executor/executor.h"
00026 #include "executor/nodeForeignscan.h"
00027 #include "foreign/fdwapi.h"
00028 #include "utils/rel.h"
00029
00030 static TupleTableSlot *ForeignNext(ForeignScanState *node);
00031 static bool ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot);
00032
00033
00034
00035
00036
00037
00038
00039
00040 static TupleTableSlot *
00041 ForeignNext(ForeignScanState *node)
00042 {
00043 TupleTableSlot *slot;
00044 ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
00045 ExprContext *econtext = node->ss.ps.ps_ExprContext;
00046 MemoryContext oldcontext;
00047
00048
00049 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
00050 slot = node->fdwroutine->IterateForeignScan(node);
00051 MemoryContextSwitchTo(oldcontext);
00052
00053
00054
00055
00056
00057
00058
00059 if (plan->fsSystemCol && !TupIsNull(slot))
00060 {
00061 HeapTuple tup = ExecMaterializeSlot(slot);
00062
00063 tup->t_tableOid = RelationGetRelid(node->ss.ss_currentRelation);
00064 }
00065
00066 return slot;
00067 }
00068
00069
00070
00071
00072 static bool
00073 ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot)
00074 {
00075
00076 return true;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 TupleTableSlot *
00089 ExecForeignScan(ForeignScanState *node)
00090 {
00091 return ExecScan((ScanState *) node,
00092 (ExecScanAccessMtd) ForeignNext,
00093 (ExecScanRecheckMtd) ForeignRecheck);
00094 }
00095
00096
00097
00098
00099
00100
00101 ForeignScanState *
00102 ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
00103 {
00104 ForeignScanState *scanstate;
00105 Relation currentRelation;
00106 FdwRoutine *fdwroutine;
00107
00108
00109 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
00110
00111
00112
00113
00114 scanstate = makeNode(ForeignScanState);
00115 scanstate->ss.ps.plan = (Plan *) node;
00116 scanstate->ss.ps.state = estate;
00117
00118
00119
00120
00121
00122
00123 ExecAssignExprContext(estate, &scanstate->ss.ps);
00124
00125 scanstate->ss.ps.ps_TupFromTlist = false;
00126
00127
00128
00129
00130 scanstate->ss.ps.targetlist = (List *)
00131 ExecInitExpr((Expr *) node->scan.plan.targetlist,
00132 (PlanState *) scanstate);
00133 scanstate->ss.ps.qual = (List *)
00134 ExecInitExpr((Expr *) node->scan.plan.qual,
00135 (PlanState *) scanstate);
00136
00137
00138
00139
00140 ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
00141 ExecInitScanTupleSlot(estate, &scanstate->ss);
00142
00143
00144
00145
00146 currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
00147 scanstate->ss.ss_currentRelation = currentRelation;
00148
00149
00150
00151
00152
00153 ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
00154
00155
00156
00157
00158 ExecAssignResultTypeFromTL(&scanstate->ss.ps);
00159 ExecAssignScanProjectionInfo(&scanstate->ss);
00160
00161
00162
00163
00164 fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
00165 scanstate->fdwroutine = fdwroutine;
00166 scanstate->fdw_state = NULL;
00167
00168
00169
00170
00171 fdwroutine->BeginForeignScan(scanstate, eflags);
00172
00173 return scanstate;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 void
00183 ExecEndForeignScan(ForeignScanState *node)
00184 {
00185
00186 node->fdwroutine->EndForeignScan(node);
00187
00188
00189 ExecFreeExprContext(&node->ss.ps);
00190
00191
00192 ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
00193 ExecClearTuple(node->ss.ss_ScanTupleSlot);
00194
00195
00196 ExecCloseScanRelation(node->ss.ss_currentRelation);
00197 }
00198
00199
00200
00201
00202
00203
00204
00205 void
00206 ExecReScanForeignScan(ForeignScanState *node)
00207 {
00208 node->fdwroutine->ReScanForeignScan(node);
00209
00210 ExecScanReScan(&node->ss);
00211 }